|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { useRouter } from 'next/navigation'; |
| 4 | +import { graphql } from '@/gql'; |
| 5 | +import { useQuery } from '@tanstack/react-query'; |
| 6 | +import { |
| 7 | + Button, |
| 8 | + Card, |
| 9 | + Carousel, |
| 10 | + CarouselContent, |
| 11 | + CarouselItem, |
| 12 | + CarouselNext, |
| 13 | + CarouselPrevious, |
| 14 | + Spinner, |
| 15 | + Text, |
| 16 | +} from 'opub-ui'; |
| 17 | + |
| 18 | +import { GraphQL } from '@/lib/api'; |
| 19 | +import { cn, formatDate } from '@/lib/utils'; |
| 20 | +import { Icons } from '@/components/icons'; |
| 21 | +import Styles from './datasets.module.scss'; |
| 22 | + |
| 23 | +const useCasesListDoc: any = graphql(` |
| 24 | + query TopUseCases( |
| 25 | + $filters: UseCaseFilter |
| 26 | + $pagination: OffsetPaginationInput |
| 27 | + ) { |
| 28 | + useCases(filters: $filters, pagination: $pagination) { |
| 29 | + id |
| 30 | + title |
| 31 | + summary |
| 32 | + slug |
| 33 | + datasetCount |
| 34 | + logo { |
| 35 | + path |
| 36 | + } |
| 37 | + metadata { |
| 38 | + metadataItem { |
| 39 | + id |
| 40 | + label |
| 41 | + dataType |
| 42 | + } |
| 43 | + id |
| 44 | + value |
| 45 | + } |
| 46 | + publishers { |
| 47 | + logo { |
| 48 | + path |
| 49 | + } |
| 50 | + name |
| 51 | + } |
| 52 | + sectors { |
| 53 | + id |
| 54 | + name |
| 55 | + } |
| 56 | + created |
| 57 | + modified |
| 58 | + website |
| 59 | + contactEmail |
| 60 | + } |
| 61 | + } |
| 62 | +`); |
| 63 | + |
| 64 | +const UseCasesListingPage = () => { |
| 65 | + const getUseCasesList: { |
| 66 | + data: any; |
| 67 | + isLoading: boolean; |
| 68 | + error: any; |
| 69 | + isError: boolean; |
| 70 | + } = useQuery([`useCases_list`], () => |
| 71 | + GraphQL( |
| 72 | + useCasesListDoc, |
| 73 | + {}, |
| 74 | + { |
| 75 | + filters: { status: 'PUBLISHED' }, |
| 76 | + pagination: { limit: 6 }, |
| 77 | + } |
| 78 | + ) |
| 79 | + ); |
| 80 | + const router = useRouter(); |
| 81 | + |
| 82 | + return ( |
| 83 | + <div className=" container pt-10 md:px-8 lg:pt-20"> |
| 84 | + <div className="flex flex-col gap-2 md:px-12 px-4 lg:px-12 "> |
| 85 | + <Text variant="heading3xl">Recent UseCases</Text> |
| 86 | + <div className="flex flex-wrap justify-between gap-2 "> |
| 87 | + <Text variant="headingLg" fontWeight="medium"> |
| 88 | + Recently updated and trending Use Cases on Asia-Pacific Climate Data |
| 89 | + Collaborative{' '} |
| 90 | + </Text> |
| 91 | + <Button |
| 92 | + kind="primary" |
| 93 | + className=" bg-secondaryOrange text-basePureBlack" |
| 94 | + onClick={() => { |
| 95 | + router.push('/usecases'); |
| 96 | + }} |
| 97 | + > |
| 98 | + Explore all Use Cases |
| 99 | + </Button> |
| 100 | + </div> |
| 101 | + </div> |
| 102 | + <div className='mt-12'> |
| 103 | + <Carousel className="flex w-full justify-between"> |
| 104 | + <CarouselPrevious /> |
| 105 | + |
| 106 | + {getUseCasesList.isLoading ? ( |
| 107 | + <div className="p-8"> |
| 108 | + <Spinner /> |
| 109 | + </div> |
| 110 | + ) : ( |
| 111 | + <CarouselContent className="p-4 "> |
| 112 | + {getUseCasesList && |
| 113 | + getUseCasesList?.data?.useCases.length > 0 && |
| 114 | + getUseCasesList?.data?.useCases.map((item: any, index: any) => ( |
| 115 | + <CarouselItem |
| 116 | + key={item.id} |
| 117 | + className={cn( |
| 118 | + 'h-2/4 basis-full pl-4 sm:basis-1/2 lg:basis-1/3', |
| 119 | + Styles.UseCaseList |
| 120 | + )} |
| 121 | + > |
| 122 | + <Card |
| 123 | + title={item.title} |
| 124 | + key={index} |
| 125 | + href={`/usecases/${item.id}`} |
| 126 | + metadataContent={[ |
| 127 | + { |
| 128 | + icon: Icons.calendar, |
| 129 | + label: 'Date', |
| 130 | + value: formatDate(item.modified), |
| 131 | + }, |
| 132 | + { |
| 133 | + icon: Icons.globe, |
| 134 | + label: 'Geography', |
| 135 | + value: item.metadata?.find( |
| 136 | + (meta: any) => |
| 137 | + meta.metadataItem?.label === 'Geography' |
| 138 | + )?.value, |
| 139 | + }, |
| 140 | + ]} |
| 141 | + footerContent={[ |
| 142 | + { |
| 143 | + icon: `/Sectors/${item?.sectors[0]?.name}.svg`, |
| 144 | + label: 'Sectors', |
| 145 | + }, |
| 146 | + { icon: '/fallback.svg', label: 'Published by' }, |
| 147 | + ]} |
| 148 | + imageUrl={`${process.env.NEXT_PUBLIC_BACKEND_URL}/${item.logo?.path.replace('/code/files/', '')}`} |
| 149 | + description={item.summary} |
| 150 | + iconColor="warning" |
| 151 | + variation={'collapsed'} |
| 152 | + /> |
| 153 | + </CarouselItem> |
| 154 | + ))} |
| 155 | + </CarouselContent> |
| 156 | + )} |
| 157 | + <CarouselNext /> |
| 158 | + </Carousel> |
| 159 | + </div> |
| 160 | + </div> |
| 161 | + ); |
| 162 | +}; |
| 163 | + |
| 164 | +export default UseCasesListingPage; |
0 commit comments