This commit is contained in:
Untone 2024-07-06 04:03:00 +03:00
parent 2d89f62864
commit 6ba51ad83e

View File

@ -46,7 +46,7 @@ export const AuthorView = (props: Props) => {
const { followers: myFollowers, follows: myFollows } = useFollowing() const { followers: myFollowers, follows: myFollows } = useFollowing()
const { session } = useSession() const { session } = useSession()
const me = createMemo<Author>(() => session()?.user?.app_data?.profile as Author) const me = createMemo<Author>(() => session()?.user?.app_data?.profile as Author)
const [slug, setSlug] = createSignal(props.authorSlug) const [authorSlug, setSlug] = createSignal(props.authorSlug)
const { sortedFeed } = useFeed() const { sortedFeed } = useFeed()
const { modal, hideModal } = useUI() const { modal, hideModal } = useUI()
const loc = useLocation() const loc = useLocation()
@ -76,8 +76,8 @@ export const AuthorView = (props: Props) => {
// 1 // проверяет не собственный ли это профиль, иначе - загружает // 1 // проверяет не собственный ли это профиль, иначе - загружает
const [isFetching, setIsFetching] = createSignal(false) const [isFetching, setIsFetching] = createSignal(false)
createEffect( createEffect(
on([() => session()?.user?.app_data?.profile, () => props.authorSlug || ''], async ([me, s]) => { on([() => session()?.user?.app_data?.profile, () => props.authorSlug || ''], async ([me, slug]) => {
const my = s && me?.slug === s const my = slug && me?.slug === slug
if (my) { if (my) {
console.debug('[Author] my profile precached') console.debug('[Author] my profile precached')
if (me) { if (me) {
@ -85,10 +85,10 @@ export const AuthorView = (props: Props) => {
if (myFollowers()) setFollowers((myFollowers() || []) as Author[]) if (myFollowers()) setFollowers((myFollowers() || []) as Author[])
changeFollowing([...(myFollows?.topics || []), ...(myFollows?.authors || [])]) changeFollowing([...(myFollows?.topics || []), ...(myFollows?.authors || [])])
} }
} else if (s && !isFetching()) { } else if (slug && !isFetching()) {
setIsFetching(true) setIsFetching(true)
setSlug(s) setSlug(slug)
await loadAuthor(s) await loadAuthor({ slug })
setIsFetching(false) // Сброс состояния загрузки после завершения setIsFetching(false) // Сброс состояния загрузки после завершения
} }
}) })
@ -96,19 +96,19 @@ export const AuthorView = (props: Props) => {
// 3 // after fetch loading following data // 3 // after fetch loading following data
createEffect( createEffect(
on( on(
[followers, () => authorsEntities()[slug()]], [followers, () => authorsEntities()[authorSlug()]],
async ([current, found]) => { async ([current, found]) => {
if (current) return if (current) return
if (!found) return if (!found) return
setAuthor(found) setAuthor(found)
console.info(`[Author] profile for @${slug()} fetched`) console.info(`[Author] profile for @${authorSlug()} fetched`)
const followsResp = await query(getAuthorFollowsQuery, { slug: slug() }).toPromise() const followsResp = await query(getAuthorFollowsQuery, { slug: authorSlug() }).toPromise()
const follows = followsResp?.data?.get_author_followers || {} const follows = followsResp?.data?.get_author_followers || {}
changeFollowing([...(follows?.authors || []), ...(follows?.topics || [])]) changeFollowing([...(follows?.authors || []), ...(follows?.topics || [])])
console.info(`[Author] follows for @${slug()} fetched`) console.info(`[Author] follows for @${authorSlug()} fetched`)
const followersResp = await query(getAuthorFollowersQuery, { slug: slug() }).toPromise() const followersResp = await query(getAuthorFollowersQuery, { slug: authorSlug() }).toPromise()
setFollowers(followersResp?.data?.get_author_followers || []) setFollowers(followersResp?.data?.get_author_followers || [])
console.info(`[Author] followers for @${slug()} fetched`) console.info(`[Author] followers for @${authorSlug()} fetched`)
setIsFetching(false) setIsFetching(false)
}, },
{ defer: true } { defer: true }