refactor: enhance news handling and improve content display in various components

This commit is contained in:
Ardeman
2025-03-09 11:36:47 +08:00
parent bad5294030
commit 4847ef2be3
11 changed files with 161 additions and 26 deletions
@@ -1,14 +1,10 @@
import { getNews } from '~/apis/common/get-news'
import { handleCookie } from '~/libs/cookies'
import { ContentsPage } from '~/pages/dashboard-contents'
import type { Route } from './+types/_admin.lg-admin._dashboard.contents._index'
export const loader = async ({ request }: Route.LoaderArgs) => {
const { staffToken } = await handleCookie(request)
const { data: newsData } = await getNews({
accessToken: staffToken,
})
export const loader = async ({}: Route.LoaderArgs) => {
const { data: newsData } = await getNews()
return { newsData }
}
+16 -1
View File
@@ -1,4 +1,6 @@
import { getCategories } from '~/apis/common/get-categories'
import { getNews } from '~/apis/common/get-news'
import { APP } from '~/configs/meta'
import { NewsCategoriesPage } from '~/pages/news-categories'
import type { Route } from './+types/_news.category.$code'
@@ -8,7 +10,20 @@ export const loader = async ({ params }: Route.LoaderArgs) => {
const categoryData = categoriesData.find(
(category) => category.code === params.code,
)
return { categoryData }
const { data: newsData } = await getNews({ categories: [params.code] })
return { categoryData, newsData }
}
export const meta = ({ data }: Route.MetaArgs) => {
const { categoryData } = data
const metaTitle = APP.title
const title = `${categoryData?.name} - ${metaTitle}`
return [
{
title,
},
]
}
const NewsCategoriesLayout = () => <NewsCategoriesPage />