prepare-all-authors

This commit is contained in:
Untone 2023-12-23 10:45:37 +03:00
parent 0adeba1407
commit 62887f88c0
5 changed files with 21 additions and 13 deletions

View File

@ -1,6 +1,3 @@
import { createMemo, createSignal, For, onMount, Show } from 'solid-js'
import { useLocalize } from '../../context/localize'
import { Shout, Topic } from '../../graphql/schema/core.gen'
import { getPagePath } from '@nanostores/router'
import { batch, createMemo, createSignal, For, onMount, Show } from 'solid-js'
@ -15,7 +12,6 @@ import {
} from '../../stores/zine/articles'
import { useTopAuthorsStore } from '../../stores/zine/topAuthors'
import { useTopicsStore } from '../../stores/zine/topics'
import { apiClient } from '../../utils/apiClient'
import { restoreScrollPosition, saveScrollPosition } from '../../utils/scroll'
import { splitToPages } from '../../utils/splitToPages'
import { Icon } from '../_shared/Icon'
@ -32,6 +28,7 @@ import RowShort from '../Feed/RowShort'
import { Topics } from '../Nav/Topics'
import styles from './Home.module.scss'
import { apiClient } from '../../graphql/client/core'
type Props = {
shouts: Shout[]

View File

@ -43,6 +43,7 @@ import topicBySlug from '../query/core/topic-by-slug'
import topicsAll from '../query/core/topics-all'
import userFollowedTopics from '../query/core/topics-by-author'
import topicsRandomQuery from '../query/core/topics-random'
import articlesLoadRandomTopic from '../query/core/articles-load-random-topic'
const publicGraphQLClient = createGraphQLClient('core')
@ -78,6 +79,16 @@ export const apiClient = {
return response.data.get_topics_random
},
getRandomTopicShouts: async (limit: number): Promise<{ topic: Topic; shouts: Shout[] }> => {
const resp = await publicGraphQLClient.query(articlesLoadRandomTopic, { limit }).toPromise()
if (resp.error) {
console.error(resp)
}
return resp.data.load_random_topics_shouts
},
follow: async ({ what, slug }: { what: FollowingEntity; slug: string }) => {
const response = await apiClient.private.mutation(followMutation, { what, slug }).toPromise()
return response.data.follow

View File

@ -2,7 +2,7 @@ import { gql } from '@urql/core'
export default gql`
query LoadRandomTopicShoutsQuery($limit: Int!) {
loadRandomTopicShouts(limit: $limit) {
load_shouts_random_topic(limit: $limit) {
topic {
id
title
@ -28,7 +28,7 @@ export default gql`
cover
lead
# community
mainTopic
main_topic
topics {
id
title
@ -44,12 +44,12 @@ export default gql`
id
name
slug
userpic
createdAt
pic
created_at
bio
}
createdAt
publishedAt
created_at
published_at
stat {
viewed
reacted

View File

@ -17,7 +17,7 @@ export const AllAuthorsPage = (props: PageProps) => {
return
}
await loadAllAuthors()
await loadAllAuthors() // default limit, offset: 60, 0
setIsLoaded(true)
})

View File

@ -83,8 +83,8 @@ export const addAuthorsByTopic = (newAuthorsByTopic: { [topicSlug: string]: Auth
})
}
export const loadAllAuthors = async (): Promise<void> => {
const authors = await apiClient.getAllAuthors()
export const loadAllAuthors = async (limit: number = 50, offset = 0): Promise<void> => {
const authors = await apiClient.getAllAuthors(limit, offset)
addAuthors(authors)
}