mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-13 19:58:09 +00:00
Save last location state of inbox (#5656)
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
parent
f1791c9e21
commit
8b0d099b1a
@ -14,8 +14,10 @@
|
||||
//
|
||||
|
||||
import { Analytics } from '@hcengineering/analytics'
|
||||
import { clone } from '@hcengineering/core'
|
||||
import { clone, type Ref, type Space } from '@hcengineering/core'
|
||||
import { derived, get, writable } from 'svelte/store'
|
||||
import { type Plugin } from '@hcengineering/platform'
|
||||
|
||||
import { closePopup } from './popups'
|
||||
import { type Location as PlatformLocation } from './types'
|
||||
|
||||
@ -207,3 +209,23 @@ export const setTreeCollapsed = (_id: any, collapsed: boolean): void => {
|
||||
const key = getCollapsedKey(_id)
|
||||
collapsed ? localStorage.setItem(key, COLLAPSED) : localStorage.removeItem(key)
|
||||
}
|
||||
|
||||
export function restoreLocation (loc: PlatformLocation, app: Plugin): void {
|
||||
const last = localStorage.getItem(`${locationStorageKeyId}_${app}`)
|
||||
|
||||
if (last !== null) {
|
||||
const newLocation: PlatformLocation = JSON.parse(last)
|
||||
|
||||
if (newLocation.path[3] != null) {
|
||||
loc.path[3] = newLocation.path[3] as Ref<Space>
|
||||
loc.path[4] = newLocation.path[4]
|
||||
if (loc.path[4] == null) {
|
||||
loc.path.length = 4
|
||||
} else {
|
||||
loc.path.length = 5
|
||||
}
|
||||
|
||||
navigate(loc)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,8 @@
|
||||
location,
|
||||
navigate,
|
||||
Separator,
|
||||
Location
|
||||
Location,
|
||||
restoreLocation
|
||||
} from '@hcengineering/ui'
|
||||
|
||||
import { NavigatorModel, SpecialNavModel } from '@hcengineering/workbench'
|
||||
@ -33,7 +34,7 @@
|
||||
|
||||
import ChatNavigator from './navigator/ChatNavigator.svelte'
|
||||
import ChannelView from '../ChannelView.svelte'
|
||||
import { chatSpecials, loadSavedAttachments, storeChannel, openedChannelStore, clearChannel } from './utils'
|
||||
import { chatSpecials, loadSavedAttachments } from './utils'
|
||||
import { SelectChannelEvent } from './types'
|
||||
import { decodeChannelURI, openChannel } from '../../navigation'
|
||||
|
||||
@ -60,16 +61,6 @@
|
||||
syncLocation(loc)
|
||||
})
|
||||
|
||||
openedChannelStore.subscribe((data) => {
|
||||
if (data === undefined) {
|
||||
selectedData = undefined
|
||||
object = undefined
|
||||
} else if (selectedData?._id !== data._id) {
|
||||
selectedData = data
|
||||
openChannel(data._id, data._class, data.thread)
|
||||
}
|
||||
})
|
||||
|
||||
$: void loadObject(selectedData?._id, selectedData?._class)
|
||||
|
||||
async function loadObject (_id?: Ref<Doc>, _class?: Ref<Class<Doc>>): Promise<void> {
|
||||
@ -98,18 +89,20 @@
|
||||
|
||||
if (!id) {
|
||||
currentSpecial = undefined
|
||||
clearChannel()
|
||||
selectedData = undefined
|
||||
object = undefined
|
||||
restoreLocation(loc, chunterId)
|
||||
return
|
||||
}
|
||||
|
||||
currentSpecial = navigatorModel?.specials?.find((special) => special.id === id)
|
||||
|
||||
if (currentSpecial !== undefined) {
|
||||
clearChannel()
|
||||
selectedData = undefined
|
||||
object = undefined
|
||||
} else {
|
||||
const [_id, _class] = decodeChannelURI(loc.path[3])
|
||||
|
||||
storeChannel(_id, _class, loc.path[4] as Ref<ActivityMessage>)
|
||||
selectedData = { _id, _class }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,6 @@
|
||||
//
|
||||
import notification, { type DocNotifyContext } from '@hcengineering/notification'
|
||||
import {
|
||||
type Class,
|
||||
type Doc,
|
||||
generateId,
|
||||
type Ref,
|
||||
SortingOrder,
|
||||
@ -32,7 +30,7 @@ import { get, writable } from 'svelte/store'
|
||||
import view from '@hcengineering/view'
|
||||
import workbench, { type SpecialNavModel } from '@hcengineering/workbench'
|
||||
import attachment, { type SavedAttachments } from '@hcengineering/attachment'
|
||||
import activity, { type ActivityMessage } from '@hcengineering/activity'
|
||||
import activity from '@hcengineering/activity'
|
||||
import { InboxNotificationsClientImpl } from '@hcengineering/notification-resources'
|
||||
import { type Action, showPopup } from '@hcengineering/ui'
|
||||
import contact, { type PersonAccount } from '@hcengineering/contact'
|
||||
@ -41,34 +39,15 @@ import { type DirectMessage } from '@hcengineering/chunter'
|
||||
import { type ChatNavGroupModel, type ChatNavItemModel, type SortFnOptions } from './types'
|
||||
import chunter from '../../plugin'
|
||||
|
||||
const channelStorageKey = 'chunter.openedChannel'
|
||||
const navigatorStateStorageKey = 'chunter.navigatorState'
|
||||
|
||||
interface ChannelMetadata {
|
||||
_id: Ref<Doc>
|
||||
_class: Ref<Class<Doc>>
|
||||
thread?: Ref<ActivityMessage>
|
||||
}
|
||||
interface NavigatorState {
|
||||
collapsedSections: string[]
|
||||
}
|
||||
|
||||
export const savedAttachmentsStore = writable<Array<WithLookup<SavedAttachments>>>([])
|
||||
export const openedChannelStore = writable<ChannelMetadata | undefined>(restoreChannel())
|
||||
export const navigatorStateStore = writable<NavigatorState>(restoreNavigatorState())
|
||||
|
||||
function restoreChannel (): ChannelMetadata | undefined {
|
||||
const raw = localStorage.getItem(channelStorageKey)
|
||||
|
||||
if (raw == null) return undefined
|
||||
|
||||
try {
|
||||
return JSON.parse(raw) as ChannelMetadata
|
||||
} catch (e) {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
function restoreNavigatorState (): NavigatorState {
|
||||
const raw = localStorage.getItem(navigatorStateStorageKey)
|
||||
|
||||
@ -93,18 +72,6 @@ export function toggleSections (_id: string): void {
|
||||
navigatorStateStore.set(result)
|
||||
}
|
||||
|
||||
export function clearChannel (): void {
|
||||
localStorage.removeItem(channelStorageKey)
|
||||
openedChannelStore.set(undefined)
|
||||
}
|
||||
|
||||
export function storeChannel (_id: Ref<Doc>, _class: Ref<Class<Doc>>, thread?: Ref<ActivityMessage>): void {
|
||||
const data: ChannelMetadata = { _id, _class, thread }
|
||||
|
||||
localStorage.setItem(channelStorageKey, JSON.stringify(data))
|
||||
openedChannelStore.set(data)
|
||||
}
|
||||
|
||||
export const chatSpecials: SpecialNavModel[] = [
|
||||
{
|
||||
id: 'threads',
|
||||
|
@ -17,7 +17,8 @@
|
||||
ActivityInboxNotification,
|
||||
decodeObjectURI,
|
||||
DocNotifyContext,
|
||||
InboxNotification
|
||||
InboxNotification,
|
||||
notificationId
|
||||
} from '@hcengineering/notification'
|
||||
import { ActionContext, createQuery, getClient } from '@hcengineering/presentation'
|
||||
import view from '@hcengineering/view'
|
||||
@ -28,6 +29,7 @@
|
||||
Label,
|
||||
location as locationStore,
|
||||
Location,
|
||||
restoreLocation,
|
||||
Scroller,
|
||||
Separator,
|
||||
TabItem,
|
||||
@ -147,6 +149,16 @@
|
||||
|
||||
async function syncLocation (newLocation: Location): Promise<void> {
|
||||
const loc = await resolveLocation(newLocation)
|
||||
if (loc?.loc.path[2] !== notificationId) {
|
||||
return
|
||||
}
|
||||
|
||||
if (loc?.loc.path[3] == null) {
|
||||
selectedContext = undefined
|
||||
restoreLocation(newLocation, notificationId)
|
||||
return
|
||||
}
|
||||
|
||||
const [_id] = decodeObjectURI(loc?.loc.path[3] ?? '')
|
||||
const context = $contextByDocStore.get(_id)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user