Created
May 11, 2018 15:13
-
-
Save SSmale/6432a0d5841bc67b75dd30df413803eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import firebase from "@/store/firebase"; | |
| let ticketsDB = firebase.database.ref("tickets"); | |
| export const state = { | |
| tickets: [] | |
| }; | |
| export const getters = { | |
| getAllTickets: function(state) { | |
| return state.tickets; | |
| }, | |
| getSingleTicket: function(state) { | |
| return function(payload) { | |
| return state.tickets.find(t => t.id === payload); | |
| }; | |
| }, | |
| getSingleUserTickets: function(state) { | |
| return function(payload) { | |
| return state.tickets.filter(t => t.user === payload.uid); | |
| }; | |
| } | |
| }; | |
| export const mutations = { | |
| storeTickets: function(state, payload) { | |
| let temp = []; | |
| for (let item in payload) { | |
| let ticket = { | |
| id: item, | |
| title: payload[item].title, | |
| message: payload[item].message, | |
| imageUrl: payload[item].imageUrl, | |
| status: payload[item].status, | |
| user: payload[item].user | |
| }; | |
| temp.push(ticket); | |
| } | |
| state.tickets = temp; | |
| } | |
| }; | |
| export const actions = { | |
| addTicket: function(context, ticket) { | |
| return ticketsDB.push(ticket).then(data => { | |
| return data.key; | |
| }); | |
| }, | |
| getAllFirebaseTickets: function(context) { | |
| ticketsDB.on("value", function(snapshot) { | |
| context.commit("storeTickets", snapshot.val()); | |
| context.dispatch("isNotLoading"); | |
| }); | |
| } | |
| }; | |
| export default { | |
| state, | |
| getters, | |
| mutations, | |
| actions | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment