offset-limit-fix-3
This commit is contained in:
parent
cb3748a731
commit
5d8be09601
|
@ -19,8 +19,8 @@ import { useTopicsStore } from '../../stores/zine/topics'
|
||||||
interface FeedProps {
|
interface FeedProps {
|
||||||
articles: Shout[]
|
articles: Shout[]
|
||||||
reactions: Reaction[]
|
reactions: Reaction[]
|
||||||
page?: number
|
limit?: number
|
||||||
size?: number
|
offset?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
// const AUTHORSHIP_REACTIONS = [
|
// const AUTHORSHIP_REACTIONS = [
|
||||||
|
@ -54,9 +54,11 @@ export const FeedPage = (props: FeedProps) => {
|
||||||
// return []
|
// return []
|
||||||
// })
|
// })
|
||||||
|
|
||||||
|
// eslint-disable-next-line unicorn/consistent-function-scoping
|
||||||
const loadMore = () => {
|
const loadMore = () => {
|
||||||
const page = (props.page || 1) + 1
|
const limit = props.limit || 50
|
||||||
loadRecentArticles({ page })
|
const offset = props.offset || 0
|
||||||
|
loadRecentArticles({ limit, offset })
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -22,8 +22,8 @@ type HomeProps = {
|
||||||
recentPublishedArticles: Shout[]
|
recentPublishedArticles: Shout[]
|
||||||
topMonthArticles: Shout[]
|
topMonthArticles: Shout[]
|
||||||
topOverallArticles: Shout[]
|
topOverallArticles: Shout[]
|
||||||
page?: number
|
limit?: number
|
||||||
size?: number
|
offset?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
const LAYOUTS = ['article', 'prose', 'music', 'video', 'image']
|
const LAYOUTS = ['article', 'prose', 'music', 'video', 'image']
|
||||||
|
@ -92,8 +92,9 @@ export const HomePage = (props: HomeProps) => {
|
||||||
// }, [byLayout()])
|
// }, [byLayout()])
|
||||||
|
|
||||||
const loadMore = () => {
|
const loadMore = () => {
|
||||||
const page = (props.page || 1) + 1
|
const limit = props.limit || 50
|
||||||
loadPublishedArticles({ page })
|
const offset = props.offset || 0
|
||||||
|
loadPublishedArticles({ limit, offset })
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Suspense fallback={t('Loading')}>
|
<Suspense fallback={t('Loading')}>
|
||||||
|
|
|
@ -3,8 +3,10 @@ import { AuthorPage } from '../../../components/Views/Author'
|
||||||
import Zine from '../../../layouts/zine.astro'
|
import Zine from '../../../layouts/zine.astro'
|
||||||
import { apiClient } from '../../../utils/apiClient'
|
import { apiClient } from '../../../utils/apiClient'
|
||||||
|
|
||||||
|
const limit = parseInt(Astro.params?.limit as string, 10) || 50
|
||||||
|
const offset = parseInt(Astro.params?.offset as string, 10) || 0
|
||||||
const slug = Astro.params.slug.toString()
|
const slug = Astro.params.slug.toString()
|
||||||
const articles = await apiClient.getArticlesForAuthors({ authorSlugs: [slug], offset: 0, limit: 50 })
|
const articles = await apiClient.getArticlesForAuthors({ authorSlugs: [slug], offset, limit })
|
||||||
const author = articles[0].authors.find((a) => a.slug === slug)
|
const author = articles[0].authors.find((a) => a.slug === slug)
|
||||||
|
|
||||||
Astro.response.headers.set('Cache-Control', 's-maxage=1, stale-while-revalidate')
|
Astro.response.headers.set('Cache-Control', 's-maxage=1, stale-while-revalidate')
|
||||||
|
|
|
@ -3,7 +3,9 @@ import { FeedPage } from '../../components/Views/Feed'
|
||||||
import Zine from '../../layouts/zine.astro'
|
import Zine from '../../layouts/zine.astro'
|
||||||
import { apiClient } from '../../utils/apiClient'
|
import { apiClient } from '../../utils/apiClient'
|
||||||
|
|
||||||
const recentArticles = await apiClient.getRecentArticles({ limit: 50, offset: 0 })
|
const limit = parseInt(Astro.params?.limit as string, 10) || 50
|
||||||
|
const offset = parseInt(Astro.params?.offset as string, 10) || 0
|
||||||
|
const recentArticles = await apiClient.getRecentArticles({ limit, offset })
|
||||||
const shoutSlugs = recentArticles.map((s) => s.slug)
|
const shoutSlugs = recentArticles.map((s) => s.slug)
|
||||||
const reactions = await apiClient.getReactionsForShouts({ shoutSlugs })
|
const reactions = await apiClient.getReactionsForShouts({ shoutSlugs })
|
||||||
---
|
---
|
||||||
|
|
|
@ -3,8 +3,10 @@ import { HomePage } from '../components/Views/Home'
|
||||||
import Zine from '../layouts/zine.astro'
|
import Zine from '../layouts/zine.astro'
|
||||||
import { apiClient } from '../utils/apiClient'
|
import { apiClient } from '../utils/apiClient'
|
||||||
|
|
||||||
|
const limit = parseInt(Astro.params?.limit as string, 10) || 50
|
||||||
|
const offset = parseInt(Astro.params?.offset as string, 10) || 0
|
||||||
const randomTopics = await apiClient.getRandomTopics()
|
const randomTopics = await apiClient.getRandomTopics()
|
||||||
const recentPublished = await apiClient.getRecentPublishedArticles({ limit: 50, offset: 0 })
|
const recentPublished = await apiClient.getRecentPublishedArticles({ limit, offset })
|
||||||
const topMonth = await apiClient.getTopMonthArticles()
|
const topMonth = await apiClient.getTopMonthArticles()
|
||||||
const topOverall = await apiClient.getTopArticles()
|
const topOverall = await apiClient.getTopArticles()
|
||||||
|
|
||||||
|
|
|
@ -132,20 +132,40 @@ const addSortedArticles = (articles: Shout[]) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loadRecentArticles = async ({ page }: { page: number }): Promise<void> => {
|
export const loadRecentArticles = async ({
|
||||||
const newArticles = await apiClient.getRecentArticles({ page })
|
limit,
|
||||||
|
offset
|
||||||
|
}: {
|
||||||
|
limit?: number
|
||||||
|
offset?: number
|
||||||
|
}): Promise<void> => {
|
||||||
|
const newArticles = await apiClient.getRecentArticles({ limit, offset })
|
||||||
addArticles(newArticles)
|
addArticles(newArticles)
|
||||||
addSortedArticles(newArticles)
|
addSortedArticles(newArticles)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loadPublishedArticles = async ({ page }: { page: number }): Promise<void> => {
|
export const loadPublishedArticles = async ({
|
||||||
const newArticles = await apiClient.getPublishedArticles({ page })
|
limit,
|
||||||
|
offset
|
||||||
|
}: {
|
||||||
|
limit?: number
|
||||||
|
offset?: number
|
||||||
|
}): Promise<void> => {
|
||||||
|
const newArticles = await apiClient.getPublishedArticles({ limit, offset })
|
||||||
addArticles(newArticles)
|
addArticles(newArticles)
|
||||||
addSortedArticles(newArticles)
|
addSortedArticles(newArticles)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loadSearchResults = async ({ query }: { query: string }): Promise<void> => {
|
export const loadSearchResults = async ({
|
||||||
const newArticles = await apiClient.getSearchResults({ query })
|
query,
|
||||||
|
limit,
|
||||||
|
offset
|
||||||
|
}: {
|
||||||
|
query: string
|
||||||
|
limit?: number
|
||||||
|
offset?: number
|
||||||
|
}): Promise<void> => {
|
||||||
|
const newArticles = await apiClient.getSearchResults({ query, limit, offset })
|
||||||
addArticles(newArticles)
|
addArticles(newArticles)
|
||||||
addSortedArticles(newArticles)
|
addSortedArticles(newArticles)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user