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