Skip to content

Commit

Permalink
country boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
mluena committed May 3, 2024
1 parent 4fc3497 commit 02a3c06
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
24 changes: 19 additions & 5 deletions client/src/containers/countries/item.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
'use client';

import { useCallback } from 'react';

import Flag from 'react-world-flags';

import Link from 'next/link';
import { useRouter } from 'next/navigation';

import { useSetAtom } from 'jotai';

import { tmpBboxAtom } from '@/store';

import { useGetCountryIndicatorFields } from '@/types/generated/country-indicator-field';
import { CountryListResponseDataItem } from '@/types/generated/strapi.schemas';
import type { Bbox } from '@/types/map';

import { useSyncQueryParams } from '@/hooks/datasets';

export default function CountryItem({ data }: { data: CountryListResponseDataItem }) {
const setTempBbox = useSetAtom(tmpBboxAtom);

const queryParams = useSyncQueryParams();
const { push } = useRouter();

const { data: projectsCountIndicator } = useGetCountryIndicatorFields(
{
Expand All @@ -27,10 +36,15 @@ export default function CountryItem({ data }: { data: CountryListResponseDataIte
}
);

const handleClick = useCallback(() => {
push(`/countries/${data.id}${queryParams}`);
setTempBbox(data.attributes?.bbox as Bbox);
}, [data, push, queryParams, setTempBbox]);

return (
<Link
href={`/countries/${data.id}${queryParams}`}
<button
data-cy="country-item-link"
onClick={handleClick}
className="flex items-center justify-between space-x-4 rounded-lg border border-gray-100 bg-white py-2 pl-2 pr-4 text-sm text-yellow-900 no-underline shadow-sm transition-all duration-300 hover:border-yellow-500"
>
<div className="flex items-center space-x-4">
Expand All @@ -49,6 +63,6 @@ export default function CountryItem({ data }: { data: CountryListResponseDataIte
{projectsCountIndicator?.attributes?.value === 1 ? 'project' : 'projects'}
</p>
)}
</Link>
</button>
);
}
1 change: 1 addition & 0 deletions client/src/types/generated/strapi.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4425,6 +4425,7 @@ export interface Country {
publishedAt?: string;
createdBy?: CountryCreatedBy;
updatedBy?: CountryUpdatedBy;
bbox: Bbox;
}

export interface CountryResponseDataObject {
Expand Down

0 comments on commit 02a3c06

Please sign in to comment.