get-authors-all-fix
This commit is contained in:
parent
a383283cd2
commit
aca1358c18
|
@ -34,7 +34,7 @@ export const AllAuthorsView = (props: Props) => {
|
|||
const { searchParams, changeSearchParams } = useRouter<AllAuthorsPageSearchParams>()
|
||||
const { sortedAuthors } = useAuthorsStore({
|
||||
authors: props.authors,
|
||||
sortBy: searchParams().by || 'shouts',
|
||||
sortBy: searchParams().by || 'name',
|
||||
})
|
||||
|
||||
const [searchQuery, setSearchQuery] = createSignal('')
|
||||
|
@ -42,13 +42,13 @@ export const AllAuthorsView = (props: Props) => {
|
|||
createEffect(() => {
|
||||
if (!searchParams().by) {
|
||||
changeSearchParams({
|
||||
by: 'shouts',
|
||||
by: 'name',
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
createEffect(() => {
|
||||
setAuthorsSort(searchParams().by || 'shouts')
|
||||
setAuthorsSort(searchParams().by || 'name')
|
||||
})
|
||||
|
||||
const byLetter = createMemo<{ [letter: string]: Author[] }>(() => {
|
||||
|
@ -171,7 +171,9 @@ export const AllAuthorsView = (props: Props) => {
|
|||
<div class={clsx(styles.topic, 'topic col-sm-12 col-md-8')}>
|
||||
<div class="topic-title">
|
||||
<a href={`/author/${author.slug}`}>{author.name}</a>
|
||||
<span class={styles.articlesCounter}>{author.stat.shouts}</span>
|
||||
<Show when={author.stat}>
|
||||
<span class={styles.articlesCounter}>{author.stat.shouts}</span>
|
||||
</Show>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
|
|
@ -40,13 +40,19 @@ export const AuthorView = (props: Props) => {
|
|||
const { authorEntities } = useAuthorsStore({ authors: [props.author] })
|
||||
|
||||
const { page: getPage } = useRouter()
|
||||
const author = createMemo(() => authorEntities()[props.authorSlug])
|
||||
const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false)
|
||||
const [isBioExpanded, setIsBioExpanded] = createSignal(false)
|
||||
const [followers, setFollowers] = createSignal<Author[]>([])
|
||||
const [following, setFollowing] = createSignal<Array<Author | Topic>>([])
|
||||
const [showExpandBioControl, setShowExpandBioControl] = createSignal(false)
|
||||
|
||||
const author = createMemo(() => authorEntities()[props.authorSlug])
|
||||
createEffect(async () => {
|
||||
if (author() && !author().stat) {
|
||||
await apiClient.getAuthor({ author_id: author().id })
|
||||
}
|
||||
})
|
||||
|
||||
const bioContainerRef: { current: HTMLDivElement } = { current: null }
|
||||
const bioWrapperRef: { current: HTMLDivElement } = { current: null }
|
||||
const fetchSubscriptions = async (): Promise<{ authors: Author[]; topics: Topic[] }> => {
|
||||
|
@ -71,20 +77,24 @@ export const AuthorView = (props: Props) => {
|
|||
}
|
||||
|
||||
onMount(async () => {
|
||||
try {
|
||||
const userSubscribers = await apiClient.getAuthorFollowers({ slug: props.authorSlug })
|
||||
setFollowers(userSubscribers)
|
||||
} catch (error) {
|
||||
console.error('[getAuthorFollowers]', error)
|
||||
}
|
||||
|
||||
checkBioHeight()
|
||||
|
||||
// pagination
|
||||
if (sortedArticles().length === PRERENDERED_ARTICLES_COUNT) {
|
||||
await loadMore()
|
||||
}
|
||||
const { authors, topics } = await fetchSubscriptions()
|
||||
setFollowing([...(authors || []), ...(topics || [])])
|
||||
})
|
||||
|
||||
createEffect(async () => {
|
||||
console.error('[AuthorView] load subscriptions')
|
||||
try {
|
||||
const { authors, topics } = await fetchSubscriptions()
|
||||
setFollowing([...(authors || []), ...(topics || [])])
|
||||
const userSubscribers = await apiClient.getAuthorFollowers({ slug: author().slug })
|
||||
setFollowers(userSubscribers)
|
||||
} catch (error) {
|
||||
console.error('[AuthorView] error:', error)
|
||||
}
|
||||
})
|
||||
|
||||
createEffect(() => {
|
||||
|
@ -160,13 +170,17 @@ export const AuthorView = (props: Props) => {
|
|||
<a href={getPagePath(router, 'author', { slug: props.authorSlug })}>
|
||||
{t('Publications')}
|
||||
</a>
|
||||
<span class="view-switcher__counter">{author().stat.shouts}</span>
|
||||
<Show when={author().stat}>
|
||||
<span class="view-switcher__counter">{author().stat.shouts}</span>
|
||||
</Show>
|
||||
</li>
|
||||
<li classList={{ 'view-switcher__item--selected': getPage().route === 'authorComments' }}>
|
||||
<a href={getPagePath(router, 'authorComments', { slug: props.authorSlug })}>
|
||||
{t('Comments')}
|
||||
</a>
|
||||
<span class="view-switcher__counter">{author().stat.commented}</span>
|
||||
<Show when={author().stat}>
|
||||
<span class="view-switcher__counter">{author().stat.commented}</span>
|
||||
</Show>
|
||||
</li>
|
||||
<li classList={{ 'view-switcher__item--selected': getPage().route === 'authorAbout' }}>
|
||||
<a
|
||||
|
|
|
@ -36,7 +36,7 @@ import authorBy from '../query/core/author-by'
|
|||
import authorFollowers from '../query/core/author-followers'
|
||||
import authorId from '../query/core/author-id'
|
||||
import authorFollowed from '../query/core/authors-followed-by'
|
||||
import authorsAll from '../query/core/authors-load-all'
|
||||
import authorsAll from '../query/core/authors-all'
|
||||
import authorsLoadBy from '../query/core/authors-load-by'
|
||||
import mySubscriptions from '../query/core/my-followed'
|
||||
import reactionsLoadBy from '../query/core/reactions-load-by'
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
import { gql } from '@urql/core'
|
||||
|
||||
export default gql`
|
||||
query AuthorsAllQuery($limit: Int, $offset: Int) {
|
||||
load_authors_all(limit: $limit, offset: $offset) {
|
||||
id
|
||||
slug
|
||||
name
|
||||
bio
|
||||
pic
|
||||
created_at
|
||||
stat {
|
||||
shouts
|
||||
followers
|
||||
comments: commented
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
|
@ -7,7 +7,7 @@ import { byStat } from '../../utils/sortby'
|
|||
|
||||
export type AuthorsSortBy = 'shouts' | 'name' | 'followers'
|
||||
|
||||
const [sortAllBy, setSortAllBy] = createSignal<AuthorsSortBy>('shouts')
|
||||
const [sortAllBy, setSortAllBy] = createSignal<AuthorsSortBy>('name')
|
||||
|
||||
export const setAuthorsSort = (sortBy: AuthorsSortBy) => setSortAllBy(sortBy)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user