mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
removed node related from sagas and reducers
This commit is contained in:
parent
d202a8cb18
commit
e8f8e3536d
7 changed files with 15 additions and 46 deletions
|
@ -26,7 +26,6 @@ const NodePage: FC<Props> = ({
|
||||||
isLoadingComments,
|
isLoadingComments,
|
||||||
comments,
|
comments,
|
||||||
commentsCount,
|
commentsCount,
|
||||||
related,
|
|
||||||
lastSeenCurrent,
|
lastSeenCurrent,
|
||||||
} = useFullNode(id);
|
} = useFullNode(id);
|
||||||
|
|
||||||
|
|
|
@ -69,11 +69,6 @@ export const nodeSetComments = (comments: IComment[]) => ({
|
||||||
type: NODE_ACTIONS.SET_COMMENTS,
|
type: NODE_ACTIONS.SET_COMMENTS,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const nodeSetRelated = (related: INodeState['related']) => ({
|
|
||||||
related,
|
|
||||||
type: NODE_ACTIONS.SET_RELATED,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const nodeUpdateTags = (id: INode['id'], tags: string[]) => ({
|
export const nodeUpdateTags = (id: INode['id'], tags: string[]) => ({
|
||||||
type: NODE_ACTIONS.UPDATE_TAGS,
|
type: NODE_ACTIONS.UPDATE_TAGS,
|
||||||
id,
|
id,
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
import { assocPath } from 'ramda';
|
import { assocPath } from 'ramda';
|
||||||
import { NODE_ACTIONS } from './constants';
|
import { NODE_ACTIONS } from './constants';
|
||||||
import {
|
import {
|
||||||
nodeSetSaveErrors,
|
|
||||||
nodeSetLoading,
|
|
||||||
nodeSetCurrent,
|
|
||||||
nodeSetLoadingComments,
|
|
||||||
nodeSetSendingComment,
|
|
||||||
nodeSetComments,
|
|
||||||
nodeSetTags,
|
|
||||||
nodeSetEditor,
|
|
||||||
nodeSetCoverImage,
|
|
||||||
nodeSetRelated,
|
|
||||||
nodeSet,
|
nodeSet,
|
||||||
|
nodeSetComments,
|
||||||
|
nodeSetCoverImage,
|
||||||
|
nodeSetCurrent,
|
||||||
|
nodeSetEditor,
|
||||||
|
nodeSetLoading,
|
||||||
|
nodeSetLoadingComments,
|
||||||
|
nodeSetSaveErrors,
|
||||||
|
nodeSetSendingComment,
|
||||||
|
nodeSetTags,
|
||||||
} from './actions';
|
} from './actions';
|
||||||
import { INodeState } from './reducer';
|
import { INodeState } from './reducer';
|
||||||
|
|
||||||
|
@ -42,9 +41,6 @@ const setSendingComment = (
|
||||||
const setComments = (state: INodeState, { comments }: ReturnType<typeof nodeSetComments>) =>
|
const setComments = (state: INodeState, { comments }: ReturnType<typeof nodeSetComments>) =>
|
||||||
assocPath(['comments'], comments, state);
|
assocPath(['comments'], comments, state);
|
||||||
|
|
||||||
const setRelated = (state: INodeState, { related }: ReturnType<typeof nodeSetRelated>) =>
|
|
||||||
assocPath(['related'], related, state);
|
|
||||||
|
|
||||||
const setTags = (state: INodeState, { tags }: ReturnType<typeof nodeSetTags>) =>
|
const setTags = (state: INodeState, { tags }: ReturnType<typeof nodeSetTags>) =>
|
||||||
assocPath(['current', 'tags'], tags, state);
|
assocPath(['current', 'tags'], tags, state);
|
||||||
|
|
||||||
|
@ -64,7 +60,6 @@ export const NODE_HANDLERS = {
|
||||||
[NODE_ACTIONS.SET_CURRENT]: setCurrent,
|
[NODE_ACTIONS.SET_CURRENT]: setCurrent,
|
||||||
[NODE_ACTIONS.SET_SENDING_COMMENT]: setSendingComment,
|
[NODE_ACTIONS.SET_SENDING_COMMENT]: setSendingComment,
|
||||||
[NODE_ACTIONS.SET_COMMENTS]: setComments,
|
[NODE_ACTIONS.SET_COMMENTS]: setComments,
|
||||||
[NODE_ACTIONS.SET_RELATED]: setRelated,
|
|
||||||
[NODE_ACTIONS.SET_TAGS]: setTags,
|
[NODE_ACTIONS.SET_TAGS]: setTags,
|
||||||
[NODE_ACTIONS.SET_EDITOR]: setEditor,
|
[NODE_ACTIONS.SET_EDITOR]: setEditor,
|
||||||
[NODE_ACTIONS.SET_COVER_IMAGE]: setCoverImage,
|
[NODE_ACTIONS.SET_COVER_IMAGE]: setCoverImage,
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
import { createReducer } from '~/utils/reducer';
|
import { createReducer } from '~/utils/reducer';
|
||||||
import { IComment, IFile, INode } from '../types';
|
import { IComment, IFile, INode } from '../types';
|
||||||
import { EMPTY_COMMENT, EMPTY_NODE } from './constants';
|
import { EMPTY_NODE } from './constants';
|
||||||
import { NODE_HANDLERS } from './handlers';
|
import { NODE_HANDLERS } from './handlers';
|
||||||
import { INodeRelated } from '~/redux/node/types';
|
|
||||||
|
|
||||||
export type INodeState = Readonly<{
|
export type INodeState = Readonly<{
|
||||||
editor: INode;
|
editor: INode;
|
||||||
current: INode;
|
current: INode;
|
||||||
comments: IComment[];
|
comments: IComment[];
|
||||||
related: INodeRelated;
|
|
||||||
lastSeenCurrent?: string;
|
lastSeenCurrent?: string;
|
||||||
comment_count: number;
|
comment_count: number;
|
||||||
current_cover_image?: IFile;
|
current_cover_image?: IFile;
|
||||||
|
@ -31,10 +29,6 @@ const INITIAL_STATE: INodeState = {
|
||||||
current: { ...EMPTY_NODE },
|
current: { ...EMPTY_NODE },
|
||||||
comment_count: 0,
|
comment_count: 0,
|
||||||
comments: [],
|
comments: [],
|
||||||
related: {
|
|
||||||
albums: {},
|
|
||||||
similar: [],
|
|
||||||
},
|
|
||||||
current_cover_image: undefined,
|
current_cover_image: undefined,
|
||||||
|
|
||||||
is_loading: false,
|
is_loading: false,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { all, call, put, select, takeLatest, takeLeading } from 'redux-saga/effects';
|
import { call, put, select, takeLatest, takeLeading } from 'redux-saga/effects';
|
||||||
import { push } from 'connected-react-router';
|
import { push } from 'connected-react-router';
|
||||||
|
|
||||||
import { COMMENTS_DISPLAY, EMPTY_NODE, NODE_ACTIONS, NODE_EDITOR_DATA } from './constants';
|
import { COMMENTS_DISPLAY, EMPTY_NODE, NODE_ACTIONS, NODE_EDITOR_DATA } from './constants';
|
||||||
|
@ -18,7 +18,6 @@ import {
|
||||||
nodeSetEditor,
|
nodeSetEditor,
|
||||||
nodeSetLoading,
|
nodeSetLoading,
|
||||||
nodeSetLoadingComments,
|
nodeSetLoadingComments,
|
||||||
nodeSetRelated,
|
|
||||||
nodeSetTags,
|
nodeSetTags,
|
||||||
nodeSubmitLocal,
|
nodeSubmitLocal,
|
||||||
nodeUpdateTags,
|
nodeUpdateTags,
|
||||||
|
@ -27,7 +26,6 @@ import {
|
||||||
apiDeleteNodeTag,
|
apiDeleteNodeTag,
|
||||||
apiGetNode,
|
apiGetNode,
|
||||||
apiGetNodeComments,
|
apiGetNodeComments,
|
||||||
apiGetNodeRelated,
|
|
||||||
apiLockComment,
|
apiLockComment,
|
||||||
apiLockNode,
|
apiLockNode,
|
||||||
apiPostComment,
|
apiPostComment,
|
||||||
|
@ -111,7 +109,6 @@ function* onNodeGoto({ id, node_type }: ReturnType<typeof nodeGotoNode>) {
|
||||||
if (node_type) yield put(nodeSetCurrent({ ...EMPTY_NODE, type: node_type }));
|
if (node_type) yield put(nodeSetCurrent({ ...EMPTY_NODE, type: node_type }));
|
||||||
|
|
||||||
yield put(nodeLoadNode(id));
|
yield put(nodeLoadNode(id));
|
||||||
yield put(nodeSetRelated({ albums: {}, similar: [] }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function* onNodeLoadMoreComments() {
|
function* onNodeLoadMoreComments() {
|
||||||
|
@ -146,13 +143,6 @@ function* onNodeLoadMoreComments() {
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
function* nodeGetRelated(id: INode['id']) {
|
|
||||||
try {
|
|
||||||
const { related }: Unwrap<typeof apiGetNodeRelated> = yield call(apiGetNodeRelated, { id });
|
|
||||||
yield put(nodeSet({ related }));
|
|
||||||
} catch {}
|
|
||||||
}
|
|
||||||
|
|
||||||
function* nodeGetComments(id: INode['id']) {
|
function* nodeGetComments(id: INode['id']) {
|
||||||
try {
|
try {
|
||||||
const { comments, comment_count }: Unwrap<typeof apiGetNodeComments> = yield call(
|
const { comments, comment_count }: Unwrap<typeof apiGetNodeComments> = yield call(
|
||||||
|
@ -188,9 +178,9 @@ function* onNodeLoad({ id }: ReturnType<typeof nodeLoadNode>) {
|
||||||
yield put(nodeSetLoading(false));
|
yield put(nodeSetLoading(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comments and related
|
// Comments
|
||||||
try {
|
try {
|
||||||
yield all([call(nodeGetComments, id), call(nodeGetRelated, id)]);
|
yield call(nodeGetComments, id);
|
||||||
|
|
||||||
yield put(
|
yield put(
|
||||||
nodeSet({
|
nodeSet({
|
||||||
|
@ -235,7 +225,6 @@ function* onUpdateTags({ id, tags }: ReturnType<typeof nodeUpdateTags>) {
|
||||||
const { current }: ReturnType<typeof selectNode> = yield select(selectNode);
|
const { current }: ReturnType<typeof selectNode> = yield select(selectNode);
|
||||||
if (!node || !node.id || node.id !== current.id) return;
|
if (!node || !node.id || node.id !== current.id) return;
|
||||||
yield put(nodeSetTags(node.tags));
|
yield put(nodeSetTags(node.tags));
|
||||||
yield call(nodeGetRelated, id);
|
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,7 +232,6 @@ function* onDeleteTag({ id, tagId }: ReturnType<typeof nodeDeleteTag>) {
|
||||||
try {
|
try {
|
||||||
const { tags }: Unwrap<typeof apiDeleteNodeTag> = yield call(apiDeleteNodeTag, { id, tagId });
|
const { tags }: Unwrap<typeof apiDeleteNodeTag> = yield call(apiDeleteNodeTag, { id, tagId });
|
||||||
yield put(nodeSetTags(tags));
|
yield put(nodeSetTags(tags));
|
||||||
yield call(nodeGetRelated, id);
|
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { IComment, INode, ITag } from '~/redux/types';
|
import { IComment, INode, ITag } from '~/redux/types';
|
||||||
import { INodeState } from '~/redux/node/reducer';
|
|
||||||
|
|
||||||
export interface IEditorComponentProps {}
|
export interface IEditorComponentProps {}
|
||||||
|
|
||||||
|
@ -37,7 +36,7 @@ export type ApiGetNodeRelatedRequest = {
|
||||||
id: INode['id'];
|
id: INode['id'];
|
||||||
};
|
};
|
||||||
export type ApiGetNodeRelatedResult = {
|
export type ApiGetNodeRelatedResult = {
|
||||||
related: INodeState['related'];
|
related: INodeRelated;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ApiPostCommentRequest = {
|
export type ApiPostCommentRequest = {
|
||||||
|
|
|
@ -10,12 +10,11 @@ export const useFullNode = (id: string) => {
|
||||||
comments,
|
comments,
|
||||||
comment_count: commentsCount,
|
comment_count: commentsCount,
|
||||||
is_loading_comments: isLoadingComments,
|
is_loading_comments: isLoadingComments,
|
||||||
related,
|
|
||||||
lastSeenCurrent,
|
lastSeenCurrent,
|
||||||
} = useShallowSelect(selectNode);
|
} = useShallowSelect(selectNode);
|
||||||
|
|
||||||
useLoadNode(id);
|
useLoadNode(id);
|
||||||
useOnNodeSeen(node);
|
useOnNodeSeen(node);
|
||||||
|
|
||||||
return { node, comments, commentsCount, related, lastSeenCurrent, isLoading, isLoadingComments };
|
return { node, comments, commentsCount, lastSeenCurrent, isLoading, isLoadingComments };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue