mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
node deletion (lock)
This commit is contained in:
parent
b1279e8d4d
commit
8f0625f734
12 changed files with 113 additions and 58 deletions
|
@ -96,6 +96,12 @@ export const nodeStar = (id: INode['id']) => ({
|
|||
id,
|
||||
});
|
||||
|
||||
export const nodeLock = (id: INode['id'], is_locked: boolean) => ({
|
||||
type: NODE_ACTIONS.LOCK,
|
||||
id,
|
||||
is_locked,
|
||||
});
|
||||
|
||||
export const nodeSetEditor = (editor: INode) => ({
|
||||
type: NODE_ACTIONS.SET_EDITOR,
|
||||
editor,
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
import {
|
||||
api,
|
||||
configWithToken,
|
||||
resultMiddleware,
|
||||
errorMiddleware
|
||||
} from "~/utils/api";
|
||||
import { INode, IResultWithStatus, IComment } from "../types";
|
||||
import { API } from "~/constants/api";
|
||||
import { nodeUpdateTags, nodeLike, nodeStar } from "./actions";
|
||||
import { INodeState } from "./reducer";
|
||||
import { api, configWithToken, resultMiddleware, errorMiddleware } from '~/utils/api';
|
||||
import { INode, IResultWithStatus, IComment } from '../types';
|
||||
import { API } from '~/constants/api';
|
||||
import { nodeUpdateTags, nodeLike, nodeStar, nodeLock } from './actions';
|
||||
import { INodeState } from './reducer';
|
||||
|
||||
export const postNode = ({
|
||||
access,
|
||||
node
|
||||
node,
|
||||
}: {
|
||||
access: string;
|
||||
node: INode;
|
||||
|
@ -24,7 +19,7 @@ export const postNode = ({
|
|||
|
||||
export const getNodes = ({
|
||||
from = null,
|
||||
access
|
||||
access,
|
||||
}: {
|
||||
from?: string;
|
||||
access: string;
|
||||
|
@ -42,7 +37,7 @@ export const getNodeDiff = ({
|
|||
with_updated,
|
||||
with_recent,
|
||||
with_valid,
|
||||
access
|
||||
access,
|
||||
}: {
|
||||
start?: string;
|
||||
end?: string;
|
||||
|
@ -64,8 +59,8 @@ export const getNodeDiff = ({
|
|||
with_heroes,
|
||||
with_updated,
|
||||
with_recent,
|
||||
with_valid
|
||||
}
|
||||
with_valid,
|
||||
},
|
||||
})
|
||||
)
|
||||
.then(resultMiddleware)
|
||||
|
@ -73,7 +68,7 @@ export const getNodeDiff = ({
|
|||
|
||||
export const getNode = ({
|
||||
id,
|
||||
access
|
||||
access,
|
||||
}: {
|
||||
id: string | number;
|
||||
access: string;
|
||||
|
@ -86,7 +81,7 @@ export const getNode = ({
|
|||
export const postNodeComment = ({
|
||||
id,
|
||||
data,
|
||||
access
|
||||
access,
|
||||
}: {
|
||||
access: string;
|
||||
id: number;
|
||||
|
@ -100,11 +95,11 @@ export const postNodeComment = ({
|
|||
export const getNodeComments = ({
|
||||
id,
|
||||
access,
|
||||
order = "ASC"
|
||||
order = 'ASC',
|
||||
}: {
|
||||
id: number;
|
||||
access: string;
|
||||
order: "ASC" | "DESC";
|
||||
order: 'ASC' | 'DESC';
|
||||
}): Promise<IResultWithStatus<{ comments: Comment[] }>> =>
|
||||
api
|
||||
.get(API.NODE.COMMENT(id), configWithToken(access, { params: { order } }))
|
||||
|
@ -113,11 +108,11 @@ export const getNodeComments = ({
|
|||
|
||||
export const getNodeRelated = ({
|
||||
id,
|
||||
access
|
||||
access,
|
||||
}: {
|
||||
id: number;
|
||||
access: string;
|
||||
}): Promise<IResultWithStatus<{ related: INodeState["related"] }>> =>
|
||||
}): Promise<IResultWithStatus<{ related: INodeState['related'] }>> =>
|
||||
api
|
||||
.get(API.NODE.RELATED(id), configWithToken(access))
|
||||
.then(resultMiddleware)
|
||||
|
@ -126,7 +121,7 @@ export const getNodeRelated = ({
|
|||
export const updateNodeTags = ({
|
||||
id,
|
||||
tags,
|
||||
access
|
||||
access,
|
||||
}: ReturnType<typeof nodeUpdateTags> & { access: string }): Promise<
|
||||
IResultWithStatus<{ node: INode }>
|
||||
> =>
|
||||
|
@ -137,9 +132,9 @@ export const updateNodeTags = ({
|
|||
|
||||
export const postNodeLike = ({
|
||||
id,
|
||||
access
|
||||
access,
|
||||
}: ReturnType<typeof nodeLike> & { access: string }): Promise<
|
||||
IResultWithStatus<{ is_liked: INode["is_liked"] }>
|
||||
IResultWithStatus<{ is_liked: INode['is_liked'] }>
|
||||
> =>
|
||||
api
|
||||
.post(API.NODE.POST_LIKE(id), {}, configWithToken(access))
|
||||
|
@ -148,11 +143,23 @@ export const postNodeLike = ({
|
|||
|
||||
export const postNodeStar = ({
|
||||
id,
|
||||
access
|
||||
access,
|
||||
}: ReturnType<typeof nodeStar> & { access: string }): Promise<
|
||||
IResultWithStatus<{ is_liked: INode["is_liked"] }>
|
||||
IResultWithStatus<{ is_liked: INode['is_liked'] }>
|
||||
> =>
|
||||
api
|
||||
.post(API.NODE.POST_STAR(id), {}, configWithToken(access))
|
||||
.then(resultMiddleware)
|
||||
.catch(errorMiddleware);
|
||||
|
||||
export const postNodeLock = ({
|
||||
id,
|
||||
is_locked,
|
||||
access,
|
||||
}: ReturnType<typeof nodeLock> & { access: string }): Promise<
|
||||
IResultWithStatus<{ deleted_at: INode['deleted_at'] }>
|
||||
> =>
|
||||
api
|
||||
.post(API.NODE.POST_LOCK(id), { is_locked }, configWithToken(access))
|
||||
.then(resultMiddleware)
|
||||
.catch(errorMiddleware);
|
||||
|
|
|
@ -23,6 +23,7 @@ export const NODE_ACTIONS = {
|
|||
EDIT: `${prefix}EDIT`,
|
||||
LIKE: `${prefix}LIKE`,
|
||||
STAR: `${prefix}STAR`,
|
||||
LOCK: `${prefix}LOCK`,
|
||||
CREATE: `${prefix}CREATE`,
|
||||
|
||||
SET_SAVE_ERRORS: `${prefix}SET_SAVE_ERRORS`,
|
||||
|
|
|
@ -21,6 +21,7 @@ import {
|
|||
nodeLike,
|
||||
nodeSetRelated,
|
||||
nodeGotoNode,
|
||||
nodeLock,
|
||||
} from './actions';
|
||||
import {
|
||||
postNode,
|
||||
|
@ -31,6 +32,7 @@ import {
|
|||
postNodeLike,
|
||||
postNodeStar,
|
||||
getNodeRelated,
|
||||
postNodeLock,
|
||||
} from './api';
|
||||
import { reqWrapper } from '../auth/sagas';
|
||||
import { flowSetNodes, flowSetUpdated } from '../flow/actions';
|
||||
|
@ -234,6 +236,23 @@ function* onStarSaga({ id }: ReturnType<typeof nodeLike>) {
|
|||
yield call(updateNodeEverywhere, { ...current, is_heroic });
|
||||
}
|
||||
|
||||
function* onLockSaga({ id, is_locked }: ReturnType<typeof nodeLock>) {
|
||||
const {
|
||||
current,
|
||||
current: { deleted_at },
|
||||
} = yield select(selectNode);
|
||||
|
||||
yield call(updateNodeEverywhere, {
|
||||
...current,
|
||||
deleted_at: is_locked ? new Date().toISOString() : null,
|
||||
});
|
||||
|
||||
const { data, error } = yield call(reqWrapper, postNodeLock, { id, is_locked });
|
||||
|
||||
if (error || !data.deleted_at)
|
||||
return yield call(updateNodeEverywhere, { ...current, deleted_at }); // ok and matches
|
||||
}
|
||||
|
||||
export default function* nodeSaga() {
|
||||
yield takeLatest(NODE_ACTIONS.SAVE, onNodeSave);
|
||||
yield takeLatest(NODE_ACTIONS.GOTO_NODE, onNodeGoto);
|
||||
|
@ -244,4 +263,5 @@ export default function* nodeSaga() {
|
|||
yield takeLatest(NODE_ACTIONS.EDIT, onEditSaga);
|
||||
yield takeLatest(NODE_ACTIONS.LIKE, onLikeSaga);
|
||||
yield takeLatest(NODE_ACTIONS.STAR, onStarSaga);
|
||||
yield takeLatest(NODE_ACTIONS.LOCK, onLockSaga);
|
||||
}
|
||||
|
|
|
@ -132,6 +132,7 @@ export interface INode {
|
|||
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
deleted_at?: string;
|
||||
commented_at?: string;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue