app-data-author
This commit is contained in:
parent
e3c00cc6cd
commit
58c4d6eae7
|
@ -38,26 +38,36 @@ const LOAD_MORE_PAGE_SIZE = 9
|
|||
|
||||
export const AuthorView = (props: Props) => {
|
||||
const { t } = useLocalize()
|
||||
const { loadSubscriptions } = useFollowing()
|
||||
const { subscriptions, followers } = useFollowing()
|
||||
const { session } = useSession()
|
||||
const { sortedArticles } = useArticlesStore({ shouts: props.shouts })
|
||||
const { authorEntities } = useAuthorsStore({ authors: [props.author] })
|
||||
const { page: getPage, searchParams } = useRouter()
|
||||
const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false)
|
||||
const [isBioExpanded, setIsBioExpanded] = createSignal(false)
|
||||
const [followers, setFollowers] = createSignal<Author[]>([])
|
||||
const [author, setAuthor] = createSignal<Author>()
|
||||
const [following, setFollowing] = createSignal<Array<Author | Topic>>([])
|
||||
const [showExpandBioControl, setShowExpandBioControl] = createSignal(false)
|
||||
const [commented, setCommented] = createSignal<Reaction[]>()
|
||||
const modal = MODALS[searchParams().m]
|
||||
|
||||
// current author
|
||||
const [author, setAuthor] = createSignal<Author>()
|
||||
createEffect(() => {
|
||||
try {
|
||||
const a = authorEntities()[props.authorSlug]
|
||||
setAuthor(a)
|
||||
} catch (error) {
|
||||
console.debug(error)
|
||||
if(props.authorSlug) {
|
||||
if (session()?.user?.app_data?.profile?.slug === props.authorSlug) {
|
||||
console.info('my own profile')
|
||||
const {profile, authors, topics} = session().user.app_data
|
||||
setAuthor(profile)
|
||||
setFollowing([...authors, ...topics])
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
const a = authorEntities()[props.authorSlug]
|
||||
setAuthor(a)
|
||||
console.debug('[Author] expecting following data fetched')
|
||||
} catch (error) {
|
||||
console.debug(error)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { clsx } from 'clsx'
|
||||
import { For, Show, createEffect, createSignal, onMount } from 'solid-js'
|
||||
|
||||
import { useFollowing } from '../../../context/following'
|
||||
import { useLocalize } from '../../../context/localize'
|
||||
import { useSession } from '../../../context/session'
|
||||
import { apiClient } from '../../../graphql/client/core'
|
||||
|
@ -20,23 +21,20 @@ import stylesSettings from '../../../styles/FeedSettings.module.scss'
|
|||
|
||||
export const ProfileSubscriptions = () => {
|
||||
const { t, lang } = useLocalize()
|
||||
const { author } = useSession()
|
||||
const [following, setFollowing] = createSignal<Array<Author | Topic>>([])
|
||||
const [filtered, setFiltered] = createSignal<Array<Author | Topic>>([])
|
||||
const [subscriptionFilter, setSubscriptionFilter] = createSignal<SubscriptionFilter>('all')
|
||||
const { author, session } = useSession()
|
||||
const { subscriptions } = useFollowing()
|
||||
const [following, setFollowing] = (createSignal < Array < Author) | (Topic >> [])
|
||||
const [filtered, setFiltered] = (createSignal < Array < Author) | (Topic >> [])
|
||||
const [subscriptionFilter, setSubscriptionFilter] = createSignal < SubscriptionFilter > 'all'
|
||||
const [searchQuery, setSearchQuery] = createSignal('')
|
||||
|
||||
const fetchSubscriptions = async () => {
|
||||
try {
|
||||
const slug = author()?.slug
|
||||
const authorFollows = await apiClient.getAuthorFollows({ slug })
|
||||
setFollowing([...authorFollows['authors']])
|
||||
setFiltered([...authorFollows['authors'], ...authorFollows['topics']])
|
||||
} catch (error) {
|
||||
console.error('[fetchSubscriptions] :', error)
|
||||
throw error
|
||||
createEffect(() => {
|
||||
if (subscriptions()) {
|
||||
const { authors, topics } = subscriptions()
|
||||
setFollowing([...authors, ...topics])
|
||||
setFiltered([...authors, ...topics])
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
createEffect(() => {
|
||||
if (following()) {
|
||||
|
@ -53,10 +51,6 @@ export const ProfileSubscriptions = () => {
|
|||
}
|
||||
})
|
||||
|
||||
onMount(async () => {
|
||||
await fetchSubscriptions()
|
||||
})
|
||||
|
||||
return (
|
||||
<div class="wide-container">
|
||||
<div class="row">
|
||||
|
|
|
@ -2,12 +2,13 @@ import { Accessor, JSX, createContext, createEffect, createSignal, useContext }
|
|||
import { createStore } from 'solid-js/store'
|
||||
|
||||
import { apiClient } from '../graphql/client/core'
|
||||
import { AuthorFollows, FollowingEntity } from '../graphql/schema/core.gen'
|
||||
import { AuthorFollows, FollowingEntity, Author } from '../graphql/schema/core.gen'
|
||||
|
||||
import { useSession } from './session'
|
||||
|
||||
interface FollowingContextType {
|
||||
loading: Accessor<boolean>
|
||||
followers: Accessor<Array<Author>>
|
||||
subscriptions: AuthorFollows
|
||||
setSubscriptions: (subscriptions: AuthorFollows) => void
|
||||
setFollowing: (what: FollowingEntity, slug: string, value: boolean) => void
|
||||
|
@ -31,6 +32,7 @@ const EMPTY_SUBSCRIPTIONS: AuthorFollows = {
|
|||
|
||||
export const FollowingProvider = (props: { children: JSX.Element }) => {
|
||||
const [loading, setLoading] = createSignal<boolean>(false)
|
||||
const [followers, setFollowers] = createSignal<Array<Author>>([])
|
||||
const [subscriptions, setSubscriptions] = createStore<AuthorFollows>(EMPTY_SUBSCRIPTIONS)
|
||||
const { author, session } = useSession()
|
||||
|
||||
|
@ -77,8 +79,14 @@ export const FollowingProvider = (props: { children: JSX.Element }) => {
|
|||
|
||||
createEffect(() => {
|
||||
if (author()) {
|
||||
console.debug('[context.following] author update detect')
|
||||
fetchData()
|
||||
try {
|
||||
const { authors, followers, topics } = session().user.app_data
|
||||
setSubscriptions({ authors, topics })
|
||||
setFollowers(followers)
|
||||
if(!authors) fetchData()
|
||||
} catch(e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -116,6 +124,7 @@ export const FollowingProvider = (props: { children: JSX.Element }) => {
|
|||
setSubscriptions,
|
||||
isOwnerSubscribed,
|
||||
setFollowing,
|
||||
followers,
|
||||
loadSubscriptions: fetchData,
|
||||
follow,
|
||||
unfollow,
|
||||
|
|
|
@ -199,6 +199,7 @@ export const SessionProvider = (props: {
|
|||
}
|
||||
|
||||
onCleanup(() => clearTimeout(minuteLater))
|
||||
|
||||
const authorData = async () => {
|
||||
const u = session()?.user
|
||||
return u ? (await apiClient.getAuthorId({ user: u.id.trim() })) || null : null
|
||||
|
@ -217,7 +218,15 @@ export const SessionProvider = (props: {
|
|||
apiClient.connect(token)
|
||||
inboxClient.connect(token)
|
||||
}
|
||||
if (!author()) loadAuthor()
|
||||
|
||||
try {
|
||||
const { profile } = session().user.app_data
|
||||
setAuthor(profile)
|
||||
addAuthors([profile])
|
||||
if(!profile) loadAuthor()
|
||||
} catch(e) {
|
||||
console.error(e)
|
||||
}
|
||||
|
||||
setIsSessionLoaded(true)
|
||||
}
|
||||
|
@ -262,8 +271,7 @@ export const SessionProvider = (props: {
|
|||
() => props.onStateChangeCallback,
|
||||
() => {
|
||||
props.onStateChangeCallback(session())
|
||||
},
|
||||
{ defer: true },
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user