|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { graphql } from '@/gql'; |
| 4 | +import { useQuery } from '@tanstack/react-query'; |
| 5 | +import Image from 'next/image'; |
| 6 | +import Link from 'next/link'; |
| 7 | +import { Text } from 'opub-ui'; |
| 8 | + |
| 9 | +import BreadCrumbs from '@/components/BreadCrumbs'; |
| 10 | +import { Loading } from '@/components/loading'; |
| 11 | +import { GraphQL } from '@/lib/api'; |
| 12 | + |
| 13 | +const categoriesListQueryDoc: any = graphql(` |
| 14 | + query CategoriesList { |
| 15 | + categories { |
| 16 | + id |
| 17 | + name |
| 18 | + description |
| 19 | + slug |
| 20 | + datasetCount |
| 21 | + } |
| 22 | + } |
| 23 | +`); |
| 24 | + |
| 25 | +const CategoriesListingPage = () => { |
| 26 | + const getCategoriesList: { |
| 27 | + data: any; |
| 28 | + isLoading: boolean; |
| 29 | + error: any; |
| 30 | + isError: boolean; |
| 31 | + } = useQuery([`categories_list_page`], () => |
| 32 | + GraphQL(categoriesListQueryDoc, []) |
| 33 | + ); |
| 34 | + |
| 35 | + return ( |
| 36 | + <main className="bg-baseGraySlateSolid2"> |
| 37 | + <BreadCrumbs |
| 38 | + data={[ |
| 39 | + { href: '/', label: 'Home' }, |
| 40 | + { href: '#', label: 'Categories' }, |
| 41 | + ]} |
| 42 | + /> |
| 43 | + <> |
| 44 | + {getCategoriesList.isLoading ? ( |
| 45 | + <Loading /> |
| 46 | + ) : getCategoriesList.data?.categories.length > 0 ? ( |
| 47 | + <> |
| 48 | + <div className="flex h-screen w-full flex-col gap-2 px-28 pt-10"> |
| 49 | + <Text variant="heading3xl" as="h1"> |
| 50 | + Categories |
| 51 | + </Text> |
| 52 | + <div className="flex flex-wrap justify-between pt-8"> |
| 53 | + {getCategoriesList.data?.categories.map((category: any) => ( |
| 54 | + <Link href={`/categories/${category.slug}`} key={category.id}> |
| 55 | + <div className="md::w-72 mb-7 flex flex-row items-center gap-3 rounded-2 border-borderDefault bg-basePureWhite p-3 shadow-basicLg sm:w-72 lg:w-72 xl:w-72"> |
| 56 | + <div className="flex items-center justify-center rounded-1 bg-baseGraySlateSolid2 p-2"> |
| 57 | + <Image |
| 58 | + src={'/obi.jpg'} |
| 59 | + width={40} |
| 60 | + height={40} |
| 61 | + alt={'Category Logo'} |
| 62 | + /> |
| 63 | + </div> |
| 64 | + <div className="flex flex-col gap-1"> |
| 65 | + <Text variant="bodyMd" fontWeight="semibold"> |
| 66 | + {category.name} |
| 67 | + </Text> |
| 68 | + <Text>{category.datasetCount} Dataset(s)</Text> |
| 69 | + </div> |
| 70 | + </div> |
| 71 | + </Link> |
| 72 | + ))} |
| 73 | + </div> |
| 74 | + </div> |
| 75 | + </> |
| 76 | + ) : getCategoriesList.isError ? ( |
| 77 | + <div className="text font-Medium flex h-[680px] w-full flex-col items-center justify-center gap-4 text-600"> |
| 78 | + Error fetching data. Please try again later. |
| 79 | + </div> |
| 80 | + ) : ( |
| 81 | + <></> |
| 82 | + )} |
| 83 | + </> |
| 84 | + </main> |
| 85 | + ); |
| 86 | +}; |
| 87 | + |
| 88 | +export default CategoriesListingPage; |
0 commit comments