Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions apps/frontend/src/components/NearbyVenues.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface NearbyVenuesProps {
locationError: string | null
isLoading: boolean
isError: boolean
maxDistanceKm?: number
maxDistanceKm?: number | null
onRefresh: () => void
}

Expand Down Expand Up @@ -82,7 +82,9 @@ export default function NearbyVenues({
<div className="flex flex-wrap items-start justify-between gap-3">
<div>
<h2 className="mt-1 text-xl font-extrabold">
Pubs within {maxDistanceKm} km
{maxDistanceKm == null
? 'Pubs near you'
: `Pubs within ${maxDistanceKm} km`}
</h2>
</div>
<button
Expand Down Expand Up @@ -125,7 +127,9 @@ export default function NearbyVenues({
venues.length === 0 &&
!locationError && (
<p className="mt-3 text-sm text-(--sea-ink-soft)">
No pubs within {maxDistanceKm} km of your location.
{maxDistanceKm == null
? 'No pubs found.'
: `No pubs within ${maxDistanceKm} km of your location.`}
</p>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ describe('NearbyVenues', () => {
).toBeInTheDocument()
})

it('does not describe a radius when the distance filter is unlimited', async () => {
renderNearbyVenues({ hasLocation: true, maxDistanceKm: null })

expect(await screen.findByText('Pubs near you')).toBeInTheDocument()
expect(await screen.findByText('No pubs found.')).toBeInTheDocument()
})

it('renders venue rows and links them to their venue pages', async () => {
const venues = [
makeSearchResult(),
Expand Down
29 changes: 13 additions & 16 deletions apps/frontend/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ import type { NearbyVenue, VenuePriceSighting } from '#/types/venue'

export const Route = createFileRoute('/')({ component: App })

const NEARBY_LIMIT = 5
const NEARBY_MAX_DISTANCE_KM = 10
const NEARBY_LIST_LIMIT = 5

// The map shows every venue matching the filters. The list below the map is a
// short nearby preview, so we only slice its data client-side.
const NEARBY_QUERY = `
query NearbyVenues(
$lat: Float!
$lon: Float!
$limit: Int!
$maxDistanceKm: Float!
$maxDistanceKm: Float
$minPrice: Float
$maxPrice: Float
$sizes: [GlassSize!]
Expand All @@ -45,7 +45,6 @@ const NEARBY_QUERY = `
venue(
lat: $lat
lon: $lon
limit: $limit
maxDistanceKm: $maxDistanceKm
minPrice: $minPrice
maxPrice: $maxPrice
Expand Down Expand Up @@ -178,15 +177,9 @@ function App() {
void refreshLocation()
}, [refreshLocation])

const nearbyMaxDistanceKm =
searchFilters.maxDistanceKm ?? NEARBY_MAX_DISTANCE_KM
const nearbyVariables = useMemo(
() => ({
...searchFilterVariables(searchFilters, coordinates),
limit: NEARBY_LIMIT,
maxDistanceKm: nearbyMaxDistanceKm,
}),
[searchFilters, coordinates, nearbyMaxDistanceKm],
() => searchFilterVariables(searchFilters, coordinates),
[searchFilters, coordinates],
)

const { data, isFetching, isError } = useQuery({
Expand All @@ -199,10 +192,14 @@ function App() {
retry: 1,
})

const nearbyVenues = useMemo(
const venueResults = useMemo(
() => (data?.venue ?? []).map(toSearchResult),
[data],
)
const nearbyVenues = useMemo(
() => venueResults.slice(0, NEARBY_LIST_LIMIT),
[venueResults],
)

return (
<main id="main-content" className="page-wrap px-4 pb-8 pt-14">
Expand All @@ -216,7 +213,7 @@ function App() {
<SearchBox coordinates={coordinates} filters={searchFilters} />
</div>
<ClientMap
nearby={nearbyVenues}
nearby={venueResults}
userLocation={coordinates}
isMockLocation={usingMockLocation}
/>
Expand All @@ -234,7 +231,7 @@ function App() {
locationError={locationError}
isLoading={isFetching}
isError={isError}
maxDistanceKm={nearbyMaxDistanceKm}
maxDistanceKm={searchFilters.maxDistanceKm}
onRefresh={refreshLocation}
/>
</div>
Expand Down
12 changes: 6 additions & 6 deletions packages/db/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,9 @@ async function main() {
create: [
{
name: 'The Dubliner Folk Pub',
address: 'Rådhusgata 13',
lat: 59.9114,
lon: 10.7405,
address: 'Rådhusgata 28',
lat: 59.909831,
lon: 10.740738,
openingHours: {
create: [
{
Expand Down Expand Up @@ -483,9 +483,9 @@ async function main() {
},
{
name: 'Tilt',
address: 'Øvre Slottsgate 6',
lat: 59.9139,
lon: 10.7432,
address: 'Badstugata 6',
lat: 59.916211,
lon: 10.750614,
openingHours: {
create: [
{
Expand Down