From 18adac0e95261da77513f94a680f291f63b28f75 Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Wed, 27 Apr 2022 17:50:48 +0200 Subject: [PATCH] Improve contents list. (#874) --- .../src/app/shared/state/contents.state.ts | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/shared/state/contents.state.ts b/frontend/src/app/shared/state/contents.state.ts index 1ca153769..58c043d39 100644 --- a/frontend/src/app/shared/state/contents.state.ts +++ b/frontend/src/app/shared/state/contents.state.ts @@ -15,6 +15,8 @@ import { AppsState } from './apps.state'; import { SavedQuery } from './queries'; import { SchemasState } from './schemas.state'; +/* eslint-disable @typescript-eslint/no-throw-literal */ + export type StatusInfo = Readonly<{ status: string; color: string }>; @@ -164,7 +166,7 @@ export abstract class ContentsStateBase extends State { return EMPTY; } - this.next({ isLoading: true }, 'Loading Done'); + this.next({ isLoading: true }, 'Loading Started'); const { page, pageSize, query, reference, referencing, total } = this.snapshot; @@ -265,7 +267,7 @@ export abstract class ContentsStateBase extends State { 'i18n:contents.unpublishReferrerConfirmTitle', 'i18n:contents.unpublishReferrerConfirmText', 'unpublishReferencngContent').pipe( - switchMap(() => this.loadInternalCore(false)), shareSubscribed(this.dialogs)); + switchMap(() => this.reloadContents(contents)), shareSubscribed(this.dialogs)); } public deleteMany(contents: ReadonlyArray) { @@ -334,6 +336,31 @@ export abstract class ContentsStateBase extends State { return this.loadInternal(false); } + private reloadContents(contents: ReadonlyArray) { + this.next({ isLoading: true }, 'Loading Done'); + + return this.contentsService.getAllContents(this.appName, { ids: contents.map(x => x.id) }).pipe( + tap(updates => { + return this.next(s => { + let contents = s.contents, selectedContent = s.selectedContent; + + for (const content of updates.items) { + contents = contents.replacedBy('id', content); + + selectedContent = + s.selectedContent?.id !== content.id ? + s.selectedContent : + content; + } + + return { ...s, contents, selectedContent }; + }); + }), + finalize(() => { + this.next({ isLoading: false }, 'Loading Done'); + })); + } + private replaceContent(content: ContentDto, oldVersion?: Version, updateText?: string) { if (!oldVersion || !oldVersion.eq(content.version)) { if (updateText) { @@ -388,7 +415,6 @@ export abstract class ContentsStateBase extends State { const error = errors[0].error!; if (errors.length >= contents.length) { - // eslint-disable-next-line @typescript-eslint/no-throw-literal throw error; } else { this.dialogs.notifyError(error);