-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
130 lines (116 loc) · 3.48 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { createApp, computed, ref, reactive, onMounted, provide } from "vue";
import { useRoute, useRouter } from "vue-router";
import { createStore } from "vuex";
import { createVuetify } from "vuetify";
import vuexStore from "./modules/vuex.js";
import mainVareityCard from "./components/main-vareity-card.js";
import familyHeroElement from "./components/family-hero-element.js";
import mainHero from "./components/main-hero.js";
import priceHero from "./components/price-hero.js";
import heroElement from "./components/hero-element.js";
import catalogHero from "./components/catalog-hero.js";
import router from "./router.js";
import persona from "./components/loged-in-person.js";
import stockInput from "./components/stock-input.js";
import {
getAuth,
signOut,
onAuthStateChanged,
} from "https://www.gstatic.com/firebasejs/9.22.1/firebase-auth.js";
const vuetify = createVuetify({
theme: {
themes: {
light: {
colors: {
primary: "#61cb6f",
secondary: "#9b91f9",
},
},
},
},
});
const store = createStore(vuexStore);
const app = createApp({
setup() {
const loaded = ref(false);
const compayName = ref("ENZApp");
const icons = ref([
"mdi-facebook",
"mdi-twitter",
"mdi-linkedin",
"mdi-instagram",
]);
const drawer = ref(false);
provide("drawer", drawer);
// fetch("/katalog-export.json")
// .then((res) => res.json())
// .then((data) => {
// for (let d in data) {
// data[d].family = data[d].crop
// }
// return data;
// })
// .then((changed) => JSON.stringify(changed));
const router = useRouter();
const auth = getAuth();
const logedInUser = computed(() => store.getters.getUserFromStore);
const logOut = () => {
signOut(auth)
.then(() => {
// Sign-out successful.
store.dispatch("insertUserToStore", null);
console.log("Wylogowano");
router.push("/");
})
.catch((error) => {
// An error happened.
console.log("Ooooppsi nie wylogowano");
});
};
onAuthStateChanged(auth, (user) => {
if (user) {
// User is signed in, see docs for a list of available properties
// https://firebase.google.com/docs/reference/js/auth.user
store.dispatch("insertUserToStore", user);
// ...
} else {
// User is signed out
// ...
store.dispatch("insertUserToStore", null);
console.log("Wylogowany");
}
});
onMounted(async () => {
let katalog = localStorage.getItem("katalog");
if (!Array.isArray(JSON.parse(katalog))) {
localStorage.removeItem("katalog");
const db = getDatabase(app);
const katalog = fref(db, "katalog");
onValue(katalog, (snapshot) => {
store.dispatch("insertKatalogToStore", snapshot.val());
crops.value = snapshot.val();
});
}
});
return {
compayName,
icons,
loaded,
drawer,
logedInUser,
logOut,
};
},
});
app.use(router);
app.use(store);
app.use(vuetify);
app.component("main-vareity-card", mainVareityCard);
app.component("family-hero-element", familyHeroElement);
app.component("main-hero", mainHero);
app.component("hero-element", heroElement);
app.component("stock-input", stockInput);
app.component("price-hero", priceHero);
app.component("persona", persona);
app.component("catalog-hero", catalogHero);
app.mount("#app");