less-code
This commit is contained in:
parent
6fbe9603fe
commit
69fc0ffd07
|
@ -53,8 +53,10 @@ export const AuthorView = (props: Props) => {
|
||||||
const [commented, setCommented] = createSignal<Reaction[]>()
|
const [commented, setCommented] = createSignal<Reaction[]>()
|
||||||
const modal = MODALS[searchParams().m]
|
const modal = MODALS[searchParams().m]
|
||||||
|
|
||||||
createEffect(async () => {
|
const [sessionChecked, setSessionChecked] = createSignal(false)
|
||||||
if (props.authorSlug && session()?.user?.app_data?.profile?.slug === props.authorSlug) {
|
createEffect(() => {
|
||||||
|
if (!sessionChecked() && props.authorSlug && session()?.user?.app_data?.profile?.slug === props.authorSlug) {
|
||||||
|
setSessionChecked(true)
|
||||||
console.info('preloaded my own profile')
|
console.info('preloaded my own profile')
|
||||||
const { profile, authors, topics } = session().user.app_data
|
const { profile, authors, topics } = session().user.app_data
|
||||||
setFollowers(myFollowers)
|
setFollowers(myFollowers)
|
||||||
|
@ -63,35 +65,22 @@ export const AuthorView = (props: Props) => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
createEffect(async () => {
|
|
||||||
if (Object.keys(authorEntities()).includes(props.authorSlug) && !author()?.id) {
|
|
||||||
// use preloaded author
|
|
||||||
const a = authorEntities()[props.authorSlug]
|
|
||||||
setAuthor(a)
|
|
||||||
console.debug('[AuthorView] preloaded author:', a)
|
|
||||||
} else if (props.authorSlug && !author()?.stat) {
|
|
||||||
// load author
|
|
||||||
const a = await loadAuthor({ slug: props.authorSlug, author_id: author()?.id })
|
|
||||||
setAuthor(a)
|
|
||||||
console.debug('[AuthorView] loaded author:', a)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const bioContainerRef: { current: HTMLDivElement } = { current: null }
|
const bioContainerRef: { current: HTMLDivElement } = { current: null }
|
||||||
const bioWrapperRef: { current: HTMLDivElement } = { current: null }
|
const bioWrapperRef: { current: HTMLDivElement } = { current: null }
|
||||||
|
|
||||||
const fetchData = async (slug) => {
|
const fetchData = async (slug) => {
|
||||||
try {
|
try {
|
||||||
const [subscriptionsResult, followersResult] = await Promise.all([
|
const [subscriptionsResult, followersResult, authorResult] = await Promise.all([
|
||||||
apiClient.getAuthorFollows({ slug }),
|
apiClient.getAuthorFollows({ slug }),
|
||||||
apiClient.getAuthorFollowers({ slug }),
|
apiClient.getAuthorFollowers({ slug }),
|
||||||
|
loadAuthor({ slug })
|
||||||
])
|
])
|
||||||
|
|
||||||
const { authors, topics } = subscriptionsResult
|
const { authors, topics } = subscriptionsResult
|
||||||
|
setAuthor(authorResult)
|
||||||
setFollowing([...(authors || []), ...(topics || [])])
|
setFollowing([...(authors || []), ...(topics || [])])
|
||||||
setFollowers(followersResult || [])
|
setFollowers(followersResult || [])
|
||||||
|
|
||||||
console.info('[components.Author] following data loaded')
|
console.info('[components.Author] data loaded')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[components.Author] fetch error', error)
|
console.error('[components.Author] fetch error', error)
|
||||||
}
|
}
|
||||||
|
@ -103,14 +92,6 @@ export const AuthorView = (props: Props) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
fetchData(props.authorSlug)
|
|
||||||
|
|
||||||
if (!modal) {
|
|
||||||
hideModal()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const loadMore = async () => {
|
const loadMore = async () => {
|
||||||
saveScrollPosition()
|
saveScrollPosition()
|
||||||
const { hasMore } = await loadShouts({
|
const { hasMore } = await loadShouts({
|
||||||
|
@ -123,7 +104,9 @@ export const AuthorView = (props: Props) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
|
if (!modal) hideModal()
|
||||||
checkBioHeight()
|
checkBioHeight()
|
||||||
|
fetchData(props.authorSlug)
|
||||||
|
|
||||||
// pagination
|
// pagination
|
||||||
if (sortedArticles().length === PRERENDERED_ARTICLES_COUNT) {
|
if (sortedArticles().length === PRERENDERED_ARTICLES_COUNT) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user