mirror of
				https://github.com/KevinMidboe/planetposen.git
				synced 2025-10-29 17:50:32 +00:00 
			
		
		
		
	Cart store module.
This commit is contained in:
		| @@ -1,7 +1,7 @@ | ||||
| import Vue from 'vue' | ||||
| import VueRouter from 'vue-router' | ||||
| import router from './routes' | ||||
| // import store from './store' | ||||
| import store from './store' | ||||
|  | ||||
| import App from './App.vue' | ||||
|  | ||||
| @@ -10,7 +10,7 @@ Vue.use(VueRouter) | ||||
| new Vue({ | ||||
|   el: '#app', | ||||
|   router, | ||||
|   // store, | ||||
|   store, | ||||
|   components: { App }, | ||||
|   render: h => h(App) | ||||
| }) | ||||
							
								
								
									
										44
									
								
								frontend/modules/cartModule.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								frontend/modules/cartModule.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,44 @@ | ||||
|  | ||||
| const updateLocalStorage = (key, value) => { | ||||
|   localStorage.setItem(key, JSON.stringify(value)); | ||||
| } | ||||
| const getParsedFromLocalStorage = key => { | ||||
|   const value = localStorage.getItem(key); | ||||
|   try { | ||||
|     return JSON.parse(value) | ||||
|   } catch { | ||||
|     return null  | ||||
|   } | ||||
| } | ||||
|  | ||||
| export default { | ||||
|   namespaced: true, | ||||
|   state: { | ||||
|     inventory: getParsedFromLocalStorage('inventory') || [], | ||||
|   }, | ||||
|   getters: { | ||||
|     inventory: state => { | ||||
|       return state.inventory; | ||||
|     } | ||||
|   }, | ||||
|   mutations: { | ||||
|     ADD_ITEM_TO_CART: (state, item) => { | ||||
|       state.inventory.push(item); | ||||
|  | ||||
|       updateLocalStorage('inventory', state.inventory) | ||||
|     }, | ||||
|     REMOVE_ITEM_FROM_CART: (state, item) => { | ||||
|       state.inventory = state.inventory.filter(i => i !== item) | ||||
|  | ||||
|       updateLocalStorage('inventory', state.inventory) | ||||
|     } | ||||
|   }, | ||||
|   actions: { | ||||
|     addItemToCart({ commit }, item) { | ||||
|       commit("ADD_ITEM_TO_CART", item); | ||||
|     }, | ||||
|     removeItemFromCart({ commit }, item) { | ||||
|       commit('REMOVE_ITEM_FROM_CART', item) | ||||
|     } | ||||
|   } | ||||
| }; | ||||
| @@ -1,117 +0,0 @@ | ||||
|  | ||||
| export default { | ||||
|   namespaced: true, | ||||
|   state: { | ||||
|     player: undefined, | ||||
|     playlist: [], | ||||
|     authenticatedAdmin: false, | ||||
|     channelSettings: null, | ||||
|     clientSettings: null, | ||||
|     nowPlaying: null, | ||||
|     userSuggested: [], | ||||
|     externalSuggested: [], | ||||
|     PLAYER_STATES: { | ||||
|       BUFFERING: 3, | ||||
|       CUED: 5, | ||||
|       ENDED: 0, | ||||
|       PAUSED: 2, | ||||
|       PLAYING: 1, | ||||
|       UNSTARTED: -1 | ||||
|     }, | ||||
|     socket: null, | ||||
|     channel: "summér" | ||||
|   }, | ||||
|   getters: { | ||||
|     channel: state => { | ||||
|       return state.channel; | ||||
|     }, | ||||
|     socket: state => { | ||||
|       return state.socket | ||||
|     }, | ||||
|     PLAYER_STATES: state => { | ||||
|       return state.PLAYER_STATES; | ||||
|     }, | ||||
|     authenticatedAdmin: state => { | ||||
|       return state.authenticatedAdmin; | ||||
|     }, | ||||
|     playlist: state => { | ||||
|       return state.playlist; | ||||
|     }, | ||||
|     channelSettings: state => { | ||||
|       return state.channelSettings; | ||||
|     }, | ||||
|     clientSettings: state => { | ||||
|       return state.clientSettings; | ||||
|     }, | ||||
|     nowPlaying: state => { | ||||
|       return state.nowPlaying; | ||||
|     }, | ||||
|     userSuggested: state => { | ||||
|       return state.userSuggested; | ||||
|     }, | ||||
|     externalSuggested: state => { | ||||
|       return state.externalSuggested; | ||||
|     }, | ||||
|     player: state => { | ||||
|       return state.player; | ||||
|     } | ||||
|   }, | ||||
|   mutations: { | ||||
|     SET_CHANNEL: (state, channel) => { | ||||
|       state.channel = channel; | ||||
|     }, | ||||
|     SET_AUTHENTICATED_ADMIN: (state, authenticatedAdmin) => { | ||||
|       state.authenticatedAdmin = authenticatedAdmin; | ||||
|     }, | ||||
|     SET_PLAYLIST: (state, playlist) => { | ||||
|       state.playlist = playlist; | ||||
|     }, | ||||
|     SET_CHANNEL_SETTINGS: (state, channelSettings) => { | ||||
|       state.channelSettings = channelSettings; | ||||
|     }, | ||||
|     SET_CLIENT_SETTINGS: (state, clientSettings) => { | ||||
|       state.clientSettings = clientSettings; | ||||
|     }, | ||||
|     SET_NOW_PLAYING: (state, nowPlaying) => { | ||||
|       state.nowPlaying = nowPlaying; | ||||
|     }, | ||||
|     SET_USER_SUGGESTED: (state, userSuggested) => { | ||||
|       state.userSuggested = userSuggested; | ||||
|     }, | ||||
|     SET_EXTERNAL_SUGGESTED: (state, externalSuggested) => { | ||||
|       state.externalSuggested = externalSuggested; | ||||
|     }, | ||||
|     SET_PLAYER: (state, player) => { | ||||
|       state.player = player; | ||||
|     } | ||||
|   }, | ||||
|   actions: { | ||||
|     setChannel({ commit }, channel) { | ||||
|       commit("SET_CHANNEL", channel.toLowerCase()); | ||||
|     }, | ||||
|     setAuthenticatedAdmin({ commit }, authenticatedAdmin) { | ||||
|       commit("SET_AUTHENTICATED_ADMIN", authenticatedAdmin); | ||||
|     }, | ||||
|     setPlaylist({ commit }, playlist) { | ||||
|       commit("SET_PLAYLIST", playlist); | ||||
|     }, | ||||
|     setChannelSettings({ commit }, channelSettings) { | ||||
|       commit("SET_CHANNEL_SETTINGS", channelSettings); | ||||
|     }, | ||||
|     setClientSettings({ commit }, clientSettings) { | ||||
|       commit("SET_CLIENT_SETTINGS", clientSettings); | ||||
|     }, | ||||
|     setNowPlaying({ commit }, nowPlaying) { | ||||
|       commit("SET_NOW_PLAYING", nowPlaying); | ||||
|     }, | ||||
|     setUserSuggested({ commit }, userSuggested) { | ||||
|       commit("SET_USER_SUGGESTED", userSuggested); | ||||
|     }, | ||||
|     setExternalSuggested({ commit }, externalSuggested) { | ||||
|       commit("SET_EXTERNAL_SUGGESTED", externalSuggested); | ||||
|     }, | ||||
|     setPlayer({ commit }, player) { | ||||
|       commit("SET_PLAYER", player); | ||||
|     } | ||||
|   } | ||||
| }; | ||||
| @@ -1,13 +1,12 @@ | ||||
| import Vue from 'vue'; | ||||
| import Vuex from 'vuex'; | ||||
|  | ||||
| import playerModule from '@/modules/playerModule'; | ||||
|  | ||||
| Vue.use(Vuex); | ||||
|  | ||||
| import cartModule from '@/modules/cartModule'; | ||||
|  | ||||
| const store = new Vuex.Store({ | ||||
|   modules: { | ||||
|     playerModule | ||||
|     cartModule | ||||
|   } | ||||
| }) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user