feat: filter news data to only include items with a live_at date in the past
This commit is contained in:
parent
29baa39a94
commit
fc23f45854
@ -13,19 +13,24 @@ export const loader = async ({}: Route.LoaderArgs) => {
|
|||||||
const spotlightCategory = categoriesData.find(
|
const spotlightCategory = categoriesData.find(
|
||||||
(category) => category.code === spotlightCode,
|
(category) => category.code === spotlightCode,
|
||||||
)
|
)
|
||||||
const { data: spotlightNews } = await getNews({ categories: [spotlightCode] })
|
let { data: spotlightNews } = await getNews({ categories: [spotlightCode] })
|
||||||
|
spotlightNews = spotlightNews.filter(
|
||||||
|
(news) => new Date(news.live_at) <= new Date(),
|
||||||
|
)
|
||||||
|
|
||||||
const beritaCode = 'berita'
|
const beritaCode = 'berita'
|
||||||
const beritaCategory = categoriesData.find(
|
const beritaCategory = categoriesData.find(
|
||||||
(category) => category.code === beritaCode,
|
(category) => category.code === beritaCode,
|
||||||
)
|
)
|
||||||
const { data: beritaNews } = await getNews({ categories: [beritaCode] })
|
let { data: beritaNews } = await getNews({ categories: [beritaCode] })
|
||||||
|
beritaNews = beritaNews.filter((news) => new Date(news.live_at) <= new Date())
|
||||||
|
|
||||||
const kajianCode = 'kajian'
|
const kajianCode = 'kajian'
|
||||||
const kajianCategory = categoriesData.find(
|
const kajianCategory = categoriesData.find(
|
||||||
(category) => category.code === kajianCode,
|
(category) => category.code === kajianCode,
|
||||||
)
|
)
|
||||||
const { data: kajianNews } = await getNews({ categories: [kajianCode] })
|
let { data: kajianNews } = await getNews({ categories: [kajianCode] })
|
||||||
|
kajianNews = kajianNews.filter((news) => new Date(news.live_at) <= new Date())
|
||||||
|
|
||||||
return {
|
return {
|
||||||
spotlightCategory,
|
spotlightCategory,
|
||||||
|
|||||||
@ -11,7 +11,8 @@ export const loader = async ({ params }: Route.LoaderArgs) => {
|
|||||||
const { data: categoriesData } = await getCategories()
|
const { data: categoriesData } = await getCategories()
|
||||||
const { code } = params
|
const { code } = params
|
||||||
const categoryData = categoriesData.find((category) => category.code === code)
|
const categoryData = categoriesData.find((category) => category.code === code)
|
||||||
const { data: newsData } = await getNews({ categories: [code] })
|
let { data: newsData } = await getNews({ categories: [code] })
|
||||||
|
newsData = newsData.filter((news) => new Date(news.live_at) <= new Date())
|
||||||
return { categoryData, newsData }
|
return { categoryData, newsData }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,8 @@ export const loader = async ({ request, params }: Route.LoaderArgs) => {
|
|||||||
const beritaCategory = categoriesData.find(
|
const beritaCategory = categoriesData.find(
|
||||||
(category) => category.code === beritaCode,
|
(category) => category.code === beritaCode,
|
||||||
)
|
)
|
||||||
const { data: beritaNews } = await getNews({ categories: [beritaCode] })
|
let { data: beritaNews } = await getNews({ categories: [beritaCode] })
|
||||||
|
beritaNews = beritaNews.filter((news) => new Date(news.live_at) <= new Date())
|
||||||
|
|
||||||
return {
|
return {
|
||||||
newsDetailData,
|
newsDetailData,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user