get-authors-all-fix
Some checks failed
deploy / test (push) Successful in 1m6s
deploy / deploy (push) Failing after 27s

This commit is contained in:
Untone 2023-12-24 20:29:16 +03:00
parent a383283cd2
commit aca1358c18
5 changed files with 34 additions and 37 deletions

View File

@ -34,7 +34,7 @@ export const AllAuthorsView = (props: Props) => {
const { searchParams, changeSearchParams } = useRouter<AllAuthorsPageSearchParams>() const { searchParams, changeSearchParams } = useRouter<AllAuthorsPageSearchParams>()
const { sortedAuthors } = useAuthorsStore({ const { sortedAuthors } = useAuthorsStore({
authors: props.authors, authors: props.authors,
sortBy: searchParams().by || 'shouts', sortBy: searchParams().by || 'name',
}) })
const [searchQuery, setSearchQuery] = createSignal('') const [searchQuery, setSearchQuery] = createSignal('')
@ -42,13 +42,13 @@ export const AllAuthorsView = (props: Props) => {
createEffect(() => { createEffect(() => {
if (!searchParams().by) { if (!searchParams().by) {
changeSearchParams({ changeSearchParams({
by: 'shouts', by: 'name',
}) })
} }
}) })
createEffect(() => { createEffect(() => {
setAuthorsSort(searchParams().by || 'shouts') setAuthorsSort(searchParams().by || 'name')
}) })
const byLetter = createMemo<{ [letter: string]: Author[] }>(() => { 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={clsx(styles.topic, 'topic col-sm-12 col-md-8')}>
<div class="topic-title"> <div class="topic-title">
<a href={`/author/${author.slug}`}>{author.name}</a> <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>
</div> </div>
)} )}

View File

@ -40,13 +40,19 @@ export const AuthorView = (props: Props) => {
const { authorEntities } = useAuthorsStore({ authors: [props.author] }) const { authorEntities } = useAuthorsStore({ authors: [props.author] })
const { page: getPage } = useRouter() const { page: getPage } = useRouter()
const author = createMemo(() => authorEntities()[props.authorSlug])
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 [followers, setFollowers] = 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 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 bioContainerRef: { current: HTMLDivElement } = { current: null }
const bioWrapperRef: { current: HTMLDivElement } = { current: null } const bioWrapperRef: { current: HTMLDivElement } = { current: null }
const fetchSubscriptions = async (): Promise<{ authors: Author[]; topics: Topic[] }> => { const fetchSubscriptions = async (): Promise<{ authors: Author[]; topics: Topic[] }> => {
@ -71,20 +77,24 @@ export const AuthorView = (props: Props) => {
} }
onMount(async () => { onMount(async () => {
try {
const userSubscribers = await apiClient.getAuthorFollowers({ slug: props.authorSlug })
setFollowers(userSubscribers)
} catch (error) {
console.error('[getAuthorFollowers]', error)
}
checkBioHeight() checkBioHeight()
// pagination
if (sortedArticles().length === PRERENDERED_ARTICLES_COUNT) { if (sortedArticles().length === PRERENDERED_ARTICLES_COUNT) {
await loadMore() 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(() => { createEffect(() => {
@ -160,13 +170,17 @@ export const AuthorView = (props: Props) => {
<a href={getPagePath(router, 'author', { slug: props.authorSlug })}> <a href={getPagePath(router, 'author', { slug: props.authorSlug })}>
{t('Publications')} {t('Publications')}
</a> </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>
<li classList={{ 'view-switcher__item--selected': getPage().route === 'authorComments' }}> <li classList={{ 'view-switcher__item--selected': getPage().route === 'authorComments' }}>
<a href={getPagePath(router, 'authorComments', { slug: props.authorSlug })}> <a href={getPagePath(router, 'authorComments', { slug: props.authorSlug })}>
{t('Comments')} {t('Comments')}
</a> </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>
<li classList={{ 'view-switcher__item--selected': getPage().route === 'authorAbout' }}> <li classList={{ 'view-switcher__item--selected': getPage().route === 'authorAbout' }}>
<a <a

View File

@ -36,7 +36,7 @@ import authorBy from '../query/core/author-by'
import authorFollowers from '../query/core/author-followers' import authorFollowers from '../query/core/author-followers'
import authorId from '../query/core/author-id' import authorId from '../query/core/author-id'
import authorFollowed from '../query/core/authors-followed-by' 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 authorsLoadBy from '../query/core/authors-load-by'
import mySubscriptions from '../query/core/my-followed' import mySubscriptions from '../query/core/my-followed'
import reactionsLoadBy from '../query/core/reactions-load-by' import reactionsLoadBy from '../query/core/reactions-load-by'

View File

@ -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
}
}
}
`

View File

@ -7,7 +7,7 @@ import { byStat } from '../../utils/sortby'
export type AuthorsSortBy = 'shouts' | 'name' | 'followers' 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) export const setAuthorsSort = (sortBy: AuthorsSortBy) => setSortAllBy(sortBy)