refactor: simplify loaderData usage in dashboard categories and contents pages
This commit is contained in:
parent
634c809489
commit
5b94c6df91
@ -6,15 +6,12 @@ import type { TCategoryResponse } from '~/apis/common/get-categories'
|
||||
import { Button } from '~/components/ui/button'
|
||||
import { UiTable } from '~/components/ui/table'
|
||||
import { TitleDashboard } from '~/components/ui/title-dashboard'
|
||||
import type { loader } from '~/routes/_admin.lg-admin._dashboard.categories._index'
|
||||
import type { loader } from '~/routes/_admin.lg-admin'
|
||||
export const CategoriesPage = () => {
|
||||
const loaderData = useRouteLoaderData<typeof loader>(
|
||||
'routes/_admin.lg-admin._dashboard.categories._index',
|
||||
)
|
||||
const { dataCategories: categoriesData } = loaderData || {}
|
||||
const loaderData = useRouteLoaderData<typeof loader>('routes/_admin.lg-admin')
|
||||
|
||||
DataTable.use(DT)
|
||||
const dataTable = categoriesData?.sort((a, b) => {
|
||||
const dataTable = loaderData?.categoriesData?.sort((a, b) => {
|
||||
if (a.sequence === null) return 1
|
||||
if (b.sequence === null) return -1
|
||||
return a.sequence - b.sequence
|
||||
|
||||
@ -15,10 +15,9 @@ export const ContentsPage = () => {
|
||||
const loaderData = useRouteLoaderData<typeof loader>(
|
||||
'routes/_admin.lg-admin._dashboard.contents._index',
|
||||
)
|
||||
const { newsData } = loaderData || {}
|
||||
|
||||
DataTable.use(DT)
|
||||
const dataTable = newsData?.sort(
|
||||
const dataTable = loaderData?.newsData?.sort(
|
||||
(a, b) => new Date(b.live_at).getTime() - new Date(a.live_at).getTime(),
|
||||
)
|
||||
const dataColumns = [
|
||||
|
||||
@ -1,16 +1,4 @@
|
||||
import { getCategories } from '~/apis/common/get-categories'
|
||||
import { handleCookie } from '~/libs/cookies'
|
||||
import { CategoriesPage } from '~/pages/dashboard-categories'
|
||||
|
||||
import type { Route } from './+types/_admin.lg-admin._dashboard.categories._index'
|
||||
|
||||
export const loader = async ({ request }: Route.LoaderArgs) => {
|
||||
const { staffToken } = await handleCookie(request)
|
||||
const { data: dataCategories } = await getCategories({
|
||||
accessToken: staffToken,
|
||||
})
|
||||
return { dataCategories }
|
||||
}
|
||||
|
||||
const DashboardCategoriesIndexLayout = () => <CategoriesPage />
|
||||
export default DashboardCategoriesIndexLayout
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user