Inital load sorted articles with layout (#373)
This commit is contained in:
parent
df8ee62112
commit
f4e787a3ce
|
@ -41,8 +41,12 @@ export const Expo = (props: Props) => {
|
|||
|
||||
const { t } = useLocalize()
|
||||
|
||||
// const { sortedArticles } = useArticlesStore({
|
||||
// shouts: isLoaded() ? props.shouts : [],
|
||||
// })
|
||||
const { sortedArticles } = useArticlesStore({
|
||||
shouts: isLoaded() ? props.shouts : [],
|
||||
shouts: props.shouts || [],
|
||||
layout: props.layout,
|
||||
})
|
||||
|
||||
const getLoadShoutsFilters = (additionalFilters: LoadShoutsFilters = {}): LoadShoutsFilters => {
|
||||
|
|
|
@ -166,6 +166,7 @@ export const resetSortedArticles = () => {
|
|||
|
||||
type InitialState = {
|
||||
shouts?: Shout[]
|
||||
layout?: string
|
||||
}
|
||||
|
||||
const TOP_MONTH_ARTICLES_COUNT = 10
|
||||
|
@ -203,7 +204,14 @@ export const loadTopArticles = async (): Promise<void> => {
|
|||
export const useArticlesStore = (initialState: InitialState = {}) => {
|
||||
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])
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user