- initial;

This commit is contained in:
Vitalii Kiiko
2024-08-09 08:51:20 +02:00
commit 987b1b0110
46 changed files with 30261 additions and 0 deletions

15
src/store/actions.js Normal file
View File

@@ -0,0 +1,15 @@
export const actionsAlpha = (set, get, api) => ({
setAsyncRequest: () => {
const num = get.isAsyncRequest();
set.isAsyncRequest(num + 1);
},
unsetAsyncRequest: () => {
const num = get.isAsyncRequest();
set.isAsyncRequest(num - 1 < 0 ? 0 : num - 1);
},
})
export const actionsBeta = (set, get, api) => ({
});

20
src/store/index.js Normal file
View File

@@ -0,0 +1,20 @@
import { mapValuesKey } from 'zustand-x';
// stores
import { mainStore } from './main';
// Global store - initial data
const dashboardStore = {
main: mainStore
};
// Global hook selectors
export const useStore = () => mapValuesKey('use', dashboardStore);
// Global tracked hook selectors
export const useTrackedStore = () => mapValuesKey('useTracked', dashboardStore);
// Global getter selectors
export const storeGet = mapValuesKey('get', dashboardStore);
// Global actions
export const storeSet = mapValuesKey('set', dashboardStore);
export default dashboardStore;

6
src/store/initial.js Normal file
View File

@@ -0,0 +1,6 @@
const initialStore = {
// ui related
isAsyncRequest: 0, // number
}
export default initialStore;

11
src/store/main.js Normal file
View File

@@ -0,0 +1,11 @@
import { createStore } from 'zustand-x';
import zustandXOpts from './zustand-x-opts';
import initialStore from './initial';
import selectors from './selectors';
import { actionsAlpha, actionsBeta } from './actions';
export const mainStore = createStore('main')(initialStore, zustandXOpts)
.extendSelectors(selectors)
.extendActions(actionsAlpha)
.extendActions(actionsBeta);

10
src/store/selectors.js Normal file
View File

@@ -0,0 +1,10 @@
import { isEmpty } from 'ramda';
const selectors = (state, get, api) => ({
getToken: () => {
const userData = get.userData();
return userData.access && !isEmpty(userData.access) ? userData.access : null;
},
})
export default selectors;

View File

@@ -0,0 +1,16 @@
const zustandXOpts = {
devtools: {
enabled: true
},
persist: {
enabled: true,
partialize: (state) => ({
userData: state.userData,
hubsList: state.hubsList,
chosenHub: state.chosenHub,
groups: state.groups,
}),
}
}
export default zustandXOpts;