From 8865006d3fc80285de84bda67b18c3cce0a4fb90 Mon Sep 17 00:00:00 2001 From: Denis Maslennikov <41147528+disant1@users.noreply.github.com> Date: Thu, 8 Dec 2022 08:17:53 +0700 Subject: [PATCH] TSK-461: Refactor Tracker/Remember Issues (#2425) * Refactor: Move drafts.ts to /presentation Signed-off-by: Denis Maslennikov * Refactor remember issues Signed-off-by: Denis Maslennikov * Fix close issue bug Signed-off-by: Denis Maslennikov * Refactor and fix draft clean Signed-off-by: Denis Maslennikov * Minor handle method fix Signed-off-by: Denis Maslennikov Signed-off-by: Denis Maslennikov --- packages/presentation/src/drafts.ts | 67 ++++++++++++++++ packages/presentation/src/index.ts | 1 + packages/presentation/src/plugin.ts | 3 +- .../src/components/CommentInput.svelte | 3 +- plugins/chunter-resources/src/drafts.ts | 18 ----- plugins/chunter-resources/src/plugin.ts | 5 +- .../src/components/CreateIssue.svelte | 78 +++++++++++++------ .../src/components/NewIssueHeader.svelte | 26 +++---- 8 files changed, 137 insertions(+), 64 deletions(-) create mode 100644 packages/presentation/src/drafts.ts delete mode 100644 plugins/chunter-resources/src/drafts.ts diff --git a/packages/presentation/src/drafts.ts b/packages/presentation/src/drafts.ts new file mode 100644 index 0000000000..566e8fcd02 --- /dev/null +++ b/packages/presentation/src/drafts.ts @@ -0,0 +1,67 @@ +import { fetchMetadataLocalStorage, setMetadataLocalStorage } from '@hcengineering/ui' +import { writable, get } from 'svelte/store' +import { getClient } from '.' +import presentation from './plugin' + +/** + * @public + */ +// eslint-disable-next-line +export const draftStore = writable>(fetchMetadataLocalStorage(presentation.metadata.Draft) || {}) + +/** + * @public + */ +export function updateDraftStore (id: string, draft: any): void { + draftStore.update((drafts) => { + drafts[id] = draft + setMetadataLocalStorage(presentation.metadata.Draft, drafts) + return drafts + }) +} + +/** + * @public + */ +export function updateUserDraft (id: string, draft: any): void { + const client = getClient() + draftStore.update((drafts) => { + // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions + const userDrafts: Record = drafts[client.user] || {} + userDrafts[id] = draft + drafts[client.user] = userDrafts + setMetadataLocalStorage(presentation.metadata.Draft, drafts) + return drafts + }) +} + +/** + * @public + */ +export function getUserDraft (id: string): any { + const client = getClient() + const drafts: Record = get(draftStore) + // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions + const userDrafts: Record = drafts[client.user] || {} + const draft: Record = userDrafts[id] + return draft +} + +/** + * @public + */ +export function isUserDraftExists (id: string): boolean { + const client = getClient() + const drafts: Record = get(draftStore) + const userDrafts: Record = drafts[client.user] + // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions + if (!userDrafts) { + return false + } + const draftRecord: Record = userDrafts[id] + // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions + if (!draftRecord) { + return false + } + return true +} diff --git a/packages/presentation/src/index.ts b/packages/presentation/src/index.ts index 09b7ef790c..5145137ad4 100644 --- a/packages/presentation/src/index.ts +++ b/packages/presentation/src/index.ts @@ -47,6 +47,7 @@ export { connect, versionError } from './connect' export { default } from './plugin' export * from './types' export * from './utils' +export * from './drafts' export { presentationId } addStringsLoader(presentationId, async (lang: string) => { diff --git a/packages/presentation/src/plugin.ts b/packages/presentation/src/plugin.ts index 689017c639..e802faf584 100644 --- a/packages/presentation/src/plugin.ts +++ b/packages/presentation/src/plugin.ts @@ -59,6 +59,7 @@ export default plugin(presentationId, { GravatarsManaged: '' as IntlString }, metadata: { - RequiredVersion: '' as Metadata + RequiredVersion: '' as Metadata, + Draft: '' as Metadata> } }) diff --git a/plugins/chunter-resources/src/components/CommentInput.svelte b/plugins/chunter-resources/src/components/CommentInput.svelte index cf064a1bc5..e2c080e15f 100644 --- a/plugins/chunter-resources/src/components/CommentInput.svelte +++ b/plugins/chunter-resources/src/components/CommentInput.svelte @@ -16,10 +16,9 @@ @@ -64,13 +56,13 @@