'use client'
import Link from 'next/link'
import { useGetBannersQuery, useGetCategoriesQuery } from '@/store/services'
import { useTitle, useUrlQuery } from '@/hooks'
import { ResponsiveImage, EmptyCustomList, PageContainer, TableSkeleton } from '@/components'
const BannersPage = () => {
const query = useUrlQuery()
const category_id = query?.category_id
const category_name = query?.category_name
//? Get Categories
const { categories, isLoading: isLodingGetCategories } = useGetCategoriesQuery(undefined, {
selectFromResult: ({ data, isLoading }) => ({
categories: data?.data?.categories
.filter(category => category.level < 2)
.sort((a, b) => a.level - b.level),
isLoading,
}),
skip: !!category_id,
})
const { data: banners, isLoading: isLoading_get_banners } = useGetBannersQuery(
{ category: category_id },
{
skip: !!!category_id,
}
)
//? Render(s)
const title = category_name ? `banner管理 - ${category_name}` : 'banner管理'
useTitle(title)
const renderContent = () => {
if (isLoading_get_banners || isLodingGetCategories) {
return (
|
)
}
if (categories && !category_id) {
return categories.map(category => (
{category.name} |
子集
|
))
}
if (banners?.data && banners?.data?.length > 0) {
return banners?.data.map(banner => (
|
{banner.title} |
{banner.type} |
编辑
|
))
} else
return (
|
)
}
return (
{category_id && (
添加新banner
)}
{category_name && 图片 | }
{category_name ? 'banner标题' : '分类名称'}
|
{category_name && 类型 | }
操作 |
{renderContent()}
)
}
export default BannersPage