mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
node and upload reducer
This commit is contained in:
parent
e0bba90d2e
commit
5045fbce8b
11 changed files with 87 additions and 19 deletions
|
@ -10,12 +10,12 @@ export const MODAL_ACTIONS = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DIALOGS = {
|
export const DIALOGS = {
|
||||||
TEST: 'TEST',
|
EDITOR: 'EDITOR',
|
||||||
LOGIN: 'LOGIN',
|
LOGIN: 'LOGIN',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DIALOG_CONTENT = {
|
export const DIALOG_CONTENT = {
|
||||||
[DIALOGS.TEST]: ExampleDialog,
|
[DIALOGS.EDITOR]: ExampleDialog,
|
||||||
[DIALOGS.LOGIN]: LoginDialog,
|
[DIALOGS.LOGIN]: LoginDialog,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ export interface IModalState {
|
||||||
|
|
||||||
const INITIAL_STATE: IModalState = {
|
const INITIAL_STATE: IModalState = {
|
||||||
is_shown: true,
|
is_shown: true,
|
||||||
dialog: DIALOGS.LOGIN,
|
dialog: DIALOGS.EDITOR,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default createReducer(INITIAL_STATE, MODAL_HANDLERS);
|
export default createReducer(INITIAL_STATE, MODAL_HANDLERS);
|
||||||
|
|
20
src/redux/node/constants.ts
Normal file
20
src/redux/node/constants.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import { INode } from "../types";
|
||||||
|
|
||||||
|
export const EMPTY_NODE: INode = {
|
||||||
|
id: null,
|
||||||
|
|
||||||
|
user_id: null,
|
||||||
|
|
||||||
|
title: '',
|
||||||
|
files: [],
|
||||||
|
|
||||||
|
cover: null,
|
||||||
|
type: null,
|
||||||
|
|
||||||
|
options: {
|
||||||
|
flow: {
|
||||||
|
display: 'single',
|
||||||
|
show_description: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
3
src/redux/node/handlers.ts
Normal file
3
src/redux/node/handlers.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export const NODE_HANDLERS = {
|
||||||
|
|
||||||
|
};
|
|
@ -1,15 +1,18 @@
|
||||||
import { createReducer } from "~/utils/reducer";
|
import { createReducer } from "~/utils/reducer";
|
||||||
|
import { INode } from "../types";
|
||||||
|
import { EMPTY_NODE } from "./constants";
|
||||||
|
import { NODE_HANDLERS } from "./handlers";
|
||||||
|
|
||||||
export type INodeState = {
|
export type INodeState = Readonly<{
|
||||||
is_loading: boolean;
|
is_loading: boolean;
|
||||||
}
|
editor: INode;
|
||||||
|
}>;
|
||||||
const HANDLERS = {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
const INITIAL_STATE: INodeState = {
|
const INITIAL_STATE: INodeState = {
|
||||||
|
editor: {
|
||||||
|
...EMPTY_NODE,
|
||||||
|
},
|
||||||
is_loading: false,
|
is_loading: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default createReducer(INITIAL_STATE, HANDLERS);
|
export default createReducer(INITIAL_STATE, NODE_HANDLERS);
|
3
src/redux/node/sagas.ts
Normal file
3
src/redux/node/sagas.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export default function* nodeSaga() {
|
||||||
|
|
||||||
|
}
|
|
@ -8,17 +8,23 @@ import { createBrowserHistory } from "history";
|
||||||
import { PersistConfig, Persistor } from "redux-persist/es/types";
|
import { PersistConfig, Persistor } from "redux-persist/es/types";
|
||||||
import { routerMiddleware } from "connected-react-router";
|
import { routerMiddleware } from "connected-react-router";
|
||||||
|
|
||||||
import userReducer from "~/redux/auth/reducer";
|
import authReducer from "~/redux/auth/reducer";
|
||||||
import userSaga from "~/redux/auth/sagas";
|
import authSaga from "~/redux/auth/sagas";
|
||||||
|
|
||||||
|
import nodeReducer, { INodeState } from "~/redux/node/reducer";
|
||||||
|
import nodeSaga from "~/redux/node/sagas";
|
||||||
|
|
||||||
|
import uploadReducer, { IUploadState } from "~/redux/uploads/reducer";
|
||||||
|
import uploadSaga from "~/redux/node/sagas";
|
||||||
|
|
||||||
import { IAuthState } from "~/redux/auth/types";
|
import { IAuthState } from "~/redux/auth/types";
|
||||||
|
|
||||||
import modalReducer, { IModalState } from "~/redux/modal/reducer";
|
import modalReducer, { IModalState } from "~/redux/modal/reducer";
|
||||||
import { IState } from "~/redux/store";
|
import { IState } from "~/redux/store";
|
||||||
|
|
||||||
const userPersistConfig: PersistConfig = {
|
const authPersistConfig: PersistConfig = {
|
||||||
key: "user",
|
key: "auth",
|
||||||
whitelist: ["profile"],
|
whitelist: ["token"],
|
||||||
storage
|
storage
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,6 +32,8 @@ export interface IState {
|
||||||
auth: IAuthState;
|
auth: IAuthState;
|
||||||
modal: IModalState;
|
modal: IModalState;
|
||||||
router: RouterState;
|
router: RouterState;
|
||||||
|
node: INodeState;
|
||||||
|
uploads: IUploadState;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const sagaMiddleware = createSagaMiddleware();
|
export const sagaMiddleware = createSagaMiddleware();
|
||||||
|
@ -38,15 +46,19 @@ const composeEnhancers =
|
||||||
|
|
||||||
export const store = createStore(
|
export const store = createStore(
|
||||||
combineReducers<IState>({
|
combineReducers<IState>({
|
||||||
auth: persistReducer(userPersistConfig, userReducer),
|
auth: persistReducer(authPersistConfig, authReducer),
|
||||||
modal: modalReducer,
|
modal: modalReducer,
|
||||||
router: connectRouter(history)
|
router: connectRouter(history),
|
||||||
|
node: nodeReducer,
|
||||||
|
uploads: uploadReducer,
|
||||||
}),
|
}),
|
||||||
composeEnhancers(applyMiddleware(routerMiddleware(history), sagaMiddleware))
|
composeEnhancers(applyMiddleware(routerMiddleware(history), sagaMiddleware))
|
||||||
);
|
);
|
||||||
|
|
||||||
export function configureStore(): { store: Store<IState>; persistor: Persistor } {
|
export function configureStore(): { store: Store<IState>; persistor: Persistor } {
|
||||||
sagaMiddleware.run(userSaga);
|
sagaMiddleware.run(authSaga);
|
||||||
|
sagaMiddleware.run(nodeSaga);
|
||||||
|
sagaMiddleware.run(uploadSaga);
|
||||||
|
|
||||||
const persistor = persistStore(store);
|
const persistor = persistStore(store);
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,7 @@ export interface INode {
|
||||||
id?: UUID;
|
id?: UUID;
|
||||||
user_id: UUID;
|
user_id: UUID;
|
||||||
|
|
||||||
|
title: string;
|
||||||
files: IFile[];
|
files: IFile[];
|
||||||
|
|
||||||
cover: IFile['id'];
|
cover: IFile['id'];
|
||||||
|
@ -82,7 +83,7 @@ export interface INode {
|
||||||
options: {
|
options: {
|
||||||
flow: {
|
flow: {
|
||||||
display: 'single' | 'double' | 'quadro';
|
display: 'single' | 'double' | 'quadro';
|
||||||
has_description: boolean;
|
show_description: boolean;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
3
src/redux/uploads/handlers.ts
Normal file
3
src/redux/uploads/handlers.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export const UPLOAD_HANDLERS = {
|
||||||
|
|
||||||
|
}
|
20
src/redux/uploads/reducer.ts
Normal file
20
src/redux/uploads/reducer.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import { createReducer } from "~/utils/reducer";
|
||||||
|
import { IFile } from "~/constants/cells";
|
||||||
|
import { UUID } from "../types";
|
||||||
|
import { UPLOAD_HANDLERS } from "./handlers";
|
||||||
|
|
||||||
|
export interface IUploadStatus {
|
||||||
|
progress: number; is_loading: boolean; error: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IUploadState {
|
||||||
|
files: Record<UUID, IFile>;
|
||||||
|
statuses: Record<UUID, IUploadStatus>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const INITIAL_STATE = {
|
||||||
|
files: {},
|
||||||
|
statuses: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default createReducer(INITIAL_STATE, UPLOAD_HANDLERS);
|
3
src/redux/uploads/sagas.ts
Normal file
3
src/redux/uploads/sagas.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export default function* () {
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue