mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
removed redux completely
This commit is contained in:
parent
26e6d8d41b
commit
a4bb07e9cf
323 changed files with 2464 additions and 3348 deletions
43
src/store/auth/AuthStore.ts
Normal file
43
src/store/auth/AuthStore.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import { IUser } from '~/types/auth';
|
||||
import { EMPTY_USER } from '~/constants/auth';
|
||||
import { makeAutoObservable } from 'mobx';
|
||||
import { makePersistable } from 'mobx-persist-store';
|
||||
|
||||
export class AuthStore {
|
||||
token: string = '';
|
||||
user: IUser = EMPTY_USER;
|
||||
private isTesterInternal: boolean = false;
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
|
||||
void makePersistable(this, {
|
||||
name: `vault48_auth_${process.env.REACT_APP_API_URL}`,
|
||||
properties: ['token', 'user'],
|
||||
storage: window.localStorage,
|
||||
});
|
||||
}
|
||||
|
||||
get isUser() {
|
||||
return !!this.token;
|
||||
}
|
||||
|
||||
setUser = (user: Partial<IUser>) => {
|
||||
this.user = { ...this.user, ...user };
|
||||
};
|
||||
|
||||
setToken = (token: string) => {
|
||||
this.token = token;
|
||||
};
|
||||
|
||||
setIsTester = (isTester: boolean) => (this.isTesterInternal = isTester);
|
||||
|
||||
get isTester() {
|
||||
return this.isUser && this.isTesterInternal;
|
||||
}
|
||||
|
||||
logout = () => {
|
||||
this.token = '';
|
||||
this.setUser(EMPTY_USER);
|
||||
};
|
||||
}
|
3
src/store/auth/useAuthStore.ts
Normal file
3
src/store/auth/useAuthStore.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
import { useStore } from '~/utils/context/StoreContextProvider';
|
||||
|
||||
export const useAuthStore = () => useStore().auth;
|
|
@ -1,5 +1,5 @@
|
|||
import { makeAutoObservable } from 'mobx';
|
||||
import { IFlowNode } from '~/redux/types';
|
||||
import { IFlowNode } from '~/types';
|
||||
|
||||
export class FlowStore {
|
||||
nodes: IFlowNode[] = [];
|
||||
|
|
|
@ -2,11 +2,13 @@ import { makeAutoObservable } from 'mobx';
|
|||
import { FlowStore } from '~/store/flow/FlowStore';
|
||||
import { ModalStore } from '~/store/modal/ModalStore';
|
||||
import { LabStore } from '~/store/lab/LabStore';
|
||||
import { AuthStore } from '~/store/auth/AuthStore';
|
||||
|
||||
export class Store {
|
||||
flow = new FlowStore();
|
||||
modal = new ModalStore();
|
||||
lab = new LabStore();
|
||||
auth = new AuthStore();
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { makeAutoObservable } from 'mobx';
|
||||
import { IFlowNode, ITag } from '~/redux/types';
|
||||
import { IFlowNode, ITag } from '~/types';
|
||||
import { ILabNode } from '~/types/lab';
|
||||
|
||||
export class LabStore {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { makeAutoObservable, runInAction } from 'mobx';
|
||||
import { IFile, UUID } from '~/redux/types';
|
||||
import { IFile, UUID } from '~/types';
|
||||
import { getFileType, uploadGetThumb } from '~/utils/uploader';
|
||||
import { has, omit, values } from 'ramda';
|
||||
import { UploadType } from '~/constants/uploads';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue