2023-01-14 10:54:54 +00:00
|
|
|
import { SortingOrder } from '@hcengineering/core'
|
2022-09-21 08:08:25 +00:00
|
|
|
import { getCurrentLocation, locationToUrl } from '@hcengineering/ui'
|
2023-01-14 10:54:54 +00:00
|
|
|
import { DropdownViewOption, ToggleViewOption, ViewOptionModel, ViewOptions } from '@hcengineering/view'
|
2022-07-10 15:29:59 +00:00
|
|
|
import { writable } from 'svelte/store'
|
|
|
|
|
2023-01-14 10:54:54 +00:00
|
|
|
export const noCategory = '#no_category'
|
2022-07-10 15:29:59 +00:00
|
|
|
|
2023-01-14 10:54:54 +00:00
|
|
|
export const defaulOptions: ViewOptions = {
|
|
|
|
groupBy: noCategory,
|
|
|
|
orderBy: ['modifiedBy', SortingOrder.Descending]
|
|
|
|
}
|
|
|
|
|
|
|
|
export const viewOptionsStore = writable<ViewOptions>(defaulOptions)
|
2022-07-10 15:29:59 +00:00
|
|
|
|
|
|
|
export function isToggleType (viewOption: ViewOptionModel): viewOption is ToggleViewOption {
|
|
|
|
return viewOption.type === 'toggle'
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isDropdownType (viewOption: ViewOptionModel): viewOption is DropdownViewOption {
|
|
|
|
return viewOption.type === 'dropdown'
|
|
|
|
}
|
|
|
|
|
|
|
|
function makeViewOptionsKey (prefix: string): string {
|
|
|
|
const loc = getCurrentLocation()
|
|
|
|
loc.fragment = undefined
|
|
|
|
loc.query = undefined
|
|
|
|
return `viewOptions:${prefix}:${locationToUrl(loc)}`
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setViewOptions (prefix: string, options: ViewOptions): void {
|
|
|
|
const key = makeViewOptionsKey(prefix)
|
|
|
|
localStorage.setItem(key, JSON.stringify(options))
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getViewOptions (prefix: string): ViewOptions | null {
|
|
|
|
const key = makeViewOptionsKey(prefix)
|
|
|
|
const options = localStorage.getItem(key)
|
|
|
|
if (options === null) return null
|
|
|
|
return JSON.parse(options)
|
|
|
|
}
|