Compare commits

...

11 Commits

Author SHA1 Message Date
Ovidiu U
a969c1b347 feat: add fuel price classification markers and responsive search UI improvements
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.3) (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled
- Move map pin icon to right side of input with adjusted spacing
- Change button styling from accent to primary color
2026-04-11 20:51:07 +01:00
Ovidiu U
951bb0b98d feat: add sort select to homepage SearchBar 2026-04-11 18:57:03 +01:00
Ovidiu U
b8adc98669 feat: add brand and reliable sort options to StationList 2026-04-11 18:55:21 +01:00
Ovidiu U
2747047f53 fix: correct default fuelType in useStations from 'petrol' to 'e10' 2026-04-11 18:50:29 +01:00
Ovidiu U
5fe9f9dc6d fix: empty results state and validation error display on homepage 2026-04-11 18:48:25 +01:00
Ovidiu U
276f9bf612 feat: wire up homepage search with map and station list 2026-04-11 18:46:34 +01:00
Ovidiu U
6f52f3f0d7 feat: add defaultOpen prop to LeafletMap 2026-04-11 18:45:26 +01:00
Ovidiu U
d11d500a35 fix: accessibility and Enter key handling in SearchBar 2026-04-11 18:44:34 +01:00
Ovidiu U
b5ee25db67 feat: add fuel type and radius selects to SearchBar 2026-04-11 17:23:56 +01:00
Ovidiu U
66c662f471 docs: add homepage search implementation plan 2026-04-11 17:23:03 +01:00
Ovidiu U
9f7b45751e docs: add homepage search design spec 2026-04-11 17:15:23 +01:00
9 changed files with 675 additions and 63 deletions

View File

@@ -5,6 +5,7 @@ namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful;
use Symfony\Component\HttpFoundation\Response;
final class VerifyApiKey
@@ -20,6 +21,10 @@ final class VerifyApiKey
return $next($request);
}
if (EnsureFrontendRequestsAreStateful::fromFrontend($request)) {
return $next($request);
}
if ($request->header('X-Api-Key') !== config('app.api_secret_key')) {
abort(403);
}

View File

@@ -0,0 +1,335 @@
# Homepage Search Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Wire up the homepage `SearchBar` to perform a live station search and render a map + station list inline below the hero section.
**Architecture:** `SearchBar` emits `{ postcode, fuelType, radius }` on button click. `Home.vue` calls `useStations.search()` with those params and renders `LeafletMap` (open by default) + `StationList` in a full-width section below the hero. `LeafletMap` gains a `defaultOpen` prop to auto-initialise without user toggle.
**Tech Stack:** Vue 3 Composition API (`<script setup>`), Leaflet.js, `useStations` composable, Tailwind CSS v4
---
## File Map
| File | Change |
|---|---|
| `resources/js/components/SearchBar.vue` | Add fuel type + radius selects; change emit to object; remove debounce |
| `resources/js/components/LeafletMap.vue` | Add `defaultOpen` prop; init map on mount when true |
| `resources/js/views/Home.vue` | Wire `useStations`; hold `lastParams`/`sort`; render results section |
---
## Task 1: Update SearchBar — params + layout
**Files:**
- Modify: `resources/js/components/SearchBar.vue`
- [ ] **Step 1: Replace SearchBar.vue with the new implementation**
```vue
<template>
<div class="flex flex-col gap-3 max-w-md w-full">
<!-- Row 1: postcode + button -->
<div class="relative flex flex-col sm:flex-row gap-3">
<div class="relative flex-1">
<span class="absolute left-4 top-1/2 -translate-y-1/2 text-zinc-500">
<iconify-icon icon="lucide:map-pin" style="font-size:1.25rem"></iconify-icon>
</span>
<input
v-model="postcode"
type="text"
placeholder="Enter postcode, e.g. SW1A 1AA"
class="w-full h-14 pl-12 pr-4 bg-white border border-zinc-300 rounded-xl focus:outline-none focus:ring-2 focus:ring-accent shadow-inner text-base"
/>
</div>
<button
@click="onSearch"
:disabled="!postcode.trim()"
class="h-14 px-8 bg-accent text-white rounded-xl font-bold text-base shadow-xl hover:bg-accent-content transition-all disabled:opacity-50 disabled:cursor-not-allowed"
>
Find Prices
</button>
</div>
<!-- Row 2: fuel type + radius -->
<div class="flex gap-3">
<select
v-model="fuelType"
class="flex-1 h-10 px-3 bg-white border border-zinc-300 rounded-xl text-sm font-medium text-zinc-700 focus:outline-none focus:ring-2 focus:ring-accent"
>
<option value="e10">Petrol (E10)</option>
<option value="e5">Premium Petrol (E5)</option>
<option value="b7_standard">Diesel (B7)</option>
<option value="b7_premium">Premium Diesel (B7)</option>
<option value="b10">Diesel (B10)</option>
<option value="hvo">HVO</option>
</select>
<select
v-model="radius"
class="w-32 h-10 px-3 bg-white border border-zinc-300 rounded-xl text-sm font-medium text-zinc-700 focus:outline-none focus:ring-2 focus:ring-accent"
>
<option :value="2">2 miles</option>
<option :value="5">5 miles</option>
<option :value="10">10 miles</option>
<option :value="20">20 miles</option>
</select>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue'
const emit = defineEmits(['search'])
const postcode = ref('')
const fuelType = ref('e10')
const radius = ref(10)
function onSearch() {
if (!postcode.value.trim()) return
emit('search', {
postcode: postcode.value.trim(),
fuelType: fuelType.value,
radius: radius.value,
})
}
</script>
```
- [ ] **Step 2: Commit**
```bash
git add resources/js/components/SearchBar.vue
git commit -m "feat: add fuel type and radius selects to SearchBar"
```
---
## Task 2: Update LeafletMap — defaultOpen prop
**Files:**
- Modify: `resources/js/components/LeafletMap.vue`
- [ ] **Step 1: Add `defaultOpen` prop and auto-init on mount**
Replace the `<script setup>` block in `resources/js/components/LeafletMap.vue`:
```vue
<script setup>
import { ref, watch, onMounted, onUnmounted, nextTick } from 'vue'
import L from 'leaflet'
import 'leaflet/dist/leaflet.css'
// Fix Leaflet default marker icon path broken by Vite
delete L.Icon.Default.prototype._getIconUrl
L.Icon.Default.mergeOptions({
iconRetinaUrl: 'https://unpkg.com/leaflet@1.9.4/dist/images/marker-icon-2x.png',
iconUrl: 'https://unpkg.com/leaflet@1.9.4/dist/images/marker-icon.png',
shadowUrl: 'https://unpkg.com/leaflet@1.9.4/dist/images/marker-shadow.png',
})
const props = defineProps({
stations: { type: Array, required: true },
defaultOpen: { type: Boolean, default: false },
})
const mapContainer = ref(null)
const isOpen = ref(false)
let mapInstance = null
let markersLayer = null
function initMap() {
if (mapInstance || !mapContainer.value) return
mapInstance = L.map(mapContainer.value)
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors',
}).addTo(mapInstance)
markersLayer = L.layerGroup().addTo(mapInstance)
}
function renderMarkers() {
if (!mapInstance || !markersLayer) return
markersLayer.clearLayers()
if (!props.stations.length) return
const bounds = []
props.stations.forEach(station => {
const marker = L.marker([station.lat, station.lng])
.bindPopup(`<strong>${station.name}</strong><br>${station.price}p`)
markersLayer.addLayer(marker)
bounds.push([station.lat, station.lng])
})
if (bounds.length) {
mapInstance.fitBounds(bounds, { padding: [30, 30] })
}
}
async function toggleMap() {
isOpen.value = !isOpen.value
if (isOpen.value) {
await nextTick()
initMap()
mapInstance.invalidateSize()
renderMarkers()
}
}
onMounted(async () => {
if (props.defaultOpen) {
isOpen.value = true
await nextTick()
initMap()
mapInstance.invalidateSize()
renderMarkers()
}
})
watch(() => props.stations, () => {
if (isOpen.value) {
renderMarkers()
}
})
onUnmounted(() => {
if (mapInstance) {
mapInstance.remove()
mapInstance = null
}
})
</script>
```
- [ ] **Step 2: Commit**
```bash
git add resources/js/components/LeafletMap.vue
git commit -m "feat: add defaultOpen prop to LeafletMap"
```
---
## Task 3: Wire up Home.vue — results section
**Files:**
- Modify: `resources/js/views/Home.vue`
- [ ] **Step 1: Update the script block**
Replace the `<script setup>` block at the bottom of `resources/js/views/Home.vue`:
```vue
<script setup>
import { ref } from 'vue'
import { RouterLink } from 'vue-router'
import { useAuth } from '../composables/useAuth.js'
import { useStations } from '../composables/useStations.js'
import SearchBar from '../components/SearchBar.vue'
import LeafletMap from '../components/LeafletMap.vue'
import StationList from '../components/StationList.vue'
const { isAuthenticated } = useAuth()
const { stations, loading, error, search } = useStations()
const sort = ref('price')
const lastParams = ref(null)
const searchAttempted = ref(false)
async function onSearch(params) {
lastParams.value = params
searchAttempted.value = true
await search({ ...params, sort: sort.value })
}
async function onSort(newSort) {
sort.value = newSort
if (lastParams.value) {
await search({ ...lastParams.value, sort: newSort })
}
}
</script>
```
- [ ] **Step 2: Add the results section to the template**
Add this new `<section>` block directly after the closing `</section>` tag of the hero section (after line `</section>` that closes `id="hero"`), before the `<!-- How It Works -->` section:
```html
<!-- Search Results -->
<section v-if="searchAttempted" class="px-6 py-10 bg-zinc-100">
<div class="max-w-7xl mx-auto space-y-6">
<!-- Loading -->
<div v-if="loading" class="flex items-center justify-center py-16">
<div class="flex items-center gap-3 text-zinc-500">
<iconify-icon icon="lucide:loader-circle" class="animate-spin text-2xl text-accent"></iconify-icon>
<span class="font-medium">Finding stations near you…</span>
</div>
</div>
<!-- Error -->
<div v-else-if="error" class="flex items-center gap-3 p-4 bg-white border border-zinc-300 rounded-xl text-status-bad">
<iconify-icon icon="lucide:circle-alert" style="font-size:1.25rem"></iconify-icon>
<span class="font-medium">{{ error.general?.[0] ?? 'Unable to load stations. Please try again.' }}</span>
</div>
<!-- Results -->
<template v-else>
<LeafletMap :stations="stations" :default-open="true" />
<StationList :stations="stations" :current-sort="sort" @sort="onSort" />
</template>
</div>
</section>
```
- [ ] **Step 3: Verify the `<SearchBar>` tag in the hero still has `@search="onSearch"`**
In the hero section, the tag should read:
```html
<SearchBar @search="onSearch" />
```
- [ ] **Step 4: Commit**
```bash
git add resources/js/views/Home.vue
git commit -m "feat: wire up homepage search with map and station list"
```
---
## Task 4: Manual browser verification
- [ ] **Step 1: Start the dev server** (if not already running)
```bash
npm run dev
```
- [ ] **Step 2: Open the homepage** at the URL from `herd` (e.g. `https://fuel-price.test`)
- [ ] **Step 3: Verify the search bar has three controls** — postcode input, fuel type select, radius select
- [ ] **Step 4: Enter a valid UK postcode** (e.g. `SW1A 1AA`) and click "Find Prices"
- [ ] **Step 5: Verify the results section appears below the hero** with:
- Loading spinner shown briefly
- Map opens automatically with markers at each station
- Station list renders below the map with sort tabs (Price / Distance / Updated)
- Cheapest station price is highlighted in green
- [ ] **Step 6: Click a sort tab** (e.g. Distance) and verify the list re-fetches and reorders
- [ ] **Step 7: Click "Hide map" toggle** and verify the map collapses; click "Show map" and verify it reopens
- [ ] **Step 8: Enter an invalid postcode** and verify an error message appears instead of the results

View File

@@ -0,0 +1,70 @@
# Homepage Search — Design Spec
**Date:** 2026-04-11
**Status:** Approved
## Overview
Wire up the `SearchBar` on the homepage so it performs a live station search and renders a map + station list inline, below the search bar. No navigation away from the page. All existing components (`LeafletMap`, `StationList`, `useStations`) are reused as-is, with minimal targeted changes.
---
## Component Changes
### `SearchBar.vue`
- Add a **fuel type** `<select>` with options: E10, E5, Diesel (B7), Premium Diesel (B7), B10, HVO
- Add a **radius** `<select>` with options: 2, 5, 10, 20 miles (default: 10)
- Change the `search` emit payload from a bare postcode string to `{ postcode, fuelType, radius }`
- **Remove** the debounced `onInput` handler — search fires on button click only (debounce on a multi-param form causes confusing mid-type fetches)
- Button stays disabled when postcode is empty
### `LeafletMap.vue`
- Add a `defaultOpen` Boolean prop (default `false`) for backwards compatibility
- When `defaultOpen` is `true`, initialise the map on `onMounted` instead of waiting for the toggle
- Toggle button remains so users can collapse the map
- Auto-renders markers when `stations` prop is populated after mount
### `Home.vue`
- Import `useStations` and hold `sort` ref (default `'price'`)
- On `@search` from `SearchBar`, call `useStations.search({ postcode, fuelType, radius, sort })`
- Add a results `<section>` directly below the hero section — full width, `max-w-7xl` container, `px-6 py-10` padding
- Results section only renders when a search has been attempted (`stations.length || loading || error`)
- Results layout (top to bottom):
1. `LeafletMap` with `:stations="stations"` and `:default-open="true"``h-80` height
2. `StationList` with `:stations="stations"` `:current-sort="sort"` `@sort="onSort"`
- **Loading state:** spinner centred in the results section, replaces map+list
- **Error state:** inline error message (`error.general[0]` or fallback text), replaces map+list
- `onSort` handler updates `sort` ref and re-runs `search()` with last used params (store params in a `lastParams` ref)
---
## Data Flow
```
SearchBar emits { postcode, fuelType, radius }
→ Home.vue calls useStations.search({ ...params, sort })
→ API GET /stations?postcode=...&fuel_type=...&radius=...&sort=...
→ stations ref populated
→ LeafletMap renders markers (auto-open)
→ StationList renders cards
```
---
## What Is Not Changing
- `StationCard.vue` — no changes
- `useStations.js` — no changes
- API layer — no changes
- Dashboard usage of `LeafletMap` and `StationList` — unaffected (defaultOpen defaults to false)
---
## Out of Scope
- Saving/favouriting stations from homepage (dashboard feature)
- Geolocation "use my location" button
- Pagination of results

View File

@@ -6,7 +6,7 @@
@source '../../vendor/livewire/flux-pro/stubs/**/*.blade.php';
@source '../../vendor/livewire/flux/stubs/**/*.blade.php';
@custom-variant dark (&:where(.dark, .dark *));
@custom-variant dark (&:where(.dark-mode-disabled));
@theme {
--font-sans: 'Inter', ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
@@ -53,13 +53,6 @@
--font-display: 'Manrope', ui-sans-serif, system-ui, sans-serif;
}
@layer theme {
.dark {
--color-accent: var(--color-white);
--color-accent-content: var(--color-white);
--color-accent-foreground: var(--color-neutral-800);
}
}
@layer utilities {
.hero-gradient {

View File

@@ -8,29 +8,98 @@
{{ isOpen ? 'Hide map' : 'Show map' }}
</button>
<template v-if="isOpen">
<div
v-show="isOpen"
ref="mapContainer"
class="w-full h-72 rounded-2xl overflow-hidden border border-zinc-300 shadow-sm"
></div>
<div class="flex flex-wrap gap-3 text-xs text-zinc-500">
<span class="flex items-center gap-1.5">
<span class="inline-block size-3 rounded-full bg-green-500"></span>
Current (&lt;24h)
</span>
<span class="flex items-center gap-1.5">
<span class="inline-block size-3 rounded-full bg-slate-500"></span>
Recent (2448h)
</span>
<span class="flex items-center gap-1.5">
<span class="inline-block size-3 rounded-full bg-amber-500"></span>
Stale (25 days)
</span>
<span class="flex items-center gap-1.5">
<span class="inline-block size-3 rounded-full bg-red-500"></span>
Outdated (5+ days)
</span>
</div>
</template>
</div>
</template>
<script setup>
import { ref, watch, onUnmounted, nextTick } from 'vue'
import { ref, watch, onMounted, onUnmounted, nextTick } from 'vue'
import L from 'leaflet'
import 'leaflet/dist/leaflet.css'
// Fix Leaflet default marker icon path broken by Vite
delete L.Icon.Default.prototype._getIconUrl
L.Icon.Default.mergeOptions({
iconRetinaUrl: 'https://unpkg.com/leaflet@1.9.4/dist/images/marker-icon-2x.png',
iconUrl: 'https://unpkg.com/leaflet@1.9.4/dist/images/marker-icon.png',
shadowUrl: 'https://unpkg.com/leaflet@1.9.4/dist/images/marker-shadow.png',
})
const CLASSIFICATION_COLOURS = {
current: '#22c55e',
recent: '#64748b',
stale: '#f59e0b',
outdated: '#ef4444',
}
const CLASSIFICATION_BORDER_COLOURS = {
current: '#16a34a',
recent: '#475569',
stale: '#d97706',
outdated: '#dc2626',
}
function buildMarkerHtml(station, index, colour, borderColour) {
const isFirst = index === 0
const w = isFirst ? 63 : 59
const h = isFirst ? 58 : 51
const bw = isFirst ? 56 : 52
const bh = isFirst ? 43 : 38
const br = isFirst ? 17 : 15
const tailTop = isFirst ? 45 : 40
const tailW = isFirst ? 9 : 7
const tailH = isFirst ? 11 : 9
const badgeSize = isFirst ? 18 : 16
const badgeFontSize = isFirst ? 10 : 8
const priceFontSize = isFirst ? 12 : 11
const initial = escHtml((station.brand || station.name || '?')[0].toUpperCase())
const badge = isFirst
? `<div style="position:absolute;top:-4px;right:-4px;width:${badgeSize}px;height:${badgeSize}px;background:#facc15;border-radius:50%;display:flex;align-items:center;justify-content:center;border:2px solid white;box-shadow:0 2px 4px rgba(0,0,0,0.2);z-index:30;"><span style="font-size:${badgeFontSize}px;color:#713f12;">★</span></div>`
: `<div style="position:absolute;top:-3px;right:-3px;width:${badgeSize}px;height:${badgeSize}px;background:#374151;border-radius:50%;display:flex;align-items:center;justify-content:center;border:1px solid white;box-shadow:0 1px 3px rgba(0,0,0,0.2);z-index:30;"><span style="font-size:${badgeFontSize}px;font-weight:bold;color:white;">${index + 1}</span></div>`
return `<div style="position:relative;width:${w}px;height:${h}px;">
${badge}
<div style="position:absolute;top:6px;left:50%;transform:translateX(-50%);width:${bw}px;height:${bh}px;background:${colour};border-radius:${br}px;border:3px solid ${borderColour};box-shadow:0 2px 6px rgba(0,0,0,0.24),inset 0 1px 0 rgba(255,255,255,0.22);overflow:hidden;z-index:10;">
<div style="position:absolute;top:0;left:0;right:0;height:11px;background:rgba(15,23,42,0.20);border-bottom:1px solid rgba(255,255,255,0.24);display:flex;align-items:center;justify-content:center;">
<span style="font-size:9px;font-weight:700;letter-spacing:-0.05px;color:rgba(255,255,255,0.84);text-transform:uppercase;line-height:1;">${initial}</span>
</div>
<div style="position:absolute;left:3px;right:3px;top:12px;bottom:2px;display:flex;align-items:center;justify-content:center;text-align:center;">
<span style="display:inline-block;max-width:${bw - 13}px;color:#ffffff;font-size:${priceFontSize}px;font-weight:800;letter-spacing:-0.1px;line-height:1.12;white-space:nowrap;text-shadow:0 1px 1px rgba(0,0,0,0.42);">${Number(station.price).toFixed(1)}p</span>
</div>
</div>
<div style="position:absolute;top:${tailTop}px;left:50%;transform:translateX(-50%);width:0;height:0;border-left:${tailW}px solid transparent;border-right:${tailW}px solid transparent;border-top:${tailH}px solid ${colour};z-index:5;"></div>
</div>`
}
function escHtml(str) {
return String(str ?? '')
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
}
const props = defineProps({
stations: { type: Array, required: true },
defaultOpen: { type: Boolean, default: false },
})
const mapContainer = ref(null)
@@ -59,15 +128,44 @@ function renderMarkers() {
const bounds = []
props.stations.forEach(station => {
const marker = L.marker([station.lat, station.lng])
.bindPopup(`<strong>${station.name}</strong><br>${station.price}p`)
props.stations.forEach((station, index) => {
const colour = CLASSIFICATION_COLOURS[station.price_classification] ?? '#64748b'
const borderColour = CLASSIFICATION_BORDER_COLOURS[station.price_classification] ?? '#475569'
const miles = ((station.distance_km ?? 0) * 0.621371).toFixed(1)
const supermarketTag = station.is_supermarket
? '<span style="display:inline-block;background:#84cc16;color:#fff;font-size:10px;padding:1px 5px;border-radius:3px;margin-left:4px;">Supermarket</span>'
: ''
const popup = `
<div style="min-width:160px">
<strong style="font-size:13px">${escHtml(station.name)}</strong>${supermarketTag}<br>
<span style="font-size:20px;font-weight:700;color:${escHtml(colour)}">${Number(station.price).toFixed(1)}p</span><br>
<span style="font-size:12px;color:#6b7280">${escHtml(miles)} miles away</span><br>
<span style="font-size:11px;color:#9ca3af">${escHtml(station.address)}, ${escHtml(station.postcode)}</span>
</div>
`
const isFirst = index === 0
const w = isFirst ? 63 : 59
const h = isFirst ? 58 : 51
const icon = L.divIcon({
className: '',
iconSize: [w, h],
iconAnchor: [w / 2, h],
html: buildMarkerHtml(station, index, colour, borderColour),
})
const marker = L.marker([station.lat, station.lng], { icon }).bindPopup(popup)
markersLayer.addLayer(marker)
bounds.push([station.lat, station.lng])
})
if (bounds.length) {
mapInstance.fitBounds(bounds, { padding: [30, 30] })
if (bounds.length === 1) {
mapInstance.setView(bounds[0], 14)
} else {
mapInstance.fitBounds(bounds, { padding: [40, 40], maxZoom: 14 })
}
}
@@ -82,6 +180,16 @@ async function toggleMap() {
}
}
onMounted(async () => {
if (props.defaultOpen) {
isOpen.value = true
await nextTick()
initMap()
mapInstance.invalidateSize()
renderMarkers()
}
})
watch(() => props.stations, () => {
if (isOpen.value) {
renderMarkers()

View File

@@ -1,40 +1,88 @@
<template>
<div class="relative flex flex-col sm:flex-row gap-3 max-w-md w-full">
<div class="flex flex-col gap-3 max-w-md w-full">
<!-- Row 1: postcode + button -->
<div class="flex flex-col sm:flex-row gap-3">
<div class="relative flex-1">
<span class="absolute left-4 top-1/2 -translate-y-1/2 text-zinc-500">
<label for="postcode-input" class="sr-only">Postcode or city</label>
<span aria-hidden="true"
class="absolute right-4 top-1/2 -translate-y-1/2 text-zinc-500 p-4"
>
<iconify-icon icon="lucide:map-pin" style="font-size:1.25rem"></iconify-icon>
</span>
<input
id="postcode-input"
v-model="postcode"
@input="onInput"
type="text"
placeholder="Enter postcode, e.g. SW1A 1AA"
class="w-full h-14 pl-12 pr-4 bg-white border border-zinc-300 rounded-xl focus:outline-none focus:ring-2 focus:ring-accent shadow-inner text-base"
class="w-full h-14 pr-12 pl-4 bg-white border border-zinc-300 rounded-xl focus:outline-none focus:ring-2 focus:ring-accent shadow-inner text-base"
@keyup.enter="onSearch"
/>
</div>
<button
@click="emit('search', postcode)"
@click="onSearch"
:disabled="!postcode.trim()"
class="h-14 px-8 bg-accent text-white rounded-xl font-bold text-base shadow-xl hover:bg-accent-content transition-all disabled:opacity-50 disabled:cursor-not-allowed"
class="h-14 px-8 bg-primary text-white rounded-xl font-bold text-base shadow-xl hover:bg-primary-dark transition-all disabled:cursor-not-allowed"
>
Find Prices
</button>
</div>
<!-- Row 2: fuel type + radius + sort -->
<div class="grid grid-cols-3 gap-2">
<select
v-model="fuelType"
aria-label="Fuel type"
class="min-w-0 h-10 px-2 bg-white border border-zinc-300 rounded-xl text-sm font-medium text-zinc-700 focus:outline-none focus:ring-2 focus:ring-accent truncate"
>
<option value="e10">Petrol (E10)</option>
<option value="e5">Premium (E5)</option>
<option value="b7_standard">Diesel (B7)</option>
<option value="b7_premium">Prem Diesel</option>
<option value="b10">Diesel (B10)</option>
<option value="hvo">HVO</option>
</select>
<select
v-model="radius"
aria-label="Search radius"
class="min-w-0 h-10 px-2 bg-white border border-zinc-300 rounded-xl text-sm font-medium text-zinc-700 focus:outline-none focus:ring-2 focus:ring-accent"
>
<option :value="2">2 miles</option>
<option :value="5">5 miles</option>
<option :value="10">10 miles</option>
<option :value="20">20 miles</option>
</select>
<select
v-model="sort"
aria-label="Sort by"
class="min-w-0 h-10 px-2 bg-white border border-zinc-300 rounded-xl text-sm font-medium text-zinc-700 focus:outline-none focus:ring-2 focus:ring-accent"
>
<option value="price">Price</option>
<option value="distance">Distance</option>
<option value="updated">Updated</option>
<option value="brand">Brand</option>
<option value="reliable">Reliable</option>
</select>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue'
const emit = defineEmits(['search'])
const postcode = ref('')
let debounceTimer = null
function onInput() {
clearTimeout(debounceTimer)
debounceTimer = setTimeout(() => {
if (postcode.value.trim().length >= 2) {
emit('search', postcode.value.trim())
}
}, 400)
const postcode = ref('')
const fuelType = ref('e10')
const radius = ref(10)
const sort = ref('price')
function onSearch() {
if (!postcode.value.trim()) return
emit('search', {
postcode: postcode.value.trim(),
fuelType: fuelType.value,
radius: radius.value,
sort: sort.value,
})
}
</script>

View File

@@ -49,6 +49,8 @@ const sortOptions = [
{ label: 'Price', value: 'price' },
{ label: 'Distance', value: 'distance' },
{ label: 'Updated', value: 'updated' },
{ label: 'Brand', value: 'brand' },
{ label: 'Reliable', value: 'reliable' },
]
const lowestPrice = computed(() => {

View File

@@ -7,7 +7,7 @@ export function useStations() {
const loading = ref(false)
const error = ref(null)
async function search({ postcode, lat, lng, fuelType = 'petrol', radius = 10, sort = 'price' }) {
async function search({ postcode, lat, lng, fuelType = 'e10', radius = 10, sort = 'price' }) {
loading.value = true
error.value = null
stations.value = []

View File

@@ -30,15 +30,15 @@
</nav>
<!-- Hero -->
<section id="hero" class="relative pt-12 md:pt-40 pb-12 md:pb-24 px-6 hero-gradient overflow-hidden">
<section id="hero" class="relative pt-24 md:pt-40 pb-12 md:pb-24 px-6 hero-gradient overflow-hidden">
<div class="max-w-7xl mx-auto grid lg:grid-cols-2 gap-16 items-center">
<div class="space-y-8">
<div class="inline-flex items-center gap-2 px-3 py-1 bg-accent/10 text-accent rounded-full text-xs font-bold uppercase tracking-wider">
<iconify-icon icon="lucide:sparkles"></iconify-icon>
Save up to £250/year on fuel
</div>
<h1 class="text-5xl md:text-7xl font-black font-display text-zinc-800 leading-[1.1] tracking-tighter">
Stop Overpaying <br><span class="text-accent">for Fuel.</span>
<h1 class="text-4xl sm:text-5xl md:text-7xl font-black font-display text-zinc-800 leading-[1.1] tracking-tighter">
Stop Overpaying <br class="hidden sm:block"><span class="text-accent">for Fuel.</span>
</h1>
<p class="text-xl text-zinc-500 max-w-lg leading-relaxed">
Join 50,000+ UK drivers using real-time insights to find the cheapest petrol and time their fill-ups perfectly.
@@ -57,7 +57,7 @@
</div>
<!-- Visual mockup card -->
<div class="relative hidden md:block">
<div class="relative hidden lg:block">
<div class="absolute -inset-4 bg-accent/5 rounded-[2.5rem] blur-2xl"></div>
<div class="relative glass-card p-6 rounded-[2rem] shadow-2xl space-y-4 max-w-md mx-auto transform rotate-2">
<div class="flex justify-between items-center mb-4">
@@ -93,6 +93,39 @@
</div>
</section>
<!-- Search Results -->
<section v-if="searchAttempted" class="px-6 py-10 bg-zinc-100">
<div class="max-w-7xl mx-auto space-y-6">
<!-- Loading -->
<div v-if="loading" class="flex items-center justify-center py-16">
<div class="flex items-center gap-3 text-zinc-500">
<iconify-icon icon="lucide:loader-circle" class="animate-spin text-2xl text-accent"></iconify-icon>
<span class="font-medium">Finding stations near you</span>
</div>
</div>
<!-- Error -->
<div v-else-if="error" class="flex items-center gap-3 p-4 bg-white border border-zinc-300 rounded-xl text-status-bad">
<iconify-icon icon="lucide:circle-alert" style="font-size:1.25rem"></iconify-icon>
<span class="font-medium">{{ Object.values(error).flat()[0] ?? 'Unable to load stations. Please try again.' }}</span>
</div>
<!-- Results -->
<template v-else>
<div v-if="!stations.length" class="flex items-center gap-3 p-4 bg-white border border-zinc-300 rounded-xl text-zinc-500">
<iconify-icon icon="lucide:map-pin-off" style="font-size:1.25rem"></iconify-icon>
<span class="font-medium">No stations found near you. Try a different postcode or increase the radius.</span>
</div>
<template v-else>
<LeafletMap :stations="stations" :default-open="true" />
<StationList :stations="stations" :current-sort="sort" @sort="onSort" />
</template>
</template>
</div>
</section>
<!-- How It Works -->
<section id="how-it-works" class="py-12 md:py-24 px-6 bg-zinc-50">
<div class="max-w-7xl mx-auto">
@@ -376,14 +409,32 @@
</template>
<script setup>
import { RouterLink, useRouter } from 'vue-router'
import { ref } from 'vue'
import { RouterLink } from 'vue-router'
import { useAuth } from '../composables/useAuth.js'
import { useStations } from '../composables/useStations.js'
import SearchBar from '../components/SearchBar.vue'
import LeafletMap from '../components/LeafletMap.vue'
import StationList from '../components/StationList.vue'
const { isAuthenticated } = useAuth()
const router = useRouter()
const { stations, loading, error, search } = useStations()
function onSearch(postcode) {
router.push({ path: '/dashboard', query: { postcode } })
const sort = ref('price')
const lastParams = ref(null)
const searchAttempted = ref(false)
async function onSearch(params) {
lastParams.value = params
sort.value = params.sort ?? sort.value
searchAttempted.value = true
await search(params)
}
async function onSort(newSort) {
sort.value = newSort
if (lastParams.value) {
await search({ ...lastParams.value, sort: newSort })
}
}
</script>