Files
speckle-server/packages/frontend-2/lib/viewer/helpers/comments.ts
T
Kristaps Fabians Geikins 9427686d42 fix(fe2): various follow mode & thread viewer state sync fixes & improvements (#1595)
* fix(fe2): unfollow on camera move

* WIP new state hydration function

* WIP sync state

* minor cleanup

* fix coloring not being tracked

* fix for post thread close camera pos restore

* supporting duplicate users

* preventing guest commenting + state reset fixes

* fixed guests not receiving viewer comment updates

* post-thread creation opens new thread

* removing gap between 'X is typing' and bubble appearing

* reset filters will also reset colors now

* fixed thread full context

* camera reset fix

* thread reset fix

* fixed router concurrency issues

* followed user avatar fix

* TONS OF DEBUGGING FOR ROUTER QUEUING

* removing queued routing debugging stuff + disabling spotlight cancelation

* WIP async URL updates

* missing authLogger fixed

* fix for broken projection

* fix for bubbles positions not updating correctly

* queued routing cleanup

* fixed spotlight mode disabling unnecessarily

* added back stoplight stop on ctrl

* undid spotlight debugging
2023-05-29 15:20:32 +03:00

64 lines
1.9 KiB
TypeScript

import { RichTextEditor, SpeckleViewer } from '@speckle/shared'
import { sortBy } from 'lodash-es'
import { graphql } from '~~/lib/common/generated/gql'
import {
CommentContentInput,
LinkableCommentFragment
} from '~~/lib/common/generated/gql/graphql'
import { modelRoute } from '~~/lib/common/helpers/route'
import { CommentEditorValue } from '~~/lib/viewer/composables/commentManagement'
import { ViewerHashStateKeys } from '~~/lib/viewer/composables/setup/urlHashState'
export function convertCommentEditorValueToInput(
value: CommentEditorValue
): CommentContentInput {
return {
doc: value.doc || null,
blobIds: value.attachments?.map((a) => a.result.blobId) || []
}
}
export function isValidCommentEditorValue(val: CommentEditorValue) {
const input = convertCommentEditorValueToInput(val)
return isValidCommentContentInput(input)
}
export function isValidCommentContentInput(input: CommentContentInput) {
if (!input.doc && !(input.blobIds || []).length) return false
if (input.doc && RichTextEditor.isDocEmpty(input.doc)) return false
return true
}
graphql(`
fragment LinkableComment on Comment {
id
viewerResources {
modelId
versionId
objectId
}
}
`)
export function getLinkToThread(projectId: string, thread: LinkableCommentFragment) {
if (!thread.viewerResources.length) return undefined
const sortedResources = sortBy(thread.viewerResources, (r) => {
if (r.versionId) return 1
if (r.modelId) return 2
if (r.objectId) return 3
})
const resource = sortedResources[0]
const resourceUrlBuilder = SpeckleViewer.ViewerRoute.resourceBuilder()
if (resource.modelId) {
resourceUrlBuilder.addModel(resource.modelId, resource.versionId || undefined)
} else {
resourceUrlBuilder.addObject(resource.objectId)
}
return modelRoute(projectId, resourceUrlBuilder.toString(), {
[ViewerHashStateKeys.FocusedThreadId]: thread.id
})
}