You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
906 B
TypeScript
44 lines
906 B
TypeScript
import defaultSettings from '../settings.json';
|
|
export interface GlobalState {
|
|
settings?: typeof defaultSettings;
|
|
userInfo?: {
|
|
name?: string;
|
|
avatar?: string;
|
|
job?: string;
|
|
organization?: string;
|
|
location?: string;
|
|
email?: string;
|
|
permissions: Record<string, string[]>;
|
|
};
|
|
userLoading?: boolean;
|
|
}
|
|
|
|
const initialState: GlobalState = {
|
|
settings: defaultSettings,
|
|
userInfo: {
|
|
permissions: {},
|
|
},
|
|
};
|
|
|
|
export default function store(state = initialState, action) {
|
|
switch (action.type) {
|
|
case 'update-settings': {
|
|
const { settings } = action.payload;
|
|
return {
|
|
...state,
|
|
settings,
|
|
};
|
|
}
|
|
case 'update-userInfo': {
|
|
const { userInfo = initialState.userInfo, userLoading } = action.payload;
|
|
return {
|
|
...state,
|
|
userLoading,
|
|
userInfo,
|
|
};
|
|
}
|
|
default:
|
|
return state;
|
|
}
|
|
}
|