2022-07-27 06:54:43 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
import { defaultPortalFlags } from './index';
|
|
|
|
|
|
|
|
export const types = {
|
|
|
|
SET_UI_FLAG: 'setUIFlag',
|
|
|
|
ADD_PORTAL_ENTRY: 'addPortalEntry',
|
2022-08-08 10:17:32 +00:00
|
|
|
SET_PORTALS_META: 'setPortalsMeta',
|
2022-07-27 06:54:43 +00:00
|
|
|
ADD_MANY_PORTALS_ENTRY: 'addManyPortalsEntry',
|
|
|
|
ADD_PORTAL_ID: 'addPortalId',
|
2022-08-08 10:17:32 +00:00
|
|
|
CLEAR_PORTALS: 'clearPortals',
|
2022-07-27 06:54:43 +00:00
|
|
|
ADD_MANY_PORTALS_IDS: 'addManyPortalsIds',
|
2022-08-08 10:17:32 +00:00
|
|
|
SET_SELECTED_PORTAL_ID: 'setSelectedPortalId',
|
2022-07-27 06:54:43 +00:00
|
|
|
UPDATE_PORTAL_ENTRY: 'updatePortalEntry',
|
|
|
|
REMOVE_PORTAL_ENTRY: 'removePortalEntry',
|
|
|
|
REMOVE_PORTAL_ID: 'removePortalId',
|
|
|
|
SET_HELP_PORTAL_UI_FLAG: 'setHelpCenterUIFlag',
|
|
|
|
};
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
[types.SET_UI_FLAG]($state, uiFlags) {
|
|
|
|
$state.uiFlags = {
|
|
|
|
...$state.uiFlags,
|
|
|
|
...uiFlags,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
[types.ADD_PORTAL_ENTRY]($state, portal) {
|
|
|
|
Vue.set($state.portals.byId, portal.id, {
|
|
|
|
...portal,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
[types.ADD_MANY_PORTALS_ENTRY]($state, portals) {
|
|
|
|
const allPortals = { ...$state.portals.byId };
|
|
|
|
portals.forEach(portal => {
|
|
|
|
allPortals[portal.id] = portal;
|
|
|
|
});
|
2022-08-08 10:17:32 +00:00
|
|
|
Vue.set($state.portals, 'byId', allPortals);
|
|
|
|
},
|
|
|
|
|
|
|
|
[types.CLEAR_PORTALS]: $state => {
|
|
|
|
Vue.set($state.portals, 'byId', {});
|
|
|
|
Vue.set($state.portals, 'allIds', []);
|
|
|
|
Vue.set($state.portals, 'uiFlags', {});
|
|
|
|
},
|
|
|
|
|
|
|
|
[types.SET_PORTALS_META]: ($state, data) => {
|
|
|
|
const { portals_count: count, current_page: currentPage } = data;
|
|
|
|
Vue.set($state.meta, 'count', count);
|
|
|
|
Vue.set($state.meta, 'currentPage', currentPage);
|
|
|
|
},
|
|
|
|
|
|
|
|
[types.SET_SELECTED_PORTAL_ID]: ($state, portalId) => {
|
|
|
|
Vue.set($state.portals, 'selectedPortalId', portalId);
|
2022-07-27 06:54:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
[types.ADD_PORTAL_ID]($state, portalId) {
|
|
|
|
$state.portals.allIds.push(portalId);
|
|
|
|
},
|
|
|
|
|
|
|
|
[types.ADD_MANY_PORTALS_IDS]($state, portalIds) {
|
|
|
|
$state.portals.allIds.push(...portalIds);
|
|
|
|
},
|
|
|
|
|
|
|
|
[types.UPDATE_PORTAL_ENTRY]($state, portal) {
|
|
|
|
const portalId = portal.id;
|
|
|
|
if (!$state.portals.allIds.includes(portalId)) return;
|
|
|
|
|
|
|
|
Vue.set($state.portals.byId, portalId, {
|
|
|
|
...portal,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
[types.REMOVE_PORTAL_ENTRY]($state, portalId) {
|
|
|
|
if (!portalId) return;
|
|
|
|
|
|
|
|
const { [portalId]: toBeRemoved, ...newById } = $state.portals.byId;
|
|
|
|
Vue.set($state.portals, 'byId', newById);
|
|
|
|
},
|
|
|
|
|
|
|
|
[types.REMOVE_PORTAL_ID]($state, portalId) {
|
|
|
|
$state.portals.allIds = $state.portals.allIds.filter(id => id !== portalId);
|
|
|
|
},
|
|
|
|
|
|
|
|
[types.SET_HELP_PORTAL_UI_FLAG]($state, { portalId, uiFlags }) {
|
|
|
|
const flags = $state.portals.uiFlags.byId[portalId];
|
|
|
|
Vue.set($state.portals.uiFlags.byId, portalId, {
|
|
|
|
...defaultPortalFlags,
|
|
|
|
...flags,
|
|
|
|
...uiFlags,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|