Browse Source

Merge branch 'synchronize-comments' into 'master'

CHORE | Synchronize comments in app and web for the same account

See merge request jetup/rws/rws-appication!349
merge-requests/350/head
Coder 2 years ago
parent
commit
b4ac1c579a
  1. 3
      src/modules/comments/hooks/use-task-comments.hook.ts
  2. 15
      src/modules/tasks/hooks/use-task-list-events.hook.ts
  3. 2
      src/shared/events/index.ts

3
src/modules/comments/hooks/use-task-comments.hook.ts

@ -136,6 +136,7 @@ export const useTaskComments = (taskId: number | string) => { @@ -136,6 +136,7 @@ export const useTaskComments = (taskId: number | string) => {
const onNewComment = (data: SocketEvents['task/new-comment']) => {
if (data.taskId.toString() !== taskId.toString()) return
if (_.find(comments, it => it.id === data.commentId)) return
loadComments()
}
@ -177,7 +178,7 @@ export const useTaskComments = (taskId: number | string) => { @@ -177,7 +178,7 @@ export const useTaskComments = (taskId: number | string) => {
setComments(newComments)
}
useSocketListener('task/new-comment', onNewComment, [taskId])
useSocketListener('task/new-comment', onNewComment, [taskId, comments])
useSocketListener('task/update-comment', onCommentUpdated, [
comments,

15
src/modules/tasks/hooks/use-task-list-events.hook.ts

@ -95,8 +95,6 @@ export const useTaskListEvents = (props: IProps) => { @@ -95,8 +95,6 @@ export const useTaskListEvents = (props: IProps) => {
taskId: number | string
userId?: number
}) => {
if (data.userId && data.userId !== account.id) return
const index = _.findIndex(
props.items,
item => item.id.toString() === data.taskId.toString(),
@ -112,6 +110,11 @@ export const useTaskListEvents = (props: IProps) => { @@ -112,6 +110,11 @@ export const useTaskListEvents = (props: IProps) => {
props.setItems(changedItems)
}
const onCommentsAreRead = (data: SocketEvents['task/read-comments']) => {
if (!data.userId || (data.userId && data.userId !== account.id)) return
onTaskCommentsRead(data)
}
const onTaskDocumentsRead = (data: { taskId: number | string }) => {
const index = _.findIndex(
props.items,
@ -129,7 +132,9 @@ export const useTaskListEvents = (props: IProps) => { @@ -129,7 +132,9 @@ export const useTaskListEvents = (props: IProps) => {
props.setItems(changedItems)
}
const onTaskNewComment = (data: { taskId: number }) => {
const onTaskNewComment = (data: SocketEvents['task/new-comment']) => {
if (data.userId === account.id) return
const index = _.findIndex(
props.items,
item => item.id.toString() === data.taskId.toString(),
@ -311,7 +316,7 @@ export const useTaskListEvents = (props: IProps) => { @@ -311,7 +316,7 @@ export const useTaskListEvents = (props: IProps) => {
// ************************************************************
// ******** SOCKET SIGNALS LISTENERS **************************
useSocketListener('task/new-comment', onTaskNewComment, [props.items])
useSocketListener('task/new-comment', onTaskNewComment, [props.items, account])
useSocketListener('task/new-task', onNewTask, [props.items])
@ -325,7 +330,7 @@ export const useTaskListEvents = (props: IProps) => { @@ -325,7 +330,7 @@ export const useTaskListEvents = (props: IProps) => {
useSocketListener('task/read-docs', onTaskDocumentsRead, [props.items])
useSocketListener('task/read-comments', onTaskCommentsRead, [props.items])
useSocketListener('task/read-comments', onCommentsAreRead, [props.items])
useSocketListener('task/new-docs', onTaskNewDocument, [props.items])

2
src/shared/events/index.ts

@ -152,7 +152,7 @@ export type SocketEvents = { @@ -152,7 +152,7 @@ export type SocketEvents = {
'chat/unpin': { chatId: number }
'chat/unread': { chatId: number }
'task/new-comment': { taskId: number }
'task/new-comment': { taskId: number, commentId: number, userId: number }
'task/update-comment': { comment: IComment }
'task/read-comments': { taskId: number; userId?: number }
'task/delete-comment': {

Loading…
Cancel
Save