1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-26 05:16:41 +07:00

fixed pushing tags

This commit is contained in:
Fedor Katurov 2019-10-24 12:43:54 +07:00
parent 6836e00de1
commit 99426172b2
12 changed files with 79 additions and 22 deletions

View file

@ -48,6 +48,11 @@ export const nodeSetComments = (comments: IComment[]) => ({
type: NODE_ACTIONS.SET_COMMENTS,
});
export const nodeSetRelated = (related: INodeState['related']) => ({
related,
type: NODE_ACTIONS.SET_RELATED,
});
export const nodeSetCommentData = (id: number, comment: IComment) => ({
id,
comment,

View file

@ -2,6 +2,7 @@ import { api, configWithToken, resultMiddleware, errorMiddleware } from '~/utils
import { INode, IResultWithStatus, IComment } from '../types';
import { API } from '~/constants/api';
import { nodeUpdateTags, nodeLike, nodeStar } from './actions';
import { INodeState } from './reducer';
export const postNode = ({
access,
@ -58,12 +59,24 @@ export const getNodeComments = ({
}: {
id: number;
access: string;
}): Promise<IResultWithStatus<{ comment: Comment }>> =>
}): Promise<IResultWithStatus<{ comments: Comment[] }>> =>
api
.get(API.NODE.COMMENT(id), configWithToken(access))
.then(resultMiddleware)
.catch(errorMiddleware);
export const getNodeRelated = ({
id,
access,
}: {
id: number;
access: string;
}): Promise<IResultWithStatus<{ related: INodeState['related'] }>> =>
api
.get(API.NODE.RELATED(id), configWithToken(access))
.then(resultMiddleware)
.catch(errorMiddleware);
export const updateNodeTags = ({
id,
tags,

View file

@ -34,6 +34,7 @@ export const NODE_ACTIONS = {
POST_COMMENT: `${prefix}POST_COMMENT`,
SET_COMMENTS: `${prefix}SET_COMMENTS`,
SET_RELATED: `${prefix}SET_RELATED`,
UPDATE_TAGS: `${prefix}UPDATE_TAGS`,
SET_TAGS: `${prefix}SET_TAGS`,

View file

@ -11,6 +11,7 @@ import {
nodeSetTags,
nodeSetEditor,
nodeSetCoverImage,
nodeSetRelated,
} from './actions';
import { INodeState } from './reducer';
@ -36,6 +37,9 @@ const setSendingComment = (
const setComments = (state: INodeState, { comments }: ReturnType<typeof nodeSetComments>) =>
assocPath(['comments'], comments, state);
const setRelated = (state: INodeState, { related }: ReturnType<typeof nodeSetRelated>) =>
assocPath(['related'], related, state);
const setCommentData = (
state: INodeState,
{ id, comment }: ReturnType<typeof nodeSetCommentData>
@ -59,6 +63,7 @@ export const NODE_HANDLERS = {
[NODE_ACTIONS.SET_CURRENT]: setCurrent,
[NODE_ACTIONS.SET_SENDING_COMMENT]: setSendingComment,
[NODE_ACTIONS.SET_COMMENTS]: setComments,
[NODE_ACTIONS.SET_RELATED]: setRelated,
[NODE_ACTIONS.SET_COMMENT_DATA]: setCommentData,
[NODE_ACTIONS.SET_TAGS]: setTags,
[NODE_ACTIONS.SET_EDITOR]: setEditor,

View file

@ -7,6 +7,10 @@ export type INodeState = Readonly<{
editor: INode;
current: INode;
comments: IComment[];
related: {
albums: Record<string, Partial<INode[]>>;
similar: Partial<INode[]>;
};
comment_data: Record<number, IComment>;
current_cover_image: IFile;
@ -28,6 +32,7 @@ const INITIAL_STATE: INodeState = {
current: { ...EMPTY_NODE },
comment_data: { 0: { ...EMPTY_COMMENT } },
comments: [],
related: null,
current_cover_image: null,
is_loading: false,

View file

@ -1,4 +1,4 @@
import { takeLatest, call, put, select, delay } from 'redux-saga/effects';
import { takeLatest, call, put, select, delay, all } from 'redux-saga/effects';
import { push } from 'connected-react-router';
import { NODE_ACTIONS, EMPTY_NODE, EMPTY_COMMENT, NODE_EDITOR_DATA } from './constants';
@ -19,6 +19,7 @@ import {
nodeSetEditor,
nodeEdit,
nodeLike,
nodeSetRelated,
} from './actions';
import {
postNode,
@ -28,6 +29,7 @@ import {
updateNodeTags,
postNodeLike,
postNodeStar,
getNodeRelated,
} from './api';
import { reqWrapper } from '../auth/sagas';
import { flowSetNodes } from '../flow/actions';
@ -112,11 +114,19 @@ function* onNodeLoad({ id, node_type }: ReturnType<typeof nodeLoadNode>) {
// todo: load comments
const {
data: { comments },
} = yield call(reqWrapper, getNodeComments, { id });
comments: {
data: { comments },
},
related: {
data: { related },
},
} = yield all({
comments: call(reqWrapper, getNodeComments, { id }),
related: call(reqWrapper, getNodeRelated, { id }),
});
yield put(nodeSetComments(comments || []));
yield put(nodeSetRelated(related || []));
yield put(nodeSetLoadingComments(false));
return;