Skip to content

Commit

Permalink
fix: resolve loading state after queryUrlData fails (#6102)
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushAgrawal-A2 authored Jan 25, 2024
1 parent 2beb067 commit d057954
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 105 deletions.
10 changes: 5 additions & 5 deletions packages/block-std/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"compilerOptions": {
"rootDir": "./src/",
"outDir": "./dist/",
"noEmit": false
"noEmit": false,
},
"include": ["./src"],
"references": [
{
"path": "../global"
"path": "../global",
},
{
"path": "../store"
}
]
"path": "../store",
},
],
}
43 changes: 25 additions & 18 deletions packages/blocks/src/bookmark-block/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,39 @@ import type { BookmarkBlockComponent } from './bookmark-block.js';
export async function refreshBookmarkUrlData(
bookmarkElement: BookmarkBlockComponent
) {
bookmarkElement.loading = true;
let title = null,
description = null,
icon = null,
image = null;

const queryUrlData = bookmarkElement.service?.queryUrlData;
assertExists(queryUrlData);
try {
bookmarkElement.loading = true;

let title, description, icon, image;
const queryUrlData = bookmarkElement.service?.queryUrlData;
assertExists(queryUrlData);

const bookmarkUrlData = await queryUrlData(bookmarkElement.model.url);
({
title = null,
description = null,
icon = null,
image = null,
} = bookmarkUrlData);

try {
const metaData = await queryUrlData(bookmarkElement.model.url);
title = metaData.title ?? null;
description = metaData.description ?? null;
icon = metaData.icon ?? null;
image = metaData.image ?? null;
if (!title && !description && !icon && !image) {
bookmarkElement.loadingFailed = true;
}
} catch (error) {
console.error(error);
bookmarkElement.loadingFailed = true;
}
} finally {
bookmarkElement.page.updateBlock(bookmarkElement.model, {
title,
description,
icon,
image,
});

bookmarkElement.page.updateBlock(bookmarkElement.model, {
title,
description,
icon,
image,
});
bookmarkElement.loading = false;
bookmarkElement.loading = false;
}
}
56 changes: 34 additions & 22 deletions packages/blocks/src/embed-github-block/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,33 +72,45 @@ export async function queryEmbedGithubApiData(
export async function refreshEmbedGithubUrlData(
embedGithubElement: EmbedGithubBlockComponent
) {
embedGithubElement.loading = true;

const queryUrlData = embedGithubElement.service?.queryUrlData;
assertExists(queryUrlData);
const githubUrlData = await queryUrlData(embedGithubElement.model);

const {
image = null,
let image = null,
status = null,
statusReason = null,
title = null,
description = null,
createdAt = null,
assignees = null,
} = githubUrlData;

embedGithubElement.page.updateBlock(embedGithubElement.model, {
image,
status,
statusReason,
title,
description,
createdAt,
assignees,
});

embedGithubElement.loading = false;
assignees = null;

try {
embedGithubElement.loading = true;

const queryUrlData = embedGithubElement.service?.queryUrlData;
assertExists(queryUrlData);

const githubUrlData = await queryUrlData(embedGithubElement.model);
({
image = null,
status = null,
statusReason = null,
title = null,
description = null,
createdAt = null,
assignees = null,
} = githubUrlData);
} catch (error) {
console.error(error);
} finally {
embedGithubElement.page.updateBlock(embedGithubElement.model, {
image,
status,
statusReason,
title,
description,
createdAt,
assignees,
});

embedGithubElement.loading = false;
}
}

export async function refreshEmbedGithubStatus(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,11 @@ export class EmbedYoutubeBlockComponent extends EmbedBlockElement<

const creatorImageEl =
!loading && creatorImage
? html`<object type="image/webp" data=${creatorImage} draggable="false">
${EmbedCardBannerIcon}
</object>`
? html`<object
type="image/webp"
data=${creatorImage}
draggable="false"
></object>`
: nothing;

return this.renderEmbed(
Expand Down
53 changes: 32 additions & 21 deletions packages/blocks/src/embed-youtube-block/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,40 @@ export async function queryYoutubeOEmbedData(
export async function refreshEmbedYoutubeUrlData(
embedYoutubeElement: EmbedYoutubeBlockComponent
) {
embedYoutubeElement.loading = true;

const queryUrlData = embedYoutubeElement.service?.queryUrlData;
assertExists(queryUrlData);
const youtubeUrlData = await queryUrlData(embedYoutubeElement.model);

const {
image = null,
let image = null,
title = null,
description = null,
creator = null,
creatorUrl = null,
creatorImage = null,
} = youtubeUrlData;

embedYoutubeElement.page.updateBlock(embedYoutubeElement.model, {
image,
title,
description,
creator,
creatorUrl,
creatorImage,
});

embedYoutubeElement.loading = false;
creatorImage = null;

try {
embedYoutubeElement.loading = true;

const queryUrlData = embedYoutubeElement.service?.queryUrlData;
assertExists(queryUrlData);

const youtubeUrlData = await queryUrlData(embedYoutubeElement.model);
({
image = null,
title = null,
description = null,
creator = null,
creatorUrl = null,
creatorImage = null,
} = youtubeUrlData);
} catch (error) {
console.error(error);
} finally {
embedYoutubeElement.page.updateBlock(embedYoutubeElement.model, {
image,
title,
description,
creator,
creatorUrl,
creatorImage,
});

embedYoutubeElement.loading = false;
}
}
16 changes: 8 additions & 8 deletions packages/blocks/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
"compilerOptions": {
"rootDir": "./src/",
"outDir": "./dist/",
"noEmit": false
"noEmit": false,
},
"include": ["./src"],
"references": [
{
"path": "../global"
"path": "../global",
},
{
"path": "../store"
"path": "../store",
},
{
"path": "../block-std"
"path": "../block-std",
},
{
"path": "../lit"
"path": "../lit",
},
{
"path": "../inline"
}
]
"path": "../inline",
},
],
}
4 changes: 2 additions & 2 deletions packages/global/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"compilerOptions": {
"rootDir": "./src/",
"outDir": "./dist/",
"noEmit": false
"noEmit": false,
},
"include": ["./src", "index.d.ts"],
// This package MUST NOT use any other package.
"references": []
"references": [],
}
8 changes: 4 additions & 4 deletions packages/inline/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"compilerOptions": {
"rootDir": "./src/",
"outDir": "./dist/",
"noEmit": false
"noEmit": false,
},
"include": ["./src"],
"references": [
{
"path": "../global"
}
]
"path": "../global",
},
],
}
12 changes: 6 additions & 6 deletions packages/lit/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
"compilerOptions": {
"rootDir": "./src/",
"outDir": "./dist/",
"noEmit": false
"noEmit": false,
},
"include": ["./src"],
"references": [
{
"path": "../global"
"path": "../global",
},
{
"path": "../store"
"path": "../store",
},
{
"path": "../block-std"
}
]
"path": "../block-std",
},
],
}
16 changes: 8 additions & 8 deletions packages/presets/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
"compilerOptions": {
"rootDir": "./src/",
"outDir": "./dist/",
"noEmit": false
"noEmit": false,
},
"include": ["./src"],
"references": [
{
"path": "../global"
"path": "../global",
},
{
"path": "../store"
"path": "../store",
},
{
"path": "../block-std"
"path": "../block-std",
},
{
"path": "../lit"
"path": "../lit",
},
{
"path": "../blocks"
}
]
"path": "../blocks",
},
],
}
10 changes: 5 additions & 5 deletions packages/store/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"compilerOptions": {
"rootDir": "./src/",
"outDir": "./dist/",
"noEmit": false
"noEmit": false,
},
"include": ["./src"],
"references": [
{
"path": "../global"
"path": "../global",
},
{
"path": "../inline"
}
]
"path": "../inline",
},
],
}
6 changes: 3 additions & 3 deletions tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"@store/provider/*": ["../packages/store/provider/*"],
"@store/*": ["../packages/store/src/*"],
"@presets/*": ["../packages/presets/src/*"],
"@playground/*": ["../packages/playground/*"]
}
"@playground/*": ["../packages/playground/*"],
},
},
"include": ["**.spec.ts", "**.test.ts", "**/**.ts"]
"include": ["**.spec.ts", "**.test.ts", "**/**.ts"],
}

1 comment on commit d057954

@vercel
Copy link

@vercel vercel bot commented on d057954 Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

blocksuite – ./packages/playground

try-blocksuite.vercel.app
blocksuite-toeverything.vercel.app
blocksuite-git-master-toeverything.vercel.app

Please sign in to comment.