From 3b116efc313ce735b42f63d86da5e93c219cfe66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Prod=27homme?= Date: Tue, 8 Oct 2024 10:20:10 +0200 Subject: [PATCH] Remove the location input and URL param --- .../main-panel/panels/modelling/index.tsx | 27 +------------- .../{[locationCode].tsx => index.tsx} | 35 ++----------------- 2 files changed, 4 insertions(+), 58 deletions(-) rename frontend/src/pages/conservation-builder/{[locationCode].tsx => index.tsx} (58%) diff --git a/frontend/src/containers/map/sidebar/main-panel/panels/modelling/index.tsx b/frontend/src/containers/map/sidebar/main-panel/panels/modelling/index.tsx index b1cbba8f..207d84e1 100644 --- a/frontend/src/containers/map/sidebar/main-panel/panels/modelling/index.tsx +++ b/frontend/src/containers/map/sidebar/main-panel/panels/modelling/index.tsx @@ -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'; @@ -26,20 +22,11 @@ const SidebarModelling: FCWithMessages = () => { const containerRef = useRef(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] @@ -62,13 +49,7 @@ const SidebarModelling: FCWithMessages = () => { return (
-
0, - })} - > +

{ > {showIntro ? t('conservation-scenarios') : t('custom-area')}

- 0 ? 'small' : 'default'} - onChange={handleLocationSelected} - />
{!showIntro &&

{t('custom-area-description')}

} diff --git a/frontend/src/pages/conservation-builder/[locationCode].tsx b/frontend/src/pages/conservation-builder/index.tsx similarity index 58% rename from frontend/src/pages/conservation-builder/[locationCode].tsx rename to frontend/src/pages/conservation-builder/index.tsx index 352bb84c..157c2f90 100644 --- a/frontend/src/pages/conservation-builder/[locationCode].tsx +++ b/frontend/src/pages/conservation-builder/index.tsx @@ -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 - >; + layout: LayoutProps, ComponentProps>; } = () => { return null; }; @@ -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: { @@ -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( - 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), },