a6287fc06d
* init db migration * WIP store view * create service call * WIP insertion * insert sort of works * moving code arounmd * creation tests * avoid duplicate entries * fixes from main * basic group retrieval works * group filtering works * WIP view listing * filter by acl * fixes + WIP single group retrieval * wip pivot * more pivot query fixes * tests fixed after pivot * views list tests * fixing test command * business plan only checks * more tests for coverage * .dts import fix * cli fix * anutha one * auth policy tests for business plan access * WIP saved views panel base * BE listing adjustments * WIP group rendering * group render done * WIP post create cache updates * listing fine? * my vs theirs * auto open * minor fixes * click load omg * nicely loading views * type fix * less spammy loading * another type fix: * more lint fix * test fix * codecov disable * moar coverage * fix sidebar flashin * more test coverage * more test cvoverage * minor adfjustments * adj * saved view wipe fixes * CSR viewer * more improvements * extra feature flag checks * lint fix * feature flags fix * more test fixes
62 lines
1.8 KiB
TypeScript
62 lines
1.8 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',
|
|
EmbedOptions = 'embed',
|
|
SavedViewId = 'savedViewId'
|
|
}
|
|
|
|
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
|
|
})
|
|
|
|
const savedViewId = writableAsyncComputed({
|
|
get: () => hashState.value[ViewerHashStateKeys.SavedViewId] || null,
|
|
set: async (newVal) => {
|
|
await hashState.update({
|
|
...hashState.value,
|
|
[ViewerHashStateKeys.SavedViewId]: newVal
|
|
})
|
|
},
|
|
initialState: null,
|
|
asyncRead: false
|
|
})
|
|
|
|
return {
|
|
focusedThreadId,
|
|
diff,
|
|
savedViewId
|
|
}
|
|
}
|