Vitalik 9 months ago
parent
commit
f40585f220
  1. 5
      src/modules/root/hooks/use-app-badge.hook.ts
  2. 44
      src/modules/tasks/hooks/use-task-list-events.hook.ts
  3. 1
      src/services/system/real-time.service.ts
  4. 5
      src/shared/events/index.ts

5
src/modules/root/hooks/use-app-badge.hook.ts

@ -170,5 +170,10 @@ export const useAppBadge = () => { @@ -170,5 +170,10 @@ export const useAppBadge = () => {
permissions,
])
useSocketListener('task/hard-delete-task', decreaseTasksCountIfNeed, [
account,
permissions,
])
useSocketListener('user/change-permissions', onNeedReloadTasksCount, [])
}

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

@ -42,25 +42,38 @@ export const useTaskListEvents = (props: IProps) => { @@ -42,25 +42,38 @@ export const useTaskListEvents = (props: IProps) => {
_.some(props.items, item => _.includes(ids, item.id.toString()))
const onTaskDeleted = (data: { ids: (number | string)[] }) => {
const ids = data.ids.map(it => it.toString())
if (!checkListContainAnyItem(ids)) return
if (
props.taskFilterStatus === TaskStatus.Active ||
props.taskFilterStatus === TaskStatus.Finished
) {
const filteredItems = _.filter(
props.items,
item => !_.includes(ids, item.id.toString()),
)
props.setItems(filteredItems)
props.onAction('delete')
if (props.items.length === 1)
appEvents.emit('onLastTaskDeleted', {})
deleteTaskFromList(data)
}
}
const onTaskHardDeleted = (data: {
taskId: number
executorId: number
}) => {
deleteTaskFromList({ ids: [data.taskId] })
}
function deleteTaskFromList(data: { ids: (number | string)[] }) {
const ids = data.ids.map(it => it.toString())
if (!checkListContainAnyItem(ids)) return
const filteredItems = _.filter(
props.items,
item => !_.includes(ids, item.id.toString()),
)
props.setItems(filteredItems)
props.onAction('delete')
if (props.items.length === 1 || _.isEmpty(filteredItems))
appEvents.emit('onLastTaskDeleted', {})
}
// *********** APP EVENTS AND SOCKET SIGNALS HANDLERS *************
const onTaskChanged = (data: { ids: (number | string)[] }) => {
if (!checkListContainAnyItem(data.ids.map(it => it.toString()))) return
@ -316,7 +329,10 @@ export const useTaskListEvents = (props: IProps) => { @@ -316,7 +329,10 @@ export const useTaskListEvents = (props: IProps) => {
// ************************************************************
// ******** SOCKET SIGNALS LISTENERS **************************
useSocketListener('task/new-comment', onTaskNewComment, [props.items, account])
useSocketListener('task/new-comment', onTaskNewComment, [
props.items,
account,
])
useSocketListener('task/new-task', onNewTask, [props.items])
@ -326,6 +342,8 @@ export const useTaskListEvents = (props: IProps) => { @@ -326,6 +342,8 @@ export const useTaskListEvents = (props: IProps) => {
useSocketListener('task/delete-task', onDeleteTask, [props.items])
useSocketListener('task/hard-delete-task', onTaskHardDeleted, [props.items])
useSocketListener('task/read', onTaskRead, [props.items])
useSocketListener('task/read-docs', onTaskDocumentsRead, [props.items])

1
src/services/system/real-time.service.ts

@ -98,6 +98,7 @@ export class SocketIo { @@ -98,6 +98,7 @@ export class SocketIo {
this._onSocketSendEvent('task/update-task')
this._onSocketSendEvent('task/finish-task')
this._onSocketSendEvent('task/delete-task')
this._onSocketSendEvent('task/hard-delete-task')
this._onSocketSendEvent('task/read')
this._onSocketSendEvent('task/read-docs')
this._onSocketSendEvent('task/new-docs')

5
src/shared/events/index.ts

@ -169,6 +169,11 @@ export type SocketEvents = { @@ -169,6 +169,11 @@ export type SocketEvents = {
executorId: number
events: Record<string, TaskEvent[]>
}
'task/hard-delete-task': {
taskId: number
executorId: number
events: Record<string, TaskEvent[]>
}
'task/finish-task': {
taskId: number
executorId: number

Loading…
Cancel
Save