fix: loading speeds
This commit is contained in:
28
src/App.tsx
28
src/App.tsx
@@ -121,7 +121,7 @@ function BlisterLoader() {
|
||||
|
||||
function App() {
|
||||
const [posts, setPosts] = useState<ManifestPost[]>([]);
|
||||
const [state, setState] = useState<LoadState>("idle");
|
||||
const [state, setState] = useState<LoadState>("loading");
|
||||
const [error, setError] = useState<string>("");
|
||||
|
||||
useEffect(() => {
|
||||
@@ -343,15 +343,31 @@ function PostPage({
|
||||
const permalink = post
|
||||
? toPermalinkUrl(`/${post.slug}`)
|
||||
: toPermalinkUrl(location.pathname);
|
||||
const metadataTitle =
|
||||
state === "loading"
|
||||
? `${BLOG_NAME} | Loading`
|
||||
: state === "error"
|
||||
? `${BLOG_NAME} | Error`
|
||||
: post
|
||||
? `${title} | ${BLOG_NAME}`
|
||||
: `${BLOG_NAME} | Post Not Found`;
|
||||
const metadataDescription =
|
||||
state === "loading"
|
||||
? `Loading ${BLOG_NAME}...`
|
||||
: state === "error"
|
||||
? manifestError || BLOG_DEFAULT_DESCRIPTION
|
||||
: post
|
||||
? description
|
||||
: `Post not found on ${BLOG_NAME}.`;
|
||||
|
||||
usePageMetadata({
|
||||
title: post ? `${title} | ${BLOG_NAME}` : `${BLOG_NAME} | Post Not Found`,
|
||||
description,
|
||||
title: metadataTitle,
|
||||
description: metadataDescription,
|
||||
path: location.pathname,
|
||||
image: bannerTxId ? arweaveUrl(bannerTxId) : undefined,
|
||||
type: "article",
|
||||
publishedTime: postFrontmatter.date || post?.publishedAt,
|
||||
modifiedTime: postFrontmatter.updated || post?.updated || undefined
|
||||
type: post ? "article" : "website",
|
||||
publishedTime: post ? postFrontmatter.date || post.publishedAt : undefined,
|
||||
modifiedTime: post ? postFrontmatter.updated || post.updated || undefined : undefined
|
||||
});
|
||||
|
||||
if (state === "loading") return <BlisterLoader />;
|
||||
|
||||
14
src/lib.ts
14
src/lib.ts
@@ -113,16 +113,26 @@ const getLatestManifestFromAo = async (): Promise<string | null> => {
|
||||
};
|
||||
|
||||
export const loadManifest = async (): Promise<ManifestPost[]> => {
|
||||
const manifestTxId = (await getLatestManifestFromAo()) ?? MANIFEST_TX_ID;
|
||||
const loadByTxId = async (manifestTxId: string): Promise<ManifestPost[]> => {
|
||||
const response = await fetch(arweaveUrl(manifestTxId));
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to load manifest (${response.status})`);
|
||||
}
|
||||
|
||||
const payload: unknown = await response.json();
|
||||
return parseManifest(payload);
|
||||
};
|
||||
|
||||
try {
|
||||
return await loadByTxId(MANIFEST_TX_ID);
|
||||
} catch (manifestError) {
|
||||
const latestManifestTxId = await getLatestManifestFromAo();
|
||||
if (!latestManifestTxId || latestManifestTxId === MANIFEST_TX_ID) {
|
||||
throw manifestError;
|
||||
}
|
||||
return loadByTxId(latestManifestTxId);
|
||||
}
|
||||
};
|
||||
|
||||
const isObject = (value: unknown): value is Record<string, unknown> =>
|
||||
typeof value === "object" && value !== null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user