-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
71 lines (67 loc) · 1.77 KB
/
index.js
File metadata and controls
71 lines (67 loc) · 1.77 KB
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
import "./list.js";
import "./item.js";
import firebaseConfig from "./database.js";
import { Item } from "./models.js";
firebase.initializeApp(firebaseConfig);
const database = firebase.database();
const Tabs = {
TOPICS: 1,
ARTICLES: 2,
};
const Titles = {
[Tabs.TOPICS]: 'Tópicos',
[Tabs.ARTICLES]: 'Artigos',
}
const app = new Vue({
el: "#app",
data() {
return {
Tabs: Tabs,
Titles: Titles,
currentTab: Tabs.TOPICS,
inputText: undefined,
showDone: false,
lists: {
[Tabs.TOPICS]: [],
[Tabs.ARTICLES]: [],
},
};
},
methods: {
addButton() {
if (!this.inputText) return;
const value = { ...Item, uuid: uuid.v4(), content: this.inputText };
database.ref(this.currentTab).child(value.uuid).set(value);
this.inputText = undefined;
},
sortButton() {
[Tabs.TOPICS, Tabs.ARTICLES].forEach((tab) => {
this.lists[tab].sort((a, b) => (b.positiveVotes - b.negativeVotes) - (a.positiveVotes - a.negativeVotes))
});
},
onVote(item, isPositive) {
if(isPositive) item.positiveVotes++;
else item.negativeVotes++;
database.ref(this.currentTab).child(item.uuid).set(item);
},
onRemove(item) {
database.ref(this.currentTab).child(item.uuid).remove();
},
onDone(item) {
item.done = !item.done;
database.ref(this.currentTab).child(item.uuid).set(item);
},
onSelect(item) {
item.selected = !item.selected;
database.ref(this.currentTab).child(item.uuid).set(item);
},
},
created() {
[Tabs.TOPICS, Tabs.ARTICLES].forEach((tab) => {
database.ref(tab).on("value", (s) => {
const values = s.val();
this.lists[tab] = Object.keys(values).map(k => values[k]);
});
});
},
});