feat(tasks): fetch comments with the task
This commit is contained in:
parent
6b7c3ffef3
commit
cd304b9e4e
|
|
@ -231,6 +231,7 @@ import { useCopyToClipboard } from '@/composables/useCopyToClipboard'
|
|||
const props = withDefaults(defineProps<{
|
||||
taskId: number,
|
||||
canWrite?: boolean
|
||||
initialComments?: ITaskComment[]
|
||||
}>(), {
|
||||
canWrite: true,
|
||||
})
|
||||
|
|
@ -302,6 +303,12 @@ async function loadComments(taskId: ITask['id']) {
|
|||
|
||||
commentEdit.taskId = taskId
|
||||
commentToDelete.taskId = taskId
|
||||
|
||||
if(typeof props.initialComments !== 'undefined' && currentPage.value === 1) {
|
||||
comments.value = props.initialComments
|
||||
return
|
||||
}
|
||||
|
||||
comments.value = await taskCommentService.getAll({taskId}, {}, currentPage.value)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import type {IRepeatMode} from '@/types/IRepeatMode'
|
|||
import type {PartialWithId} from '@/types/PartialWithId'
|
||||
import type {ITaskReminder} from '@/modelTypes/ITaskReminder'
|
||||
import type {IReactionPerEntity} from '@/modelTypes/IReaction'
|
||||
import type {ITaskComment} from '@/modelTypes/ITaskComment.ts'
|
||||
|
||||
export interface ITask extends IAbstract {
|
||||
id: number
|
||||
|
|
@ -47,6 +48,7 @@ export interface ITask extends IAbstract {
|
|||
position: number
|
||||
|
||||
reactions: IReactionPerEntity
|
||||
comments: ITaskComment[]
|
||||
|
||||
createdBy: IUser
|
||||
created: Date
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import type {IRelationKind} from '@/types/IRelationKind'
|
|||
import {TASK_REPEAT_MODES, type IRepeatMode} from '@/types/IRepeatMode'
|
||||
|
||||
import {parseDateOrNull} from '@/helpers/parseDateOrNull'
|
||||
import {secondsToPeriod} from '@/helpers/time/period'
|
||||
|
||||
import AbstractModel from './abstractModel'
|
||||
import LabelModel from './label'
|
||||
|
|
@ -21,7 +22,7 @@ import AttachmentModel from './attachment'
|
|||
import SubscriptionModel from './subscription'
|
||||
import type {ITaskReminder} from '@/modelTypes/ITaskReminder'
|
||||
import TaskReminderModel from '@/models/taskReminder'
|
||||
import {secondsToPeriod} from '@/helpers/time/period'
|
||||
import TaskCommentModel from '@/models/taskComment.ts'
|
||||
|
||||
export function getHexColor(hexColor: string): string | undefined {
|
||||
if (hexColor === '' || hexColor === '#') {
|
||||
|
|
@ -87,6 +88,7 @@ export default class TaskModel extends AbstractModel<ITask> implements ITask {
|
|||
position = 0
|
||||
|
||||
reactions = {}
|
||||
comments = []
|
||||
|
||||
createdBy: IUser = UserModel
|
||||
created: Date = null
|
||||
|
|
@ -149,6 +151,8 @@ export default class TaskModel extends AbstractModel<ITask> implements ITask {
|
|||
this.updated = new Date(this.updated)
|
||||
|
||||
this.projectId = Number(this.projectId)
|
||||
|
||||
this.comments = this.comments.map(c => new TaskCommentModel(c))
|
||||
|
||||
// We can't convert emojis to camel case, hence we do this manually
|
||||
this.reactions = {}
|
||||
|
|
|
|||
|
|
@ -394,6 +394,7 @@
|
|||
<Comments
|
||||
:can-write="canWrite"
|
||||
:task-id="taskId"
|
||||
:initial-comments="task.comments"
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
|
@ -735,7 +736,7 @@ watch(
|
|||
}
|
||||
|
||||
try {
|
||||
const loaded = await taskService.get({id}, {expand: 'reactions'})
|
||||
const loaded = await taskService.get({id}, {expand: ['reactions', 'comments']})
|
||||
Object.assign(task.value, loaded)
|
||||
attachmentStore.set(task.value.attachments)
|
||||
taskColor.value = task.value.hexColor
|
||||
|
|
|
|||
Loading…
Reference in New Issue