Skip to content

Commit

Permalink
refactor(blocks): improve state initialization in EmbedLinkedDocBlock…
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Sep 13, 2024
1 parent f87af5f commit 9f1edb4
Showing 1 changed file with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,21 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
static override styles = styles;

private _load = async () => {
this._loading = true;
this.isError = false;
this.isNoteContentEmpty = true;
this.isBannerEmpty = true;
const {
loading = true,
isError = false,
isBannerEmpty = true,
isNoteContentEmpty = true,
} = this.resetState();

this._loading = loading;
this.isError = isError;
this.isBannerEmpty = isBannerEmpty;
this.isNoteContentEmpty = isNoteContentEmpty;

if (!this._loading) {
return;
}

const linkedDoc = this.linkedDoc;
if (!linkedDoc) {
Expand Down Expand Up @@ -445,6 +456,15 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
);
}

resetState(): {
loading?: boolean;
isError?: boolean;
isNoteContentEmpty?: boolean;
isBannerEmpty?: boolean;
} {
return {};
}

override updated() {
// update card style when linked doc deleted
const linkedDoc = this.linkedDoc;
Expand Down

0 comments on commit 9f1edb4

Please sign in to comment.