Skip to content

Commit

Permalink
Merge pull request #312 from Vizzuality/SKY30-462-fe-remove-the-locat…
Browse files Browse the repository at this point in the history
…ion-search-and-url-parameter-from-the-conservation-builder

Remove location-related code from the Conservation Builder
  • Loading branch information
clementprdhomme authored Oct 9, 2024
2 parents b1638c3 + 3b116ef commit 5d99474
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { useCallback, useEffect, useMemo, useRef } from 'react';

import { useRouter } from 'next/router';

import { useAtomValue } from 'jotai';
import { useTranslations } from 'next-intl';

import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { PAGES } from '@/constants/pages';
import { useMapSearchParams } from '@/containers/map/content/map/sync-settings';
import { modellingAtom } from '@/containers/map/store';
import { useSyncMapContentSettings } from '@/containers/map/sync-settings';
import useScrollPosition from '@/hooks/use-scroll-position';
Expand All @@ -26,20 +22,11 @@ const SidebarModelling: FCWithMessages = () => {
const containerRef = useRef<HTMLDivElement | null>(null);
const containerScroll = useScrollPosition(containerRef);

const { push } = useRouter();
const searchParams = useMapSearchParams();
const { status: modellingStatus } = useAtomValue(modellingAtom);
const [{ tab }, setSettings] = useSyncMapContentSettings();

const showIntro = useMemo(() => modellingStatus === 'idle', [modellingStatus]);

const handleLocationSelected = useCallback(
(locationCode) => {
push(`${PAGES.conservationBuilder}/${locationCode}?${searchParams.toString()}`);
},
[push, searchParams]
);

const handleTabChange = useCallback(
(tab: string) => setSettings((prevSettings) => ({ ...prevSettings, tab })),
[setSettings]
Expand All @@ -62,13 +49,7 @@ const SidebarModelling: FCWithMessages = () => {
return (
<Tabs value={tab} onValueChange={handleTabChange} className="flex h-full w-full flex-col">
<div className="flex flex-shrink-0 flex-col gap-y-2 border-b border-black bg-blue-600 px-4 pt-4 md:px-8 md:pt-6">
<div
className={cn({
'flex gap-y-2 gap-x-5': true,
'flex-col': containerScroll === 0,
'flex-row': containerScroll > 0,
})}
>
<div>
<h1
className={cn({
'text-ellipsis font-black transition-all': true,
Expand All @@ -78,12 +59,6 @@ const SidebarModelling: FCWithMessages = () => {
>
{showIntro ? t('conservation-scenarios') : t('custom-area')}
</h1>
<LocationSelector
className="flex-shrink-0"
theme="blue"
size={containerScroll > 0 ? 'small' : 'default'}
onChange={handleLocationSelected}
/>
</div>
{!showIntro && <p className="mt-2 font-black">{t('custom-area-description')}</p>}
<TabsList className="relative top-px mt-5">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@ import MapLayout from '@/layouts/map';
import { fetchTranslations } from '@/lib/i18n';
import mapParamsToSearchParams from '@/lib/mapparams-to-searchparams';
import { FCWithMessages } from '@/types';
import { getGetLocationsQueryKey, getGetLocationsQueryOptions } from '@/types/generated/location';
import { LocationListResponse } from '@/types/generated/strapi.schemas';

import { LayoutProps } from '../_app';

const ConservationBuilderPage: FCWithMessages & {
layout: LayoutProps<
{ location: { code: string; name: string } },
ComponentProps<typeof MapLayout>
>;
layout: LayoutProps<Record<string, never>, ComponentProps<typeof MapLayout>>;
} = () => {
return null;
};
Expand All @@ -34,11 +29,11 @@ ConservationBuilderPage.messages = ['pages.conservation-builder', ...MapLayout.m

export const getServerSideProps: GetServerSideProps = async (context) => {
const { query } = context;
const { locationCode = 'GLOB', location, mapParams = null } = query;
const { mapParams = null } = query;

if (mapParams) {
const searchParams = mapParamsToSearchParams(mapParams);
const target = `/${context.locale}/${PAGES.conservationBuilder}/${location}?${searchParams}`;
const target = `/${context.locale}/${PAGES.conservationBuilder}/?${searchParams}`;

return {
redirect: {
Expand All @@ -50,32 +45,8 @@ export const getServerSideProps: GetServerSideProps = async (context) => {

const queryClient = new QueryClient();

await queryClient.prefetchQuery({
...getGetLocationsQueryOptions({
locale: context.locale,
filters: {
code: locationCode,
},
}),
});

const locationsData = queryClient.getQueryData<LocationListResponse>(
getGetLocationsQueryKey({
locale: context.locale,
filters: {
code: locationCode,
},
})
);

if (!locationsData || !locationsData.data) return { notFound: true };

return {
props: {
location: locationsData.data[0].attributes || {
code: 'GLOB',
name: 'Global',
},
dehydratedState: dehydrate(queryClient),
messages: await fetchTranslations(context.locale, ConservationBuilderPage.messages),
},
Expand Down

0 comments on commit 5d99474

Please sign in to comment.