fix: author typing
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
type Author = { alias: string; endpoint: string }
|
export type Author = { alias: string; endpoint: string }
|
||||||
|
|
||||||
const correspondanceCache = new Map<string, Author>()
|
const correspondanceCache = new Map<string, Author>()
|
||||||
|
|
||||||
|
console.log({ correspondanceCache })
|
||||||
|
|
||||||
export const getUniqueAka = async (did: string): Promise<Author> => {
|
export const getUniqueAka = async (did: string): Promise<Author> => {
|
||||||
if (correspondanceCache.has(did)) {
|
if (correspondanceCache.has(did)) {
|
||||||
return correspondanceCache.get(did) as Author
|
return correspondanceCache.get(did) as Author
|
||||||
@@ -25,19 +27,21 @@ export const getAka = async (dids: Set<string>) => {
|
|||||||
const correspondance = await Promise.all(
|
const correspondance = await Promise.all(
|
||||||
[...dids].map(async (did) => {
|
[...dids].map(async (did) => {
|
||||||
if (correspondanceCache.has(did)) {
|
if (correspondanceCache.has(did)) {
|
||||||
return [did, correspondanceCache.get(did)?.alias] as [string, string]
|
return [did, correspondanceCache.get(did)] as [string, Author]
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(`https://plc.directory/${did}`)
|
const response = await fetch(`https://plc.directory/${did}`)
|
||||||
const {
|
const {
|
||||||
alsoKnownAs: [aka],
|
alsoKnownAs: [aka],
|
||||||
|
service: [{ serviceEndpoint }],
|
||||||
} = await response.json()
|
} = await response.json()
|
||||||
|
|
||||||
const alias = aka.replace("at://", "")
|
const alias = aka.replace("at://", "")
|
||||||
|
const author = { alias, endpoint: serviceEndpoint }
|
||||||
|
|
||||||
correspondanceCache.set(did, alias)
|
correspondanceCache.set(did, author)
|
||||||
|
|
||||||
return [did, alias] as [string, string]
|
return [did, author] as [string, Author]
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { getAka } from "@/modules/atproto/getAka"
|
import { Author, getAka } from "@/modules/atproto/getAka"
|
||||||
import { PublicNoteListItem } from "@/modules/note/models/Note"
|
import { PublicNoteListItem } from "@/modules/note/models/Note"
|
||||||
import { computedAsync, useAsyncState } from "@vueuse/core"
|
import { computedAsync, useAsyncState } from "@vueuse/core"
|
||||||
|
|
||||||
@@ -13,14 +13,16 @@ const { state, isLoading } = useAsyncState<{
|
|||||||
{ notes: [] },
|
{ notes: [] },
|
||||||
)
|
)
|
||||||
|
|
||||||
const aka = computedAsync<Map<string, string>>(async () => {
|
const aka = computedAsync<Map<string, Author>>(async () => {
|
||||||
if (state.value.notes.length === 0) {
|
if (state.value.notes.length === 0) {
|
||||||
return new Map()
|
return new Map()
|
||||||
}
|
}
|
||||||
|
|
||||||
return getAka(new Set(state.value.notes.map((n) => n.did)))
|
return getAka(new Set(state.value.notes.map((n) => n.did)))
|
||||||
}, new Map())
|
}, new Map())
|
||||||
|
|
||||||
const getAlias = (did: string) => aka.value.get(did) ?? ""
|
const getAlias = (did: string) =>
|
||||||
|
aka.value.has(did) ? aka.value.get(did)?.alias : ""
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -61,8 +61,6 @@ watch(article, () => {
|
|||||||
downloadFont(article.value.value.fontFamily)
|
downloadFont(article.value.value.fontFamily)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("font size:", article.value?.value.fontSize)
|
|
||||||
|
|
||||||
if (article.value?.value.fontSize) {
|
if (article.value?.value.fontSize) {
|
||||||
const root = document.documentElement
|
const root = document.documentElement
|
||||||
root.style.setProperty("--font-size", `${article.value.value.fontSize}pt`)
|
root.style.setProperty("--font-size", `${article.value.value.fontSize}pt`)
|
||||||
@@ -122,9 +120,11 @@ watch(
|
|||||||
>{{ title }}</a
|
>{{ title }}</a
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
<span class="badge badge-accent badge-author" v-if="author">{{
|
<span class="badge" v-if="publishedAt">{{ publishedAt }}</span>
|
||||||
author.alias
|
|
||||||
}}</span>
|
<span class="badge badge-accent badge-author" v-if="author">
|
||||||
|
{{ author.alias }}</span
|
||||||
|
>
|
||||||
<article class="note-display" v-html="content"></article>
|
<article class="note-display" v-html="content"></article>
|
||||||
<router-link
|
<router-link
|
||||||
:to="{ name: 'Home' }"
|
:to="{ name: 'Home' }"
|
||||||
|
|||||||
Reference in New Issue
Block a user