1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +07:00

node and upload reducer

This commit is contained in:
muerwre 2019-08-06 18:32:51 +07:00
parent e0bba90d2e
commit 5045fbce8b
11 changed files with 87 additions and 19 deletions

View file

@ -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,
}; };

View file

@ -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);

View 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,
}
},
}

View file

@ -0,0 +1,3 @@
export const NODE_HANDLERS = {
};

View file

@ -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
View file

@ -0,0 +1,3 @@
export default function* nodeSaga() {
}

View file

@ -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);

View file

@ -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;
} }
}; };

View file

@ -0,0 +1,3 @@
export const UPLOAD_HANDLERS = {
}

View 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);

View file

@ -0,0 +1,3 @@
export default function* () {
}