Inital load sorted articles with layout (#373)

This commit is contained in:
Ilya Y 2024-01-22 14:07:19 +03:00 committed by GitHub
parent df8ee62112
commit f4e787a3ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 2 deletions

View File

@ -41,8 +41,12 @@ export const Expo = (props: Props) => {
const { t } = useLocalize() const { t } = useLocalize()
// const { sortedArticles } = useArticlesStore({
// shouts: isLoaded() ? props.shouts : [],
// })
const { sortedArticles } = useArticlesStore({ const { sortedArticles } = useArticlesStore({
shouts: isLoaded() ? props.shouts : [], shouts: props.shouts || [],
layout: props.layout,
}) })
const getLoadShoutsFilters = (additionalFilters: LoadShoutsFilters = {}): LoadShoutsFilters => { const getLoadShoutsFilters = (additionalFilters: LoadShoutsFilters = {}): LoadShoutsFilters => {

View File

@ -166,6 +166,7 @@ export const resetSortedArticles = () => {
type InitialState = { type InitialState = {
shouts?: Shout[] shouts?: Shout[]
layout?: string
} }
const TOP_MONTH_ARTICLES_COUNT = 10 const TOP_MONTH_ARTICLES_COUNT = 10
@ -203,7 +204,14 @@ export const loadTopArticles = async (): Promise<void> => {
export const useArticlesStore = (initialState: InitialState = {}) => { export const useArticlesStore = (initialState: InitialState = {}) => {
addArticles([...(initialState.shouts || [])]) addArticles([...(initialState.shouts || [])])
if (initialState.shouts) { if (initialState.layout) {
// eslint-disable-next-line promise/catch-or-return
loadShouts({ filters: { layout: initialState.layout }, limit: 10 }).then(({ newShouts }) => {
addArticles(newShouts)
setSortedArticles(newShouts)
})
} else if (initialState.shouts) {
addArticles([...initialState.shouts])
setSortedArticles([...initialState.shouts]) setSortedArticles([...initialState.shouts])
} }