Skip to content

Commit

Permalink
feat(client): Add download link for Contextual layers
Browse files Browse the repository at this point in the history
  • Loading branch information
clementprdhomme committed Nov 8, 2024
1 parent 0989a06 commit 1fad138
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion client/src/components/panels/contextual-layers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import XMarkIcon from "@/svgs/xmark.svg";
import Item from "./item";

const ContextualLayersPanel = () => {
const { data, isLoading } = useDatasetsBySubTopic("contextual");
const { data, isLoading } = useDatasetsBySubTopic("contextual", ["layer", "download_link"]);

return (
<>
Expand Down Expand Up @@ -71,6 +71,7 @@ const ContextualLayersPanel = () => {
// Assuming the dataset has just one layer, which is currently the case
id: dataset.layers[0].id!,
name: dataset.layers[0].attributes!.name!,
downloadLink: dataset.layers[0].attributes!.download_link,
}))}
/>
))}
Expand Down
32 changes: 30 additions & 2 deletions client/src/components/panels/contextual-layers/item.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import Link from "next/link";

import { Button } from "@/components/ui/button";
import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";
import useMapLayers from "@/hooks/use-map-layers";
import { cn } from "@/lib/utils";
import DownloadIcon from "@/svgs/download.svg";
import { Dataset, Layer } from "@/types/generated/strapi.schemas";

interface ItemProps {
name: Dataset["name"];
layers: { id: number; name: Layer["name"] }[];
layers: { id: number; name: Layer["name"]; downloadLink?: Layer["download_link"] }[];
}

const Item = ({ name, layers }: ItemProps) => {
Expand All @@ -20,7 +25,30 @@ const Item = ({ name, layers }: ItemProps) => {
<Label htmlFor={`${layer.id}-toggle`} className="text-xl">
{layer.name}
</Label>
<div className="pt-1">
<div className="flex items-center gap-0.5 pt-1">
<Button
variant="ghost"
size="icon-sm"
className={cn({
"group/download": true,
"pointer-events-none opacity-20": !layer.downloadLink,
})}
aria-disabled={!layer.downloadLink}
tabIndex={!layer.downloadLink ? -1 : undefined}
asChild
>
<Link
href={layer.downloadLink ?? ""}
rel="noopener noreferrer"
download={layer.name}
>
<span className="sr-only">Download</span>
<DownloadIcon
className="!size-4 transition-colors group-hover/download:text-casper-blue-300"
aria-hidden
/>
</Link>
</Button>
<Switch
id={`${layer.id}-toggle`}
checked={layersConfiguration.findIndex(({ id }) => id === layer.id) !== -1}
Expand Down
4 changes: 4 additions & 0 deletions client/src/svgs/download.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1fad138

Please sign in to comment.