-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c517683
commit d32d4b1
Showing
11 changed files
with
247 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import ContextualLayersPanel from "@/components/panels/contextual-layers"; | ||
import { Button } from "@/components/ui/button"; | ||
import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet"; | ||
import LayersIcon from "@/svgs/layers.svg"; | ||
|
||
const ContextualLayersControls = () => { | ||
return ( | ||
<Sheet> | ||
<SheetTrigger asChild> | ||
<Button type="button" variant="yellow" className="w-8 font-sans xl:w-auto"> | ||
<LayersIcon aria-hidden className="xl:!size-5" /> | ||
<span className="sr-only xl:not-sr-only">Contextual layers</span> | ||
</Button> | ||
</SheetTrigger> | ||
<SheetContent | ||
side="right" | ||
variant="light" | ||
className="bottom-[68px] h-[calc(100%_-_68px)] xl:bottom-0 xl:h-full" | ||
> | ||
<ContextualLayersPanel /> | ||
</SheetContent> | ||
</Sheet> | ||
); | ||
}; | ||
|
||
export default ContextualLayersControls; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
"use client"; | ||
|
||
import { Button, buttonVariants } from "@/components/ui/button"; | ||
import { SheetClose, SheetHeader, SheetTitle } from "@/components/ui/sheet"; | ||
import { Skeleton } from "@/components/ui/skeleton"; | ||
import useDatasetsBySubTopic from "@/hooks/use-datasets-by-sub-topic"; | ||
import XMarkIcon from "@/svgs/xmark.svg"; | ||
|
||
import Item from "./item"; | ||
|
||
const ContextualLayersPanel = () => { | ||
const { data, isLoading } = useDatasetsBySubTopic("contextual"); | ||
|
||
return ( | ||
<> | ||
<SheetHeader className="flex items-center justify-between"> | ||
<SheetTitle | ||
className={buttonVariants({ variant: "yellow", className: "text-base xl:sr-only" })} | ||
> | ||
Contextual layers | ||
</SheetTitle> | ||
<SheetClose asChild> | ||
<Button | ||
type="button" | ||
variant="yellow" | ||
className="w-8 font-sans text-base transition-transform duration-500 ease-out xl:relative xl:w-auto xl:gap-5 xl:pr-10 xl:group-data-[state=open]:-translate-x-12" | ||
> | ||
<XMarkIcon aria-hidden className="!size-5 xl:!size-6" /> | ||
<span className="sr-only">Close</span> | ||
<span aria-hidden className="hidden xl:inline"> | ||
Contextual layers | ||
</span> | ||
</Button> | ||
</SheetClose> | ||
</SheetHeader> | ||
|
||
<p className="mt-11"> | ||
Introduction lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit | ||
amet, consectetu elit. | ||
</p> | ||
|
||
{isLoading && ( | ||
<> | ||
<Skeleton className="mt-6 h-6 w-1/2" /> | ||
<Skeleton className="mt-2 h-6 w-1/3" /> | ||
<Skeleton className="mt-2 h-6 w-2/3" /> | ||
<Skeleton className="mt-6 h-6 w-1/2" /> | ||
<Skeleton className="mt-2 h-6 w-1/3" /> | ||
<Skeleton className="mt-2 h-6 w-2/3" /> | ||
<Skeleton className="mt-6 h-6 w-1/2" /> | ||
<Skeleton className="mt-2 h-6 w-1/3" /> | ||
<Skeleton className="mt-2 h-6 w-2/3" /> | ||
</> | ||
)} | ||
|
||
{!isLoading && data.length === 0 && ( | ||
<div className="py-11 text-center font-semibold">Data not available</div> | ||
)} | ||
|
||
{!isLoading && data.length > 0 && ( | ||
<div className="mt-6 flex flex-col gap-2"> | ||
{data.map(({ subTopic, datasets }) => ( | ||
<Item | ||
key={subTopic} | ||
name={subTopic} | ||
layers={datasets | ||
.filter((dataset) => dataset.layers.length > 0) | ||
.map((dataset) => ({ | ||
// Assuming the dataset has just one layer, which is currently the case | ||
id: dataset.layers[0].id!, | ||
name: dataset.layers[0].attributes!.name!, | ||
}))} | ||
/> | ||
))} | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default ContextualLayersPanel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Dataset, Layer } from "@/types/generated/strapi.schemas"; | ||
|
||
interface ItemProps { | ||
name: Dataset["name"]; | ||
layers: { id: number; name: Layer["name"] }[]; | ||
} | ||
|
||
const Item = ({ name, layers }: ItemProps) => { | ||
return ( | ||
<div> | ||
<div className="border-b border-casper-blue-400/50 py-2 uppercase">{name}</div> | ||
<ul className="py-2"> | ||
{layers.map((layer) => ( | ||
<li key={layer.id} className="py-2"> | ||
<span className="text-xl">{layer.name}</span> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Item; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { cn } from "@/lib/utils"; | ||
|
||
function Skeleton({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) { | ||
return <div className={cn("animate-pulse bg-casper-blue-50", className)} {...props} />; | ||
} | ||
|
||
export { Skeleton }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { useGetDatasets } from "@/types/generated/dataset"; | ||
import { DatasetLayersDataItem } from "@/types/generated/strapi.schemas"; | ||
|
||
type DatasetsBySubTopic = { | ||
subTopic: string; | ||
datasets: { id: number; name: string; layers: DatasetLayersDataItem[] }[]; | ||
}; | ||
|
||
export default function useDatasetsBySubTopic(topicSlug: string, layersFields = ["name"]) { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore-error | ||
const { data, isLoading } = useGetDatasets<DatasetsBySubTopic[]>( | ||
{ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore-error | ||
fields: ["name"], | ||
populate: { | ||
sub_topic: { | ||
fields: ["name"], | ||
}, | ||
layers: { | ||
fields: layersFields, | ||
}, | ||
}, | ||
filters: { | ||
topic: { | ||
slug: { | ||
$eq: topicSlug, | ||
}, | ||
}, | ||
}, | ||
sort: "sub_topic.name", | ||
}, | ||
{ | ||
query: { | ||
placeholderData: { data: [] }, | ||
select: (data) => { | ||
const res: DatasetsBySubTopic[] = []; | ||
|
||
if (!data?.data) { | ||
return res; | ||
} | ||
|
||
let currentIndex = -1; | ||
let currentSubTopic = null; | ||
|
||
for (const item of data.data) { | ||
const subTopic = item.attributes!.sub_topic!.data!.attributes!.name!; | ||
const dataset = item.attributes!.name; | ||
const layers = item.attributes!.layers!.data!; | ||
|
||
if (currentSubTopic === null || currentSubTopic !== subTopic) { | ||
currentSubTopic = subTopic; | ||
currentIndex++; | ||
res[currentIndex] = { subTopic: currentSubTopic, datasets: [] }; | ||
} | ||
|
||
res[currentIndex].datasets.push({ | ||
id: item.id!, | ||
name: dataset, | ||
layers, | ||
}); | ||
} | ||
|
||
return res; | ||
}, | ||
}, | ||
}, | ||
); | ||
|
||
return { data, isLoading }; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.