diff --git a/src/web/lib/api.ts b/src/web/lib/api.ts index 48edce2..5419b55 100644 --- a/src/web/lib/api.ts +++ b/src/web/lib/api.ts @@ -148,11 +148,14 @@ async function getLocalPosts(did: string, collection: string): Promise { const indexRes = await fetch(`/at/${did}/${collection}/index.json`) if (indexRes.ok && isJsonResponse(indexRes)) { const rkeys: string[] = await indexRes.json() - const posts: Post[] = [] - for (const rkey of rkeys) { - const res = await fetch(`/at/${did}/${collection}/${rkey}.json`) - if (res.ok && isJsonResponse(res)) posts.push(await res.json()) - } + const results = await Promise.all( + rkeys.map(async (rkey) => { + const res = await fetch(`/at/${did}/${collection}/${rkey}.json`) + if (res.ok && isJsonResponse(res)) return res.json() as Promise + return null + }) + ) + const posts = results.filter((p): p is Post => p !== null) return posts.sort((a, b) => new Date(b.value.publishedAt).getTime() - new Date(a.value.publishedAt).getTime() )