Skip to content

Commit

Permalink
Ville paramétrée, liens vers les lieux fonctionnels
Browse files Browse the repository at this point in the history
  • Loading branch information
laem committed Jan 18, 2025
1 parent 0272dae commit cc8ef0a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 20 deletions.
4 changes: 2 additions & 2 deletions app/QuickFeatureSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function QuickFeatureSearch({
quickSearchFeaturesMap,
center,
noPhotos = false,
centerIndication = '',
annuaireMode = false,
}) {
const [categoriesSet] = getCategories(searchParams)
const [showMore, setShowMore] = useState(false)
Expand Down Expand Up @@ -183,7 +183,7 @@ export default function QuickFeatureSearch({
)}
<CategoryResults
center={center}
centerIndication={centerIndication}
annuaireMode={annuaireMode}
resultsEntries={Object.entries(quickSearchFeaturesMap).filter(
([k, v]) => categoriesSet.includes(k)
)}
Expand Down
18 changes: 13 additions & 5 deletions app/lieux/[ville]/Annuaire.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ import {
findCategory,
} from '@/app/effects/fetchOverpassRequest'
import { getCategories } from '@/components/categories'
import communes from '@/public/communes-35.json'

const description = ''
const lonLatObject = { lat: 48.6818519, lon: -1.9678375 }
export default async function Page({ ville, searchParams }) {
export default async function Page({ ville: villeName, searchParams }) {
const ville = communes.find(
(commune) => commune.nom.toLowerCase() === villeName
)
const [lon, lat] = ville.centre.coordinates
const lonLatObject = { lat, lon }

const categoryName = searchParams.cat
const [categoryNames, categories] = getCategories(searchParams)
const bbox = computeBbox(lonLatObject)
console.log('CAT', categories)

console.log('CAT', categories, bbox)
const results = categories?.length
? await Promise.all(
categories.map((category) => fetchOverpassRequest(bbox, category))
Expand All @@ -36,7 +43,8 @@ export default async function Page({ ville, searchParams }) {
<PresentationWrapper>
<StaticPageHeader small={true} />
<header>
<h1>Annuaire des lieux de {capitalise0(ville)}</h1>
<h1>Annuaire des lieux de {ville.nom} </h1>
<small>({ville.codesPostaux.join(', ')})</small>
<p>{description}</p>
<PlaceImage
src={buildPlaceMap(48.1113404, -1.6793235)}
Expand All @@ -51,7 +59,7 @@ export default async function Page({ ville, searchParams }) {
searchParams,
noPhotos: true,
center: [lonLatObject.lon, lonLatObject.lat],
centerIndication: 'du centre ',
annuaireMode: true,
}}
/>
</PresentationWrapper>
Expand Down
2 changes: 1 addition & 1 deletion buildPlaceJsonLd.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { buildAllezPartFromOsmFeature } from './app/SetDestination'
import getUrl from './app/osm/getUrl'
import { buildPlaceMap } from './app/page'
import { getFetchUrlBase } from './app/serverUrls'
import { buildPlaceMap } from './components/buildPlaceMap'
import fetchOgImage from './components/fetchOgImage'

export default async function buildPlaceJsonLd(osmFeature, step) {
Expand Down
21 changes: 12 additions & 9 deletions components/categories/CategoryResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { css, styled } from 'next-yak'
export default function CategoryResult({
result,
setSearchParams,
centerIndication,
annuaireMode,
}) {
const {
tags: { name, description, opening_hours: oh },
Expand All @@ -24,12 +24,15 @@ export default function CategoryResult({
bearing,
} = result

const url = setSearchParams(
{
allez: buildAllezPart(name, encodePlace(featureType, id), lon, lat),
},
true
)
const allez = buildAllezPart(name, encodePlace(featureType, id), lon, lat)
const url = annuaireMode
? `/lieu?allez=${allez}`
: setSearchParams(
{
allez,
},
true
)

const humanDistance = computeHumanDistance(distance * 1000)
const { isOpen } = oh ? getOh(oh) : {}
Expand Down Expand Up @@ -66,8 +69,8 @@ export default function CategoryResult({
textAlign: 'right',
}}
>
à {humanDistance[0]} {humanDistance[1]} {centerIndication}vers{' '}
{roseDirection}
à {humanDistance[0]} {humanDistance[1]}{' '}
{annuaireMode ? 'du centre ' : ''}vers {roseDirection}
</small>
</ResultLinkWrapper>
)
Expand Down
4 changes: 2 additions & 2 deletions components/categories/CategoryResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import CategoryResult from './CategoryResult'
export default function CategoryResults({
resultsEntries,
center,
centerIndication,
annuaireMode,
}) {
const setSearchParams = useSetSearchParams()
const resultsWithoutOrder = resultsEntries
Expand Down Expand Up @@ -56,7 +56,7 @@ export default function CategoryResults({
<ol>
{results.map((result) => (
<CategoryResult
centerIndication={centerIndication}
annuaireMode={annuaireMode}
key={result.id}
result={result}
setSearchParams={setSearchParams}
Expand Down
2 changes: 1 addition & 1 deletion lib/annuaireScope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs'

const doFetch = async (departementCode = 35) => {
const request = await fetch(
`https://geo.api.gouv.fr/departements/${departementCode}/communes`
`https://geo.api.gouv.fr/departements/${departementCode}/communes?fields=code,nom,population,centre,codeRegion,codeDepartement,codesPostaux`
)
const json = await request.json()

Expand Down

0 comments on commit cc8ef0a

Please sign in to comment.