fix preload author

This commit is contained in:
ilya-bkv 2024-03-15 19:42:55 +03:00
parent dd4065036f
commit 8d78ba2c62

View File

@ -48,11 +48,19 @@ export const AuthorView = (props: Props) => {
const [commented, setCommented] = createSignal<Reaction[]>() const [commented, setCommented] = createSignal<Reaction[]>()
// current author // current author
// const [author, _] = createSignal<Author>(props.author) const [author, setAuthor] = createSignal<Author>()
createEffect(() => {
try {
const a = authorEntities()[props.authorSlug]
setAuthor(a)
} catch (error) {
console.debug(error)
}
})
createEffect(async () => { createEffect(async () => {
if (props.author?.id && !props.author.stat) { if (author()?.id && !author().stat) {
const a = await loadAuthor({ slug: '', author_id: props.author.id }) const a = await loadAuthor({ slug: '', author_id: author().id })
console.debug('[AuthorView] loaded author:', a) console.debug('[AuthorView] loaded author:', a)
} }
}) })
@ -112,46 +120,42 @@ export const AuthorView = (props: Props) => {
setCommented(data) setCommented(data)
} }
createEffect( createEffect(() => {
on( if (author()) {
() => props.author, fetchData(author())
() => { fetchComments(author())
fetchData(props.author) }
fetchComments(props.author) })
},
{ defer: true },
),
)
const ogImage = createMemo(() => const ogImage = createMemo(() =>
props.author?.pic author()?.pic
? getImageUrl(props.author?.pic, { width: 1200 }) ? getImageUrl(author()?.pic, { width: 1200 })
: getImageUrl('production/image/logo_image.png'), : getImageUrl('production/image/logo_image.png'),
) )
const description = createMemo(() => getDescription(props.author?.bio)) const description = createMemo(() => getDescription(author()?.bio))
const handleDeleteComment = (id: number) => { const handleDeleteComment = (id: number) => {
setCommented((prev) => prev.filter((comment) => comment.id !== id)) setCommented((prev) => prev.filter((comment) => comment.id !== id))
} }
return ( return (
<div class={styles.authorPage}> <div class={styles.authorPage}>
<Show when={props.author}> <Show when={author()}>
<Title>{props.author.name}</Title> <Title>{author().name}</Title>
<Meta name="descprition" content={description()} /> <Meta name="descprition" content={description()} />
<Meta name="og:type" content="profile" /> <Meta name="og:type" content="profile" />
<Meta name="og:title" content={props.author.name} /> <Meta name="og:title" content={author().name} />
<Meta name="og:image" content={ogImage()} /> <Meta name="og:image" content={ogImage()} />
<Meta name="og:description" content={description()} /> <Meta name="og:description" content={description()} />
<Meta name="twitter:card" content="summary_large_image" /> <Meta name="twitter:card" content="summary_large_image" />
<Meta name="twitter:title" content={props.author.name} /> <Meta name="twitter:title" content={author().name} />
<Meta name="twitter:description" content={description()} /> <Meta name="twitter:description" content={description()} />
<Meta name="twitter:image" content={ogImage()} /> <Meta name="twitter:image" content={ogImage()} />
</Show> </Show>
<div class="wide-container"> <div class="wide-container">
<Show when={props.author} fallback={<Loading />}> <Show when={author()} fallback={<Loading />}>
<> <>
<div class={styles.authorHeader}> <div class={styles.authorHeader}>
<AuthorCard author={props.author} followers={followers()} following={following()} /> <AuthorCard author={author()} followers={followers()} following={following()} />
</div> </div>
<div class={clsx(styles.groupControls, 'row')}> <div class={clsx(styles.groupControls, 'row')}>
<div class="col-md-16"> <div class="col-md-16">
@ -160,16 +164,16 @@ export const AuthorView = (props: Props) => {
<a href={getPagePath(router, 'author', { slug: props.authorSlug })}> <a href={getPagePath(router, 'author', { slug: props.authorSlug })}>
{t('Publications')} {t('Publications')}
</a> </a>
<Show when={props.author.stat}> <Show when={author().stat}>
<span class="view-switcher__counter">{props.author.stat.shouts}</span> <span class="view-switcher__counter">{author().stat.shouts}</span>
</Show> </Show>
</li> </li>
<li classList={{ 'view-switcher__item--selected': getPage().route === 'authorComments' }}> <li classList={{ 'view-switcher__item--selected': getPage().route === 'authorComments' }}>
<a href={getPagePath(router, 'authorComments', { slug: props.authorSlug })}> <a href={getPagePath(router, 'authorComments', { slug: props.authorSlug })}>
{t('Comments')} {t('Comments')}
</a> </a>
<Show when={props.author.stat}> <Show when={author().stat}>
<span class="view-switcher__counter">{props.author.stat.comments}</span> <span class="view-switcher__counter">{author().stat.comments}</span>
</Show> </Show>
</li> </li>
<li classList={{ 'view-switcher__item--selected': getPage().route === 'authorAbout' }}> <li classList={{ 'view-switcher__item--selected': getPage().route === 'authorAbout' }}>
@ -183,10 +187,10 @@ export const AuthorView = (props: Props) => {
</ul> </ul>
</div> </div>
<div class={clsx('col-md-8', styles.additionalControls)}> <div class={clsx('col-md-8', styles.additionalControls)}>
<Show when={props.author?.stat?.rating || props.author?.stat?.rating === 0}> <Show when={author()?.stat?.rating || author()?.stat?.rating === 0}>
<div class={styles.ratingContainer}> <div class={styles.ratingContainer}>
{t('All posts rating')} {t('All posts rating')}
<AuthorShoutsRating author={props.author} class={styles.ratingControl} /> <AuthorShoutsRating author={author()} class={styles.ratingControl} />
</div> </div>
</Show> </Show>
</div> </div>
@ -205,7 +209,7 @@ export const AuthorView = (props: Props) => {
class={styles.longBio} class={styles.longBio}
classList={{ [styles.longBioExpanded]: isBioExpanded() }} classList={{ [styles.longBioExpanded]: isBioExpanded() }}
> >
<div ref={(el) => (bioContainerRef.current = el)} innerHTML={props.author.about} /> <div ref={(el) => (bioContainerRef.current = el)} innerHTML={author().about} />
</div> </div>
<Show when={showExpandBioControl()}> <Show when={showExpandBioControl()}>