6d08889a79
* fix(server): viewerState sometimes reporting wrong isOrthoProjection value * feat: more resilient viewerState read/write * feat: more resilient viewerState read/write * fix(fe2): dashboard not showing empty state properly * fix(fe2): weird thread opening/closing behaviour * feat(cli): specifying token for commit download * fix(fe2): selection not being set for opened threads
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { writableAsyncComputed } from '~~/lib/common/composables/async'
|
|
import { useRouteHashState } from '~~/lib/common/composables/url'
|
|
import type { InjectableViewerState } from '~~/lib/viewer/composables/setup'
|
|
import { useDiffBuilderUtilities } from '~~/lib/viewer/composables/setup/diff'
|
|
|
|
export enum ViewerHashStateKeys {
|
|
FocusedThreadId = 'threadId',
|
|
Diff = 'diff'
|
|
}
|
|
|
|
export function setupUrlHashState(): InjectableViewerState['urlHashState'] {
|
|
const { hashState } = useRouteHashState()
|
|
const { deserializeDiffCommand, serializeDiffCommand } = useDiffBuilderUtilities()
|
|
|
|
const focusedThreadId = writableAsyncComputed({
|
|
get: () => hashState.value[ViewerHashStateKeys.FocusedThreadId] || null,
|
|
set: async (newVal) => {
|
|
await hashState.update({
|
|
...hashState.value,
|
|
[ViewerHashStateKeys.FocusedThreadId]: newVal
|
|
})
|
|
},
|
|
initialState: null,
|
|
asyncRead: false
|
|
// debugging: { log: { name: 'focusedThreadId' } }
|
|
})
|
|
|
|
const diff = writableAsyncComputed({
|
|
get: () => {
|
|
const urlValue = hashState.value[ViewerHashStateKeys.Diff]
|
|
return deserializeDiffCommand(urlValue)
|
|
},
|
|
set: async (newVal) =>
|
|
await hashState.update({
|
|
...hashState.value,
|
|
[ViewerHashStateKeys.Diff]: newVal ? serializeDiffCommand(newVal) : null
|
|
}),
|
|
initialState: null,
|
|
asyncRead: false
|
|
})
|
|
|
|
return {
|
|
focusedThreadId,
|
|
diff
|
|
}
|
|
}
|