From 18c30b805d79c41841b0622651ddf41b916d593e Mon Sep 17 00:00:00 2001 From: andrewwallacespeckle <139135120+andrewwallacespeckle@users.noreply.github.com> Date: Tue, 13 Feb 2024 13:19:10 +0000 Subject: [PATCH] [WBX-153] Persist Comment Visibility (#2032) * Add discussionLoadedVersionOnly cookie - defaulted to true * Updates from CR * Revert change * Updates * Remove unneeded watch * Updates --- .../components/viewer/comments/Comments.vue | 1 - .../lib/viewer/composables/setup.ts | 19 ++++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/frontend-2/components/viewer/comments/Comments.vue b/packages/frontend-2/components/viewer/comments/Comments.vue index 0c87a99046..8bcea9b5b3 100644 --- a/packages/frontend-2/components/viewer/comments/Comments.vue +++ b/packages/frontend-2/components/viewer/comments/Comments.vue @@ -129,7 +129,6 @@ const { const showVisibilityOptions = ref(false) -// eslint-disable-next-line @typescript-eslint/no-unused-vars const loadedVersionsOnly = computed({ get: () => threadFilters.value.loadedVersionsOnly || false ? 'loadedVersionsOnly' : undefined, diff --git a/packages/frontend-2/lib/viewer/composables/setup.ts b/packages/frontend-2/lib/viewer/composables/setup.ts index a6e3032e90..ea3c1034d9 100644 --- a/packages/frontend-2/lib/viewer/composables/setup.ts +++ b/packages/frontend-2/lib/viewer/composables/setup.ts @@ -65,6 +65,7 @@ import { InjectableViewerStateKey, useSetupViewerScope } from '~/lib/viewer/composables/setup/core' +import { useSynchronizedCookie } from '~~/lib/common/composables/reactiveCookie' export type LoadedModel = NonNullable< Get @@ -438,7 +439,14 @@ function setupResourceRequest(state: InitialSetupState): InitialStateWithRequest asyncRead: false }) - const threadFilters = ref({} as Omit) + const discussionLoadedVersionOnly = useSynchronizedCookie( + 'discussionLoadedVersionOnly', + { + default: () => true + } + ) + + const threadFilters = ref({ loadedVersionsOnly: discussionLoadedVersionOnly.value }) const switchModelToVersion = async (modelId: string, versionId?: string) => { const resourceArr = resources.value.slice() @@ -466,6 +474,15 @@ function setupResourceRequest(state: InitialSetupState): InitialStateWithRequest } } + watch( + () => threadFilters.value.loadedVersionsOnly, + (newVal, oldVal) => { + if (newVal !== oldVal && newVal !== discussionLoadedVersionOnly.value) { + discussionLoadedVersionOnly.value = newVal + } + } + ) + return { ...state, resources: {