Support upgraded rooms (via links to successor/predecessor)
This commit is contained in:
parent
970f82ba29
commit
615aa2b781
11 changed files with 181 additions and 48 deletions
|
|
@ -1,17 +1,17 @@
|
|||
import { createStore } from 'vuex'
|
||||
import VuexPersistence from 'vuex-persist'
|
||||
|
||||
const USER = `convene_${ window.location.hostname }_user`
|
||||
const SETTINGS = `convene_${ window.location.hostname }_settings`
|
||||
export const STORE_KEY_USER = `convene_${ window.location.hostname }_user`
|
||||
export const STORE_KEY_SETTINGS = `convene_${ window.location.hostname }_settings`
|
||||
|
||||
// A Vuex plugin to persist the user object to either session or local storage, based on flag in the store state.
|
||||
//
|
||||
const persistUserPlugin = store => {
|
||||
var user;
|
||||
if (store.state.useLocalStorage) {
|
||||
user = JSON.parse(window.localStorage.getItem(USER));
|
||||
user = JSON.parse(window.localStorage.getItem(STORE_KEY_USER));
|
||||
} else {
|
||||
user = JSON.parse(window.sessionStorage.getItem(USER));
|
||||
user = JSON.parse(window.sessionStorage.getItem(STORE_KEY_USER));
|
||||
}
|
||||
const initialState = user ? { status: { loggedIn: true }, user } : { status: { loggedIn: false }, user: null };
|
||||
store.state.auth = initialState;
|
||||
|
|
@ -19,11 +19,11 @@ const persistUserPlugin = store => {
|
|||
store.subscribe((mutation, state) => {
|
||||
if (mutation.type == 'setUser' || mutation.type == 'setUseLocalStorage') {
|
||||
if (state.useLocalStorage) {
|
||||
window.localStorage.setItem(USER, JSON.stringify(state.auth.user));
|
||||
window.sessionStorage.removeItem(USER);
|
||||
window.localStorage.setItem(STORE_KEY_USER, JSON.stringify(state.auth.user));
|
||||
window.sessionStorage.removeItem(STORE_KEY_USER);
|
||||
} else {
|
||||
window.sessionStorage.setItem(USER, JSON.stringify(state.auth.user));
|
||||
window.localStorage.removeItem(USER);
|
||||
window.sessionStorage.setItem(STORE_KEY_USER, JSON.stringify(state.auth.user));
|
||||
window.localStorage.removeItem(STORE_KEY_USER);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -31,7 +31,7 @@ const persistUserPlugin = store => {
|
|||
|
||||
|
||||
const vuexPersistLocalStorage = new VuexPersistence({
|
||||
key: SETTINGS,
|
||||
key: STORE_KEY_SETTINGS,
|
||||
storage: localStorage,
|
||||
reducer: state => {
|
||||
if (state.useLocalStorage) {
|
||||
|
|
@ -40,6 +40,7 @@ const vuexPersistLocalStorage = new VuexPersistence({
|
|||
currentRoomId: state.currentRoomId,
|
||||
hasShownMissedItemsHint: state.hasShownMissedItemsHint,
|
||||
globalNotification: state.globalNotification,
|
||||
uaAccepted: state.uaAccepted,
|
||||
};
|
||||
} else {
|
||||
return {};
|
||||
|
|
@ -48,7 +49,7 @@ const vuexPersistLocalStorage = new VuexPersistence({
|
|||
})
|
||||
|
||||
const vuexPersistSessionStorage = new VuexPersistence({
|
||||
key: SETTINGS,
|
||||
key: STORE_KEY_SETTINGS,
|
||||
storage: sessionStorage,
|
||||
reducer: state => {
|
||||
if (!state.useLocalStorage) {
|
||||
|
|
@ -56,6 +57,7 @@ const vuexPersistSessionStorage = new VuexPersistence({
|
|||
language: state.language,
|
||||
currentRoomId: state.currentRoomId,
|
||||
hasShownMissedItemsHint: state.hasShownMissedItemsHint,
|
||||
uaAccepted: state.uaAccepted,
|
||||
};
|
||||
} else {
|
||||
return {};
|
||||
|
|
@ -63,10 +65,10 @@ const vuexPersistSessionStorage = new VuexPersistence({
|
|||
}
|
||||
})
|
||||
|
||||
const defaultUseSessionStorage = (sessionStorage.getItem(USER) != null);
|
||||
const defaultUseSessionStorage = (sessionStorage.getItem(STORE_KEY_USER) != null);
|
||||
|
||||
const store = createStore({
|
||||
state: { language: null, currentRoomId: null, auth: null, tempuser: null, useLocalStorage: !defaultUseSessionStorage, globalNotification: false },
|
||||
state: { language: null, currentRoomId: null, auth: null, tempuser: null, useLocalStorage: !defaultUseSessionStorage, globalNotification: false, uaAccepted: false },
|
||||
mutations: {
|
||||
loginSuccess(state, user) {
|
||||
state.auth.status.loggedIn = true;
|
||||
|
|
@ -100,6 +102,9 @@ const store = createStore({
|
|||
},
|
||||
setGlobalNotification(state, flag) {
|
||||
state.globalNotification = flag;
|
||||
},
|
||||
acceptUA(state, accepted) {
|
||||
state.uaAccepted = accepted;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue