From 8f2f860b9c61491e642a77c2c21fcf3a22f54ccd Mon Sep 17 00:00:00 2001 From: maui Date: Wed, 20 Mar 2024 01:40:43 +0100 Subject: [PATCH] New explore screen --- .../explore/_components/categories-grid.tsx | 97 -------------- .../_components/links-to-categories-modal.tsx | 92 +++++++++++++ .../_components/list-category-groups.tsx | 81 +++++++++++ .../(app)/explore/bussinesses/loading.tsx | 17 --- .../(app)/explore/bussinesses/page.tsx | 56 -------- src/app/[locale]/(app)/explore/loading.tsx | 11 +- src/app/[locale]/(app)/explore/page.tsx | 24 +--- .../place-details-verificate-button.tsx | 2 +- .../[placeId]}/_components/place-details.tsx | 4 +- .../view-more-images-button-and-dialog.tsx | 0 .../(app)/explore/places/[placeId]/page.tsx | 2 +- .../[routeId]}/_components/route-details.tsx | 4 +- .../(app)/explore/routes/[routeId]/page.tsx | 2 +- .../[locale]/(app)/explore/routes/loading.tsx | 17 --- .../[locale]/(app)/explore/routes/page.tsx | 56 -------- .../{ => search}/_components/place-list.tsx | 0 .../[locale]/(app)/explore/search/page.tsx | 2 +- .../profile/_components/tabs/visited-tab.tsx | 2 +- .../admin-only/external-links-editor.tsx | 2 +- .../features}/features-block.tsx | 0 .../features}/named-websites.ts | 0 src/helpers/color-classes.ts | 41 ++++++ src/messages/ca.json | 7 +- src/messages/en.json | 7 +- src/server/api/router/explore.ts | 126 +++++------------- 25 files changed, 272 insertions(+), 380 deletions(-) delete mode 100644 src/app/[locale]/(app)/explore/_components/categories-grid.tsx create mode 100644 src/app/[locale]/(app)/explore/_components/links-to-categories-modal.tsx create mode 100644 src/app/[locale]/(app)/explore/_components/list-category-groups.tsx delete mode 100644 src/app/[locale]/(app)/explore/bussinesses/loading.tsx delete mode 100644 src/app/[locale]/(app)/explore/bussinesses/page.tsx rename src/app/[locale]/(app)/explore/{ => places/[placeId]}/_components/place-details-verificate-button.tsx (87%) rename src/app/[locale]/(app)/explore/{ => places/[placeId]}/_components/place-details.tsx (94%) rename src/app/[locale]/(app)/explore/{ => places/[placeId]}/_components/view-more-images-button-and-dialog.tsx (100%) rename src/app/[locale]/(app)/explore/{ => routes/[routeId]}/_components/route-details.tsx (92%) delete mode 100644 src/app/[locale]/(app)/explore/routes/loading.tsx delete mode 100644 src/app/[locale]/(app)/explore/routes/page.tsx rename src/app/[locale]/(app)/explore/{ => search}/_components/place-list.tsx (100%) rename src/{app/[locale]/(app)/explore/_components => components/features}/features-block.tsx (100%) rename src/{app/[locale]/(app)/explore/_components => components/features}/named-websites.ts (100%) diff --git a/src/app/[locale]/(app)/explore/_components/categories-grid.tsx b/src/app/[locale]/(app)/explore/_components/categories-grid.tsx deleted file mode 100644 index db54475d..00000000 --- a/src/app/[locale]/(app)/explore/_components/categories-grid.tsx +++ /dev/null @@ -1,97 +0,0 @@ -'use client' - -import { Button } from '@nextui-org/button' -import { Card } from '@nextui-org/card' -import { Skeleton } from '@nextui-org/react' -import { useTranslations } from 'next-intl' -import { FC, useState } from 'react' -import { CategoryIcon } from '~/components/icons/category-icon' -import { cn } from '~/helpers/cn' -import { Link } from '~/navigation' -import { PlaceCategory } from '~/server/db/constants/placeCategories' - -const ITEMS = 6 -export const CategoriesGrid: FC<{ - categories: PlaceCategory[] - type: 'place' | 'route' -}> = ({ categories, type }) => { - const t = useTranslations('explore') - const [showingAll, setShowingAll] = useState(false) - - return ( -
-

- {t('categories')} -

-
    - {categories.map((category, i) => ( -
  • - = ITEMS } - )} - > - - - {category.namePlural} - - -
  • - ))} -
- - {categories.length > ITEMS && ( - <> - - - - )} -
- ) -} - -export const CategoriesGridSkeleton: FC = () => { - return ( -
- -
- {[...Array(3 * 2)].map((_, i) => ( - - ))} -
- -
- ) -} diff --git a/src/app/[locale]/(app)/explore/_components/links-to-categories-modal.tsx b/src/app/[locale]/(app)/explore/_components/links-to-categories-modal.tsx new file mode 100644 index 00000000..8b5b209c --- /dev/null +++ b/src/app/[locale]/(app)/explore/_components/links-to-categories-modal.tsx @@ -0,0 +1,92 @@ +'use client' + +import { + Button, + Modal, + ModalBody, + ModalContent, + ModalFooter, + ModalHeader, + ScrollShadow, + useDisclosure, +} from '@nextui-org/react' +import { useTranslations } from 'next-intl' +import { FC } from 'react' +import { PlaceMarker } from '~/components/generic/place-marker' +import { Link } from '~/navigation' +import { ApiRouterOutput } from '~/server/api/router' + +type PlaceCategoryGroup = NonNullable< + ApiRouterOutput['explore']['listCategoryGroups'] +>[number] + +export const LinksToCategoriesModal: FC<{ + group: PlaceCategoryGroup +}> = ({ group }) => { + const t = useTranslations('explore') + const { isOpen, onOpen, onOpenChange } = useDisclosure() + + return ( + <> + + + + + {(onClose) => ( + <> + + {group.name} + + + +
    + {group.placeCategories.map(({ category }) => ( + + ))} +
+
+
+ + + + + )} +
+
+ + ) +} diff --git a/src/app/[locale]/(app)/explore/_components/list-category-groups.tsx b/src/app/[locale]/(app)/explore/_components/list-category-groups.tsx new file mode 100644 index 00000000..91634065 --- /dev/null +++ b/src/app/[locale]/(app)/explore/_components/list-category-groups.tsx @@ -0,0 +1,81 @@ +import { Card } from '@nextui-org/card' +import { CardBody, Skeleton } from '@nextui-org/react' +import { FC } from 'react' +import { CategoryIcon } from '~/components/icons/category-icon' +import { cn } from '~/helpers/cn' +import { colorClasses } from '~/helpers/color-classes' +import { ApiRouterOutput } from '~/server/api/router' +import { LinksToCategoriesModal } from './links-to-categories-modal' + +type PlaceCategoryGroup = NonNullable< + ApiRouterOutput['explore']['listCategoryGroups'] +>[number] + +export const ListCategoryGroups: FC<{ + group: PlaceCategoryGroup +}> = ({ group }) => { + const highlightedCategories = group.placeCategories + .filter((category) => category.highlight) + .map(({ category }) => category) + + return ( + <> +

+ {group.name} +

+ + + + + ) +} + +export const ListCategoryGroupsSkeleton: FC = () => { + return ( + <> + +
+ {Array.from({ length: 6 }).map((_, i) => ( + + ))} +
+ + + ) +} diff --git a/src/app/[locale]/(app)/explore/bussinesses/loading.tsx b/src/app/[locale]/(app)/explore/bussinesses/loading.tsx deleted file mode 100644 index 6bbc5ff6..00000000 --- a/src/app/[locale]/(app)/explore/bussinesses/loading.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import { FC } from 'react' -import { CategoriesGridSkeleton } from '../_components/categories-grid' -import { ListPlacesOfCategorySkeleton } from '../_components/list-items-of-category' - -const Loading: FC = () => { - return ( - <> - - - {[...Array(5)].map((_, i) => ( - - ))} - - ) -} - -export default Loading diff --git a/src/app/[locale]/(app)/explore/bussinesses/page.tsx b/src/app/[locale]/(app)/explore/bussinesses/page.tsx deleted file mode 100644 index 8035cd61..00000000 --- a/src/app/[locale]/(app)/explore/bussinesses/page.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import type { Metadata } from 'next' -import { getTranslations, unstable_setRequestLocale } from 'next-intl/server' -import type { FC } from 'react' -import { - onlyTranslatableLocales, - parseLocale, - type LocaleRouteParams, -} from '~/i18n' -import { getTrpc } from '~/server/get-server-thing' -import { CategoriesGrid } from '../_components/categories-grid' -import { ListItemsOfCategory } from '../_components/list-items-of-category' -import { OverrideMainMap } from '../_components/override-main-map' - -export async function generateMetadata({ - params, -}: LocaleRouteParams): Promise { - const t = await getTranslations({ - locale: params.locale, - namespace: 'explore.bussinesses', - }) - return { - title: t('meta.title'), - description: t('meta.description'), - } -} - -const BussinessesPage: FC = async ({ params }) => { - const locale = parseLocale(params.locale) - unstable_setRequestLocale(locale) - - const trpc = await getTrpc() - const placesByCategory = await trpc.explore.listBussinesses({ - locale: onlyTranslatableLocales(locale), - }) - - return ( - <> - - - - -
- {placesByCategory.map(({ places, ...category }) => ( - - ))} -
- - ) -} - -export default BussinessesPage diff --git a/src/app/[locale]/(app)/explore/loading.tsx b/src/app/[locale]/(app)/explore/loading.tsx index 05c020f5..5780610f 100644 --- a/src/app/[locale]/(app)/explore/loading.tsx +++ b/src/app/[locale]/(app)/explore/loading.tsx @@ -1,16 +1,13 @@ import { FC } from 'react' -import { CategoriesGridSkeleton } from './_components/categories-grid' -import { ListPlacesOfCategorySkeleton } from './_components/list-items-of-category' +import { ListCategoryGroupsSkeleton } from './_components/list-category-groups' const Loading: FC = () => { return ( - <> - - +
{[...Array(5)].map((_, i) => ( - + ))} - +
) } diff --git a/src/app/[locale]/(app)/explore/page.tsx b/src/app/[locale]/(app)/explore/page.tsx index 735028e4..3e7c4872 100644 --- a/src/app/[locale]/(app)/explore/page.tsx +++ b/src/app/[locale]/(app)/explore/page.tsx @@ -7,8 +7,7 @@ import { type LocaleRouteParams, } from '~/i18n' import { getTrpc } from '~/server/get-server-thing' -import { CategoriesGrid } from './_components/categories-grid' -import { ListItemsOfCategory } from './_components/list-items-of-category' +import { ListCategoryGroups } from './_components/list-category-groups' import { OverrideMainMap } from './_components/override-main-map' export async function generateMetadata({ @@ -29,27 +28,18 @@ const ExplorePage: FC = async ({ params }) => { unstable_setRequestLocale(locale) const trpc = await getTrpc() - const placesByCategory = await trpc.explore.listPlaces({ + const categoryGroups = await trpc.explore.listCategoryGroups({ locale: onlyTranslatableLocales(locale), }) return ( - <> +
- - -
- {placesByCategory.map((category) => ( - - ))} -
- + {categoryGroups.map((group) => ( + + ))} +
) } diff --git a/src/app/[locale]/(app)/explore/_components/place-details-verificate-button.tsx b/src/app/[locale]/(app)/explore/places/[placeId]/_components/place-details-verificate-button.tsx similarity index 87% rename from src/app/[locale]/(app)/explore/_components/place-details-verificate-button.tsx rename to src/app/[locale]/(app)/explore/places/[placeId]/_components/place-details-verificate-button.tsx index c8bf1a69..40e0570a 100644 --- a/src/app/[locale]/(app)/explore/_components/place-details-verificate-button.tsx +++ b/src/app/[locale]/(app)/explore/places/[placeId]/_components/place-details-verificate-button.tsx @@ -5,7 +5,7 @@ import { shotConfettiStars } from '~/helpers/confetti' import { VerificateButton, VerificateButtonProps, -} from '../../missions/_components/verificate-button' +} from '../../../../missions/_components/verificate-button' export const PlaceDetailsVerificateButton: FC = ( props diff --git a/src/app/[locale]/(app)/explore/_components/place-details.tsx b/src/app/[locale]/(app)/explore/places/[placeId]/_components/place-details.tsx similarity index 94% rename from src/app/[locale]/(app)/explore/_components/place-details.tsx rename to src/app/[locale]/(app)/explore/places/[placeId]/_components/place-details.tsx index aa6d872d..d37f4c47 100644 --- a/src/app/[locale]/(app)/explore/_components/place-details.tsx +++ b/src/app/[locale]/(app)/explore/places/[placeId]/_components/place-details.tsx @@ -6,8 +6,8 @@ import { IconTitle } from '~/components/generic/icon-title' import { MarkdownContent } from '~/components/generic/markdown-content' import { OptimizedImage } from '~/components/generic/optimized-image' import { ApiRouterOutput } from '~/server/api/router' -import { VisitMissionsAcordion } from '../../missions/_components/visit-missions-acordion' -import { FeaturesBlock } from './features-block' +import { FeaturesBlock } from '../../../../../../../components/features/features-block' +import { VisitMissionsAcordion } from '../../../../missions/_components/visit-missions-acordion' import { PlaceDetailsVerificateButton } from './place-details-verificate-button' import { ViewMoreImagesButtonAndDialog } from './view-more-images-button-and-dialog' diff --git a/src/app/[locale]/(app)/explore/_components/view-more-images-button-and-dialog.tsx b/src/app/[locale]/(app)/explore/places/[placeId]/_components/view-more-images-button-and-dialog.tsx similarity index 100% rename from src/app/[locale]/(app)/explore/_components/view-more-images-button-and-dialog.tsx rename to src/app/[locale]/(app)/explore/places/[placeId]/_components/view-more-images-button-and-dialog.tsx diff --git a/src/app/[locale]/(app)/explore/places/[placeId]/page.tsx b/src/app/[locale]/(app)/explore/places/[placeId]/page.tsx index 9f18022f..c0ecaac4 100644 --- a/src/app/[locale]/(app)/explore/places/[placeId]/page.tsx +++ b/src/app/[locale]/(app)/explore/places/[placeId]/page.tsx @@ -12,7 +12,7 @@ import { import { db } from '~/server/db/db' import { getTrpc } from '~/server/get-server-thing' import { OverrideMainMap } from '../../_components/override-main-map' -import { PlaceDetails } from '../../_components/place-details' +import { PlaceDetails } from './_components/place-details' type Params = LocaleRouteParams<{ placeId: string }> diff --git a/src/app/[locale]/(app)/explore/_components/route-details.tsx b/src/app/[locale]/(app)/explore/routes/[routeId]/_components/route-details.tsx similarity index 92% rename from src/app/[locale]/(app)/explore/_components/route-details.tsx rename to src/app/[locale]/(app)/explore/routes/[routeId]/_components/route-details.tsx index 1b93afa6..0afba2a6 100644 --- a/src/app/[locale]/(app)/explore/_components/route-details.tsx +++ b/src/app/[locale]/(app)/explore/routes/[routeId]/_components/route-details.tsx @@ -6,8 +6,8 @@ import { IconTitle } from '~/components/generic/icon-title' import { MarkdownContent } from '~/components/generic/markdown-content' import { OptimizedImage } from '~/components/generic/optimized-image' import { ApiRouterOutput } from '~/server/api/router' -import { FeaturesBlock } from './features-block' -import { ViewMoreImagesButtonAndDialog } from './view-more-images-button-and-dialog' +import { FeaturesBlock } from '../../../../../../../components/features/features-block' +import { ViewMoreImagesButtonAndDialog } from '../../../places/[placeId]/_components/view-more-images-button-and-dialog' type Route = NonNullable diff --git a/src/app/[locale]/(app)/explore/routes/[routeId]/page.tsx b/src/app/[locale]/(app)/explore/routes/[routeId]/page.tsx index 9fbbe323..e2b7e8d6 100644 --- a/src/app/[locale]/(app)/explore/routes/[routeId]/page.tsx +++ b/src/app/[locale]/(app)/explore/routes/[routeId]/page.tsx @@ -12,7 +12,7 @@ import { import { db } from '~/server/db/db' import { getTrpc } from '~/server/get-server-thing' import { OverrideMainMap } from '../../_components/override-main-map' -import { RouteDetails } from '../../_components/route-details' +import { RouteDetails } from './_components/route-details' type Params = LocaleRouteParams<{ routeId: string }> diff --git a/src/app/[locale]/(app)/explore/routes/loading.tsx b/src/app/[locale]/(app)/explore/routes/loading.tsx deleted file mode 100644 index 6bbc5ff6..00000000 --- a/src/app/[locale]/(app)/explore/routes/loading.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import { FC } from 'react' -import { CategoriesGridSkeleton } from '../_components/categories-grid' -import { ListPlacesOfCategorySkeleton } from '../_components/list-items-of-category' - -const Loading: FC = () => { - return ( - <> - - - {[...Array(5)].map((_, i) => ( - - ))} - - ) -} - -export default Loading diff --git a/src/app/[locale]/(app)/explore/routes/page.tsx b/src/app/[locale]/(app)/explore/routes/page.tsx deleted file mode 100644 index 85eac9bb..00000000 --- a/src/app/[locale]/(app)/explore/routes/page.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import type { Metadata } from 'next' -import { getTranslations, unstable_setRequestLocale } from 'next-intl/server' -import type { FC } from 'react' -import { - onlyTranslatableLocales, - parseLocale, - type LocaleRouteParams, -} from '~/i18n' -import { getTrpc } from '~/server/get-server-thing' -import { CategoriesGrid } from '../_components/categories-grid' -import { ListItemsOfCategory } from '../_components/list-items-of-category' -import { OverrideMainMap } from '../_components/override-main-map' - -export async function generateMetadata({ - params, -}: LocaleRouteParams): Promise { - const t = await getTranslations({ - locale: params.locale, - namespace: 'explore.routes', - }) - return { - title: t('meta.title'), - description: t('meta.description'), - } -} - -const RoutesPage: FC = async ({ params }) => { - const locale = parseLocale(params.locale) - unstable_setRequestLocale(locale) - - const trpc = await getTrpc() - const routesByCategory = await trpc.explore.listRoutes({ - locale: onlyTranslatableLocales(locale), - }) - - return ( - <> - - - - -
- {routesByCategory.map((category) => ( - - ))} -
- - ) -} - -export default RoutesPage diff --git a/src/app/[locale]/(app)/explore/_components/place-list.tsx b/src/app/[locale]/(app)/explore/search/_components/place-list.tsx similarity index 100% rename from src/app/[locale]/(app)/explore/_components/place-list.tsx rename to src/app/[locale]/(app)/explore/search/_components/place-list.tsx diff --git a/src/app/[locale]/(app)/explore/search/page.tsx b/src/app/[locale]/(app)/explore/search/page.tsx index 03ce4de9..7d8f9459 100644 --- a/src/app/[locale]/(app)/explore/search/page.tsx +++ b/src/app/[locale]/(app)/explore/search/page.tsx @@ -4,7 +4,7 @@ import type { FC } from 'react' import { LocaleRouteParams, onlyTranslatableLocales, parseLocale } from '~/i18n' import { getTrpc } from '~/server/get-server-thing' import { OverrideMainMap } from '../_components/override-main-map' -import { PlaceList } from '../_components/place-list' +import { PlaceList } from './_components/place-list' type PageParams = LocaleRouteParams & { searchParams: { diff --git a/src/app/[locale]/(app)/profile/_components/tabs/visited-tab.tsx b/src/app/[locale]/(app)/profile/_components/tabs/visited-tab.tsx index cd4fac5e..6fcbb6aa 100644 --- a/src/app/[locale]/(app)/profile/_components/tabs/visited-tab.tsx +++ b/src/app/[locale]/(app)/profile/_components/tabs/visited-tab.tsx @@ -2,7 +2,7 @@ import { useLocale, useTranslations } from 'next-intl' import { FC } from 'react' import { onlyTranslatableLocales } from '~/i18n' import { trpc } from '~/trpc' -import { PlaceList } from '../../../explore/_components/place-list' +import { PlaceList } from '../../../explore/search/_components/place-list' export const VisitedTab: FC = () => { const t = useTranslations('profile.tabs.visited') diff --git a/src/components/admin-only/external-links-editor.tsx b/src/components/admin-only/external-links-editor.tsx index 8cb2f5a8..cd764a86 100644 --- a/src/components/admin-only/external-links-editor.tsx +++ b/src/components/admin-only/external-links-editor.tsx @@ -11,7 +11,7 @@ import { useFormContext, useWatch, } from 'react-hook-form' -import { getLinkData } from '~/app/[locale]/(app)/explore/_components/named-websites' +import { getLinkData } from '~/components/features/named-websites' import { cn } from '~/helpers/cn' import { makeGoogleMapsUrl } from '~/helpers/data/google-maps-id' import { Link } from '~/navigation' diff --git a/src/app/[locale]/(app)/explore/_components/features-block.tsx b/src/components/features/features-block.tsx similarity index 100% rename from src/app/[locale]/(app)/explore/_components/features-block.tsx rename to src/components/features/features-block.tsx diff --git a/src/app/[locale]/(app)/explore/_components/named-websites.ts b/src/components/features/named-websites.ts similarity index 100% rename from src/app/[locale]/(app)/explore/_components/named-websites.ts rename to src/components/features/named-websites.ts diff --git a/src/helpers/color-classes.ts b/src/helpers/color-classes.ts index 8798b349..782683ef 100644 --- a/src/helpers/color-classes.ts +++ b/src/helpers/color-classes.ts @@ -163,6 +163,47 @@ export const colorClasses = { pink: 'text-pink-600', rose: 'text-rose-600', }, + + shadow: { + gray: 'shadow-gray-700/60', + red: 'shadow-red-500/60', + orange: 'shadow-orange-500/60', + amber: 'shadow-amber-500/60', + yellow: 'shadow-yellow-500/60', + lime: 'shadow-lime-500/60', + green: 'shadow-green-500/60', + emerald: 'shadow-emerald-500/60', + teal: 'shadow-teal-500/60', + cyan: 'shadow-cyan-500/60', + sky: 'shadow-sky-500/60', + blue: 'shadow-blue-500/60', + indigo: 'shadow-indigo-500/60', + violet: 'shadow-violet-500/60', + purple: 'shadow-purple-500/60', + fuchsia: 'shadow-fuchsia-500/60', + pink: 'shadow-pink-500/60', + rose: 'shadow-rose-500/60', + }, + gradientBg: { + gray: 'from-gray-900 to-gray-700', + red: 'from-red-600 to-red-500', + orange: 'from-orange-600 to-orange-500', + amber: 'from-amber-600 to-amber-500', + yellow: 'from-yellow-600 to-yellow-500', + lime: 'from-lime-600 to-lime-500', + green: 'from-green-600 to-green-500', + emerald: 'from-emerald-600 to-emerald-500', + teal: 'from-teal-600 to-teal-500', + cyan: 'from-cyan-600 to-cyan-500', + sky: 'from-sky-600 to-sky-500', + blue: 'from-blue-600 to-blue-500', + indigo: 'from-indigo-600 to-indigo-500', + violet: 'from-violet-600 to-violet-500', + purple: 'from-purple-600 to-purple-500', + fuchsia: 'from-fuchsia-600 to-fuchsia-500', + pink: 'from-pink-600 to-pink-500', + rose: 'from-rose-600 to-rose-500', + }, } as const satisfies { [x: string]: Record } diff --git a/src/messages/ca.json b/src/messages/ca.json index a4f8b5f7..748daf3d 100644 --- a/src/messages/ca.json +++ b/src/messages/ca.json @@ -366,6 +366,7 @@ }, "see-all": "Veure {gender, select, masculine {tots} feminine {totes} other {tots}}", "show-all": "Mostrar {gender, select, masculine {tots} feminine {totes} other {tots}}", + "see-all-categories": "Veure totes les categories", "show-less": "Mostrar menys", "see-more": "Veure més", "categories": "Categories", @@ -373,11 +374,7 @@ "related-missions": "Missions relacionades", "detailed-info": "Informació detallada", "maps-app": "App de mapes", - "tabs": { - "places": "Llocs", - "bussinesses": "Negocis", - "routes": "Rutes" - } + "close": "Tancar" }, "missions": { "meta": { diff --git a/src/messages/en.json b/src/messages/en.json index 1efa2a98..ab79fa0b 100644 --- a/src/messages/en.json +++ b/src/messages/en.json @@ -366,6 +366,7 @@ }, "see-all": "See all", "show-all": "Show all", + "see-all-categories": "See all categories", "show-less": "Show less", "see-more": "See more", "categories": "Categories", @@ -373,11 +374,7 @@ "related-missions": "Related missions", "detailed-info": "Detailed info", "maps-app": "Maps app", - "tabs": { - "places": "Places", - "bussinesses": "Bussinesses", - "routes": "Routes" - } + "close": "Close" }, "missions": { "meta": { diff --git a/src/server/api/router/explore.ts b/src/server/api/router/explore.ts index 12f8c3cb..3f2db62f 100644 --- a/src/server/api/router/explore.ts +++ b/src/server/api/router/explore.ts @@ -1,7 +1,6 @@ import { z } from 'zod' -import { translatableLocales } from '~/i18n' +import { defaultLocale, translatableLocales } from '~/i18n' import { db } from '~/server/db/db' -import { placeCategoriesToPlaceCategoryGroups } from '~/server/db/schema' import { ascNullsEnd } from '~/server/helpers/order-by' import { doSomethingAfterExecute } from '~/server/helpers/translations/on-execute' import { @@ -10,94 +9,32 @@ import { } from '~/server/helpers/translations/query/with-translations' import { publicProcedure, router } from '~/server/trpc' -const placeCategoryGroupIdByName = { - nature: 1, - activities: 2, - historyAndCulture: 3, - infrastructure: 4, - shops: 5, - restaurants: 6, - leisureAndSports: 7, - services: 8, - foodAndSupermarkets: 9, - accommodation: 10, -} as const satisfies Record - -const makeGetCategoriesWithPlaces = (categoryGroupIds: number[]) => - doSomethingAfterExecute( - flattenTranslationsOnExecute( - db.query.placeCategories - .findMany( - withTranslations({ - where: (category, { inArray }) => - inArray( - category.id, - db - .select({ - data: placeCategoriesToPlaceCategoryGroups.categoryId, - }) - .from(placeCategoriesToPlaceCategoryGroups) - .where( - inArray( - placeCategoriesToPlaceCategoryGroups.categoryGroupId, - categoryGroupIds - ) - ) - ), +const getCategoryGroups = flattenTranslationsOnExecute( + db.query.placeCategoryGroups + .findMany( + withTranslations({ + with: { + placeCategories: { + columns: { + highlight: true, + }, with: { - mainPlaces: withTranslations({ + category: withTranslations({ columns: { id: true, - name: true, - importance: true, - }, - with: { - mainImage: true, + namePlural: true, + icon: true, + color: true, }, }), - secondaryPlaces: { - with: { - place: withTranslations({ - columns: { - id: true, - name: true, - importance: true, - }, - with: { - mainImage: true, - }, - }), - }, - }, }, - orderBy: (category) => [ascNullsEnd(category.order)], - }) - ) - .prepare() - ), - (categories) => - categories.map(({ mainPlaces, secondaryPlaces, ...category }) => ({ - ...category, - places: [...mainPlaces, ...secondaryPlaces.map(({ place }) => place)] - .filter(isFirstOccurence) - .sort(sortByImportance), - })) - ) - -const getCategoriesWithPlacesForBussinesses = makeGetCategoriesWithPlaces([ - placeCategoryGroupIdByName.shops, - placeCategoryGroupIdByName.restaurants, - placeCategoryGroupIdByName.leisureAndSports, - placeCategoryGroupIdByName.services, - placeCategoryGroupIdByName.foodAndSupermarkets, - placeCategoryGroupIdByName.accommodation, -]) -const getCategoriesWithPlacesForPlaces = makeGetCategoriesWithPlaces([ - placeCategoryGroupIdByName.nature, - placeCategoryGroupIdByName.activities, - placeCategoryGroupIdByName.historyAndCulture, - placeCategoryGroupIdByName.infrastructure, -]) + }, + }, + orderBy: (group) => [ascNullsEnd(group.order)], + }) + ) + .prepare() +) const getCategoriesWithRoutes = doSomethingAfterExecute( flattenTranslationsOnExecute( @@ -145,19 +82,22 @@ const getCategoriesWithRoutes = doSomethingAfterExecute( ) export const exploreRouter = router({ - listBussinesses: publicProcedure - .input(z.object({ locale: z.enum(translatableLocales).nullable() })) - .query(async ({ input }) => { - return await getCategoriesWithPlacesForBussinesses.execute({ - locale: input.locale, - }) - }), - listPlaces: publicProcedure + listCategoryGroups: publicProcedure .input(z.object({ locale: z.enum(translatableLocales).nullable() })) .query(async ({ input }) => { - return await getCategoriesWithPlacesForPlaces.execute({ + const groups = await getCategoryGroups.execute({ locale: input.locale, }) + + return groups.map((group) => ({ + ...group, + placeCategories: group.placeCategories.sort((a, b) => + a.category.namePlural.localeCompare( + b.category.namePlural, + input.locale ?? defaultLocale + ) + ), + })) }), listRoutes: publicProcedure .input(z.object({ locale: z.enum(translatableLocales).nullable() }))