thelounge/client/js/store.js

101 lines
2.7 KiB
JavaScript
Raw Normal View History

import Vue from "vue";
import Vuex from "vuex";
const storage = require("./localStorage");
Vue.use(Vuex);
const store = new Vuex.Store({
2019-02-27 15:15:34 +01:00
state: {
activeChannel: null,
currentUserVisibleError: null,
desktopNotificationState: "unsupported",
isAutoCompleting: false,
2019-02-27 15:15:34 +01:00
isConnected: false,
isFileUploadEnabled: false,
2019-02-27 15:15:34 +01:00
isNotified: false,
2019-02-27 19:15:58 +01:00
activeWindow: null,
networks: [],
pushNotificationState: "unsupported",
serverConfiguration: {},
2019-03-03 18:47:49 +01:00
sessions: [],
sidebarOpen: false,
2019-08-05 14:24:44 +02:00
sidebarDragging: false,
userlistOpen: storage.get("thelounge.state.userlist") !== "false",
2019-08-05 16:29:35 +02:00
versionData: null,
versionStatus: "loading",
versionDataExpired: false,
2019-02-27 15:15:34 +01:00
},
mutations: {
activeChannel(state, channel) {
state.activeChannel = channel;
},
currentUserVisibleError(state, error) {
state.currentUserVisibleError = error;
},
desktopNotificationState(state, desktopNotificationState) {
state.desktopNotificationState = desktopNotificationState;
},
isAutoCompleting(state, isAutoCompleting) {
state.isAutoCompleting = isAutoCompleting;
},
2019-02-27 15:15:34 +01:00
isConnected(state, payload) {
state.isConnected = payload;
},
isFileUploadEnabled(state, isFileUploadEnabled) {
state.isFileUploadEnabled = isFileUploadEnabled;
},
2019-02-27 15:15:34 +01:00
isNotified(state, payload) {
state.isNotified = payload;
},
2019-02-27 19:15:58 +01:00
activeWindow(state, payload) {
state.activeWindow = payload;
},
networks(state, networks) {
state.networks = networks;
},
removeNetwork(state, networkId) {
state.networks.splice(store.state.networks.findIndex((n) => n.uuid === networkId), 1);
},
sortNetworks(state, sortFn) {
state.networks.sort(sortFn);
},
pushNotificationState(state, pushNotificationState) {
state.pushNotificationState = pushNotificationState;
},
serverConfiguration(state, serverConfiguration) {
state.serverConfiguration = serverConfiguration;
},
2019-03-03 18:47:49 +01:00
sessions(state, payload) {
state.sessions = payload;
},
sidebarOpen(state, payload) {
state.sidebarOpen = payload;
},
2019-08-05 14:24:44 +02:00
sidebarDragging(state, payload) {
state.sidebarDragging = payload;
},
userlistOpen(state, payload) {
state.userlistOpen = payload;
},
2019-08-05 16:29:35 +02:00
versionData(state, payload) {
state.versionData = payload;
},
versionStatus(state, payload) {
state.versionStatus = payload;
},
versionDataExpired(state, payload) {
state.versionDataExpired = payload;
},
2019-03-03 18:47:49 +01:00
},
getters: {
currentSession: (state) => state.sessions.find((item) => item.current),
otherSessions: (state) => state.sessions.filter((item) => !item.current),
2019-11-03 12:23:03 +01:00
findChannelOnCurrentNetwork: (state) => (name) => {
name = name.toLowerCase();
return state.activeChannel.network.channels.find((c) => c.name.toLowerCase() === name);
},
},
});
export default store;