This commit is contained in:
Untone 2023-12-28 00:04:09 +03:00
parent 5f0ab7d870
commit 7ac836e4e3
2 changed files with 11 additions and 6 deletions

View File

@ -47,8 +47,8 @@ export const AuthorView = (props: Props) => {
const author = createMemo(() => authorEntities()[props.authorSlug])
createEffect(async () => {
if (!author()?.stat) {
const a = await loadAuthor({ slug: props.authorSlug })
if (author() && author().id && !author().stat) {
const a = await loadAuthor({ slug: '', author_id: author().id })
console.debug(`[AuthorView] loaded author:`, a)
}
})
@ -78,8 +78,7 @@ export const AuthorView = (props: Props) => {
onMount(async () => {
checkBioHeight()
const slug = props.authorSlug || props.author.slug || author().slug
await loadAuthor({ slug })
// pagination
if (sortedArticles().length === PRERENDERED_ARTICLES_COUNT) {
await loadMore()

View File

@ -56,8 +56,14 @@ export const addAuthors = (authors: Author[]) => {
)
}
export const loadAuthor = async ({ slug }: { slug: string }): Promise<Author> => {
const author = await apiClient.getAuthor({ slug })
export const loadAuthor = async ({
slug,
author_id,
}: {
slug: string
author_id: number
}): Promise<Author> => {
const author = await apiClient.getAuthor({ slug, author_id })
addAuthors([author])
return author
}