|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import React from 'react'; |
| 4 | +import Image from 'next/image'; |
| 5 | +import Link from 'next/link'; |
| 6 | +import { useRouter } from 'next/navigation'; |
| 7 | +import { graphql } from '@/gql'; |
| 8 | +import { useQuery } from '@tanstack/react-query'; // ✅ Ensure this is correct |
| 9 | + |
| 10 | +import { Button, Divider, Spinner, Text } from 'opub-ui'; |
| 11 | + |
| 12 | +import { GraphQL } from '@/lib/api'; |
| 13 | + |
| 14 | +const sectorDetails = graphql(` |
| 15 | + query SectorsList { |
| 16 | + sectors { |
| 17 | + id |
| 18 | + name |
| 19 | + description |
| 20 | + slug |
| 21 | + datasetCount |
| 22 | + } |
| 23 | + } |
| 24 | +`); |
| 25 | + |
| 26 | +const Sectors = () => { |
| 27 | + const { data, isLoading, error, isError } = useQuery({ |
| 28 | + queryKey: ['sectors_list'], // ✅ Fix queryKey syntax |
| 29 | + queryFn: () => GraphQL(sectorDetails, {}), |
| 30 | + }); |
| 31 | + const router = useRouter(); |
| 32 | + function capitalizeWords(name: any) { |
| 33 | + return name |
| 34 | + .split('-') // Split by '-' |
| 35 | + .map((word: any) => word.charAt(0).toUpperCase() + word.slice(1)) // Capitalize each word |
| 36 | + .join('+'); // Join with '+' |
| 37 | + } |
| 38 | + return ( |
| 39 | + <div className="my-5 p-4 lg:p-16"> |
| 40 | + <div className="flex flex-col gap-2 px-2 "> |
| 41 | + <Text variant="heading3xl">Explore Sectors</Text> |
| 42 | + <div className="flex flex-wrap justify-between gap-2"> |
| 43 | + <Text variant="headingLg" fontWeight="medium"> |
| 44 | + Classification of all Use Cases and Datasets on the Asia-Pacific |
| 45 | + Climate Data Collaborative{' '} |
| 46 | + </Text> |
| 47 | + <Button |
| 48 | + kind="primary" |
| 49 | + className=" bg-secondaryOrange text-basePureBlack" |
| 50 | + onClick={() => { |
| 51 | + router.push('/sectors'); |
| 52 | + }} |
| 53 | + > |
| 54 | + Explore all Sectors |
| 55 | + </Button> |
| 56 | + </div> |
| 57 | + </div> |
| 58 | + {isLoading ? ( |
| 59 | + <div className="m-4 flex justify-center"> |
| 60 | + <Spinner /> |
| 61 | + </div> |
| 62 | + ) : ( |
| 63 | + <div className="mt-10 grid w-full grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-3"> |
| 64 | + {data?.sectors.map((sectors: any) => ( |
| 65 | + <Link |
| 66 | + href={`/sectors/${sectors.slug}?sectors=${capitalizeWords(sectors.slug)}`} |
| 67 | + key={sectors.id} |
| 68 | + > |
| 69 | + <div className="flex w-full items-center gap-5 rounded-4 bg-surfaceDefault p-7 shadow-card"> |
| 70 | + <div className="flex gap-4"> |
| 71 | + <Image |
| 72 | + src={`/Sectors/${sectors.name}.svg`} |
| 73 | + width={80} |
| 74 | + height={80} |
| 75 | + alt={'Sectors Logo'} |
| 76 | + /> |
| 77 | + </div> |
| 78 | + <div className="flex w-full flex-col gap-3"> |
| 79 | + <div className="flex flex-col gap-2"> |
| 80 | + <Text variant="headingLg" fontWeight="semibold"> |
| 81 | + {sectors.name} |
| 82 | + </Text> |
| 83 | + <Divider /> |
| 84 | + </div> |
| 85 | + <div className="flex gap-1"> |
| 86 | + <Text |
| 87 | + variant="bodyMd" |
| 88 | + fontWeight="bold" |
| 89 | + className=" text-primaryBlue" |
| 90 | + > |
| 91 | + {sectors.datasetCount} |
| 92 | + </Text> |
| 93 | + <Text variant="bodyMd">Datasets</Text> |
| 94 | + </div> |
| 95 | + </div> |
| 96 | + </div> |
| 97 | + </Link> |
| 98 | + ))} |
| 99 | + </div> |
| 100 | + )} |
| 101 | + </div> |
| 102 | + ); |
| 103 | +}; |
| 104 | + |
| 105 | +export default Sectors; |
0 commit comments