refactor: simplify loaderData usage in dashboard categories and contents pages
This commit is contained in:
@@ -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 = [
|
||||
|
||||
Reference in New Issue
Block a user