45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
|
|
import { CommentThread } from "entities/Comments/CommentsInterfaces";
|
||
|
|
|
||
|
|
// used for dev
|
||
|
|
export const reduceCommentsByRef = (comments: any[]) => {
|
||
|
|
return comments.reduce((res, curr) => {
|
||
|
|
return {
|
||
|
|
commentThreadsMap: {
|
||
|
|
...res.commentThreadsMap,
|
||
|
|
[curr.id]: curr,
|
||
|
|
},
|
||
|
|
refCommentThreads: {
|
||
|
|
...(res.refCommentThreads ? res.refCommentThreads : {}),
|
||
|
|
[curr.refId]: [
|
||
|
|
...(res.refCommentThreads && res.refCommentThreads[curr.refId]
|
||
|
|
? res.refCommentThreads[curr.refId]
|
||
|
|
: []),
|
||
|
|
curr.id,
|
||
|
|
],
|
||
|
|
},
|
||
|
|
};
|
||
|
|
}, {});
|
||
|
|
};
|
||
|
|
|
||
|
|
export const transformPublishedCommentActionPayload = (
|
||
|
|
payload: any,
|
||
|
|
): Record<string, CommentThread> => {
|
||
|
|
return {
|
||
|
|
[payload.refId]: {
|
||
|
|
...payload,
|
||
|
|
position: payload.position,
|
||
|
|
id: "UNPUBLISHED",
|
||
|
|
},
|
||
|
|
};
|
||
|
|
};
|
||
|
|
|
||
|
|
export const transformUnpublishCommentThreadToCreateNew = (payload: any) => {
|
||
|
|
const { commentBody, commentThread } = payload;
|
||
|
|
// eslint-disable-next-line
|
||
|
|
const { id, ...rest } = commentThread;
|
||
|
|
return {
|
||
|
|
...rest,
|
||
|
|
comments: [{ body: commentBody }],
|
||
|
|
};
|
||
|
|
};
|