Files draft fix (#2638)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-02-15 10:38:48 +06:00 committed by GitHub
parent 199da5077a
commit 12a241eee7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,6 @@
import { getCurrentAccount } from '@hcengineering/core'
import { fetchMetadataLocalStorage, setMetadataLocalStorage } from '@hcengineering/ui' import { fetchMetadataLocalStorage, setMetadataLocalStorage } from '@hcengineering/ui'
import { writable, get } from 'svelte/store' import { get, writable } from 'svelte/store'
import { getClient } from '.'
import presentation from './plugin' import presentation from './plugin'
/** /**
@ -14,7 +14,7 @@ export const draftStore = writable<Record<string, any>>(fetchMetadataLocalStorag
*/ */
export function updateDraftStore (id: string, draft: any): void { export function updateDraftStore (id: string, draft: any): void {
draftStore.update((drafts) => { draftStore.update((drafts) => {
if (draft === undefined) { if (draft !== undefined) {
drafts[id] = draft drafts[id] = draft
} else { } else {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
@ -29,12 +29,12 @@ export function updateDraftStore (id: string, draft: any): void {
* @public * @public
*/ */
export function updateUserDraft (id: string, draft: any): void { export function updateUserDraft (id: string, draft: any): void {
const client = getClient() const me = getCurrentAccount()._id
draftStore.update((drafts) => { draftStore.update((drafts) => {
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
const userDrafts: Record<string, any> = drafts[client.user] || {} const userDrafts: Record<string, any> = drafts[me] || {}
userDrafts[id] = draft userDrafts[id] = draft
drafts[client.user] = userDrafts drafts[me] = userDrafts
setMetadataLocalStorage(presentation.metadata.Draft, drafts) setMetadataLocalStorage(presentation.metadata.Draft, drafts)
return drafts return drafts
}) })
@ -44,10 +44,10 @@ export function updateUserDraft (id: string, draft: any): void {
* @public * @public
*/ */
export function getUserDraft (id: string): any { export function getUserDraft (id: string): any {
const client = getClient() const me = getCurrentAccount()._id
const drafts: Record<string, any> = get(draftStore) const drafts: Record<string, any> = get(draftStore)
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
const userDrafts: Record<string, any> = drafts[client.user] || {} const userDrafts: Record<string, any> = drafts[me] || {}
const draft: Record<string, any> = userDrafts[id] const draft: Record<string, any> = userDrafts[id]
return draft return draft
} }
@ -56,9 +56,9 @@ export function getUserDraft (id: string): any {
* @public * @public
*/ */
export function isUserDraftExists (id: string): boolean { export function isUserDraftExists (id: string): boolean {
const client = getClient() const me = getCurrentAccount()._id
const drafts: Record<string, any> = get(draftStore) const drafts: Record<string, any> = get(draftStore)
const userDrafts: Record<string, any> = drafts[client.user] const userDrafts: Record<string, any> = drafts[me]
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (!userDrafts) { if (!userDrafts) {
return false return false