feat: expand station cards with detailed information and add live statistics endpoint
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

- Add `/stats/live` endpoint returning station count and latest price timestamp with 5-minute cache
- Transform StationCard into expandable component with click/keyboard interaction showing full details
- Display brand label, badges (24h/Supermarket/Motorway), fuel types, amenities, opening hours, and price delta vs average
- Add brand filter dropdown to StationList with dynamic brand extraction from results
- Calculate and display price comparison against filtered stations average
- Redesign map markers to simpler price display; move directions link to popup alongside station details
- Add "locate-me" button to SearchBar for geolocation trigger
- Show "Live" indicator with station count and last-update time on homepage hero
- Remove standalone directions link from marker HTML; consolidate in popup with click propagation handling
- Persist `avgPence` calculation across StationList and pass to cards for delta display
- Add `@iconify-json/lucide` dev dependency and register collection on app mount
- Stop click propagation on card action buttons (directions, remove)
This commit is contained in:
Ovidiu U
2026-04-20 18:58:13 +01:00
parent c2466e5a61
commit 831637380c
14 changed files with 438 additions and 48 deletions

View File

@@ -1,4 +1,4 @@
# FuelAlert — Claude Code Instructions
# Fuel Price — Claude Code Instructions
UK fuel price intelligence app. Subscribers receive fill-up timing recommendations
based on local price trends. Built solo by a PHP/Laravel developer.

View File

@@ -74,7 +74,6 @@ class StationController extends Controller
: $filtered->sortBy(match ($sort) {
'price' => fn ($s) => (int) $s->price_pence,
'updated' => fn ($s) => $s->price_effective_at ? -strtotime($s->price_effective_at) : PHP_INT_MAX,
'brand' => fn ($s) => strtolower((string) $s->brand_name),
default => fn ($s) => (float) $s->distance_km,
})->values();

View File

@@ -4,11 +4,33 @@ namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\Search;
use App\Models\Station;
use App\Models\StationPrice;
use Carbon\CarbonImmutable;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
class StatsController extends Controller
{
public function live(): JsonResponse
{
$payload = Cache::remember('api:stats:live', now()->addMinutes(5), function (): array {
$stationCount = Station::query()
->where('permanent_closure', false)
->count();
$latestPriceAt = StationPrice::query()->max('recorded_at');
return [
'station_count' => $stationCount,
'latest_price_at' => $latestPriceAt ? CarbonImmutable::parse($latestPriceAt)->toIso8601String() : null,
];
});
return response()->json($payload);
}
public function searches(Request $request): JsonResponse
{
$period = $request->input('period', 'week');

View File

@@ -20,12 +20,16 @@ class StationResource extends JsonResource
'name' => $this->trading_name,
'brand' => $this->brand_name,
'is_supermarket' => (bool) $this->is_supermarket,
'is_motorway' => (bool) $this->is_motorway_service_station,
'address' => implode(', ', array_filter([$this->address_line_1, $this->city])),
'postcode' => $this->postcode,
'lat' => (float) $this->lat,
'lng' => (float) $this->lng,
'distance_km' => round((float) $this->distance_km, 2),
'fuel_type' => $this->fuel_type,
'fuel_types_available' => $this->fuel_types ?? [],
'amenities' => $this->amenities ?? [],
'open_today' => $this->openTodayPayload(),
'price_pence' => (int) $this->price_pence,
'price' => round((int) $this->price_pence / 100, 2),
'price_updated_at' => $this->price_effective_at
@@ -37,4 +41,50 @@ class StationResource extends JsonResource
'reliability_label' => $reliability->label(),
];
}
/**
* @return array{is_24_hours: bool, open: ?string, close: ?string, is_open_now: bool}|null
*/
private function openTodayPayload(): ?array
{
$times = $this->opening_times;
if (! is_array($times) || empty($times['usual_days'])) {
return null;
}
$now = Carbon::now('Europe/London');
$dayKey = strtolower($now->format('l'));
$today = $times['usual_days'][$dayKey] ?? null;
if (! is_array($today)) {
return null;
}
$is24 = (bool) ($today['is_24_hours'] ?? false);
$open = $today['open'] ?? null;
$close = $today['close'] ?? null;
return [
'is_24_hours' => $is24,
'open' => $open ? substr($open, 0, 5) : null,
'close' => $close ? substr($close, 0, 5) : null,
'is_open_now' => $this->computeIsOpenNow($is24, $open, $close, $now),
];
}
private function computeIsOpenNow(bool $is24, ?string $open, ?string $close, Carbon $now): bool
{
if ($is24) {
return true;
}
if (! $open || ! $close) {
return false;
}
$current = $now->format('H:i:s');
return $current >= $open && $current < $close;
}
}

13
package-lock.json generated
View File

@@ -18,6 +18,9 @@
"vue": "^3.5.32",
"vue-router": "^4.6.4"
},
"devDependencies": {
"@iconify-json/lucide": "^1.2.102"
},
"optionalDependencies": {
"@rollup/rollup-linux-x64-gnu": "4.9.5",
"@tailwindcss/oxide-linux-x64-gnu": "^4.0.1",
@@ -101,6 +104,16 @@
"tslib": "^2.4.0"
}
},
"node_modules/@iconify-json/lucide": {
"version": "1.2.102",
"resolved": "https://registry.npmjs.org/@iconify-json/lucide/-/lucide-1.2.102.tgz",
"integrity": "sha512-Dm3EEqu5NrmzyDMB2U1+8yroEj2/dB9V4KlH0m/szwwF/ofSf0cPaGTZqkd1aExXjCor+vU53ttRMCGuXf+/cg==",
"dev": true,
"license": "ISC",
"dependencies": {
"@iconify/types": "*"
}
},
"node_modules/@iconify/types": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@iconify/types/-/types-2.0.0.tgz",

View File

@@ -24,5 +24,8 @@
"@rollup/rollup-linux-x64-gnu": "4.9.5",
"@tailwindcss/oxide-linux-x64-gnu": "^4.0.1",
"lightningcss-linux-x64-gnu": "^1.29.1"
},
"devDependencies": {
"@iconify-json/lucide": "^1.2.102"
}
}

View File

@@ -1,6 +1,10 @@
import 'iconify-icon'
import { addCollection } from 'iconify-icon'
import lucideIcons from '@iconify-json/lucide/icons.json'
import { createApp } from 'vue'
import App from './App.vue'
import router from './router/index.js'
addCollection(lucideIcons)
createApp(App).use(router).mount('#app')

View File

@@ -63,20 +63,17 @@ function buildDirectionsUrl(station, origin) {
return base
}
function buildMarkerHtml(station, index, colour, borderColour, origin) {
function buildMarkerHtml(station, index, colour, borderColour) {
const isFirst = index === 0
const w = isFirst ? 46 : 40
const h = isFirst ? 20 : 18
const fontSize = isFirst ? 11 : 10
const iconSize = isFirst ? 11 : 10
const star = isFirst
? `<span style="margin-right:2px;color:#facc15;font-size:10px;line-height:1;">★</span>`
: ''
const directionsUrl = escHtml(buildDirectionsUrl(station, origin))
const navSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="${iconSize}" height="${iconSize}" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polygon points="3 11 22 2 13 21 11 13 3 11"/></svg>`
return `<div style="display:inline-flex;align-items:center;height:${h}px;padding:0 4px 0 6px;background:${colour};color:#fff;font-weight:700;font-size:${fontSize}px;line-height:1;letter-spacing:-0.2px;border-radius:10px;border:1.5px solid ${borderColour};box-shadow:0 1px 3px rgba(0,0,0,0.25);white-space:nowrap;gap:3px;">
${star}<span>${Number(station.price).toFixed(1)}</span><a data-directions href="${directionsUrl}" target="_blank" rel="noopener" aria-label="Directions" style="display:inline-flex;align-items:center;justify-content:center;width:${h - 6}px;height:${h - 6}px;margin-left:1px;border-radius:50%;background:rgba(255,255,255,0.22);color:#fff;text-decoration:none;">${navSvg}</a>
return `<div style="display:inline-flex;align-items:center;justify-content:center;width:${w}px;height:${h}px;padding:0 5px;background:${colour};color:#fff;font-weight:700;font-size:${fontSize}px;line-height:1;letter-spacing:-0.2px;border-radius:10px;border:1.5px solid ${borderColour};box-shadow:0 1px 3px rgba(0,0,0,0.25);white-space:nowrap;">
${star}${Number(station.price).toFixed(1)}
</div>`
}
@@ -197,24 +194,31 @@ function renderMarkers() {
? '<span style="display:inline-block;background:#84cc16;color:#fff;font-size:10px;padding:1px 5px;border-radius:3px;margin-left:4px;">Supermarket</span>'
: ''
const directionsUrl = escHtml(buildDirectionsUrl(station, props.origin))
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>
<div style="min-width:180px">
<div style="display:flex;align-items:flex-start;justify-content:space-between;gap:8px;">
<div style="min-width:0;flex:1;">
<strong style="font-size:13px">${escHtml(station.name)}</strong>${supermarketTag}
</div>
<a data-directions href="${directionsUrl}" target="_blank" rel="noopener" aria-label="Directions" style="display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;flex-shrink:0;border-radius:8px;;color:black;text-decoration:none;"><iconify-icon icon="lucide:navigation" style="font-size:16px;"></iconify-icon></a>
</div>
<div style="margin-top:4px;"><span style="font-size:20px;font-weight:700;color:${escHtml(colour)}">${Number(station.price).toFixed(1)}p</span></div>
<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 ? 65 : 56
const w = isFirst ? 46 : 40
const h = isFirst ? 20 : 18
const icon = L.divIcon({
className: '',
iconSize: [w, h],
iconAnchor: [w / 2, h / 2],
html: buildMarkerHtml(station, index, colour, borderColour, props.origin),
html: buildMarkerHtml(station, index, colour, borderColour),
})
const marker = L.marker([station.lat, station.lng], {icon}).bindPopup(popup)
@@ -224,6 +228,11 @@ function renderMarkers() {
mapInstance.setView([station.lat, station.lng], target, {animate: true})
})
marker.on('popupopen', (e) => {
const link = e.popup.getElement()?.querySelector('a[data-directions]')
if (link) L.DomEvent.disableClickPropagation(link)
})
markersLayer.addLayer(marker)
bounds.push([station.lat, station.lng])
})

View File

@@ -13,8 +13,8 @@
type="button"
@click="useMyLocation"
>
<iconify-icon :class="{ 'animate-spin': locating }" :icon="locating ? 'lucide:loader-circle' : 'lucide:map-pin'" style="font-size:1rem"></iconify-icon>
<span class="hidden md:inline-flex">Near me</span>
<iconify-icon icon="lucide:locate-fixed" style="font-size:16px;"></iconify-icon>
<span class="hidden sr-only">Near me</span>
</button>
<input
id="postcode-input"
@@ -65,7 +65,6 @@
<option value="price">Price</option>
<option value="distance">Distance</option>
<option value="updated">Updated</option>
<option value="brand">Brand</option>
</select>
</div>
</div>

View File

@@ -1,12 +1,32 @@
<template>
<div class="bg-zinc-50 p-4 rounded-xl border border-zinc-300 shadow-sm flex flex-col gap-4">
<div
:aria-expanded="expanded"
:class="[
'bg-zinc-50 p-4 rounded-xl border shadow-sm flex flex-col gap-4 cursor-pointer transition-colors',
expanded ? 'border-accent' : 'border-zinc-300 hover:border-zinc-400',
]"
role="button"
tabindex="0"
@click="toggle"
@keydown.enter.prevent="toggle"
@keydown.space.prevent="toggle"
>
<div class="flex justify-between items-start gap-3">
<div class="space-y-0.5 min-w-0 flex-1">
<h4 class="font-bold text-lg text-zinc-800 truncate">{{ station.name }}</h4>
<p class="text-xs text-zinc-500 flex items-center gap-1">
<iconify-icon class="text-xs" icon="lucide:map-pin"></iconify-icon>
<span class="truncate">{{ locationLine }}</span>
<p v-if="brandLabel" class="text-[10px] font-black uppercase tracking-widest text-zinc-500">
{{ brandLabel }}
</p>
<h4 class="font-bold text-lg text-zinc-800 truncate">{{ station.name }}</h4>
<template v-if="!expanded">
<p class="text-xs text-zinc-500 flex items-center gap-1">
<iconify-icon class="text-xs" icon="lucide:map-pin"></iconify-icon>
<span class="truncate">{{ locationLine }}</span>
</p>
<p v-if="updatedAgo" :class="[priceColor, 'text-xs flex items-center gap-1 font-semibold']">
<iconify-icon class="text-xs" icon="lucide:clock"></iconify-icon>
<span>Updated {{ updatedAgo }}</span>
</p>
</template>
</div>
<a
:href="directionsUrl"
@@ -14,25 +34,94 @@
class="hidden md:inline-flex w-10 h-10 items-center justify-center rounded-lg bg-accent/10 text-accent active:bg-accent/20 flex-shrink-0"
rel="noopener"
target="_blank"
@click.stop
>
<iconify-icon class="text-lg" icon="lucide:navigation"></iconify-icon>
</a>
<div class="text-right flex-shrink-0">
<div class="text-right shrink-0">
<div :class="priceColor" class="text-xl font-black">
{{ station.price }}<span class="text-sm font-bold uppercase ml-0.5">p</span>
</div>
<p :class="priceColor" class="text-[10px] font-bold uppercase tracking-wider">
{{ statusLabel }}
</p>
<p v-if="priceDelta" :class="priceDeltaColor" class="text-[10px] font-bold mt-0.5">
{{ priceDelta }}
</p>
</div>
</div>
<Transition
enter-active-class="transition duration-200 ease-out"
enter-from-class="opacity-0 -translate-y-1"
enter-to-class="opacity-100 translate-y-0"
leave-active-class="transition duration-150 ease-in"
leave-from-class="opacity-100"
leave-to-class="opacity-0"
>
<div v-if="expanded" class="border-t border-zinc-200 pt-3 space-y-3">
<div v-if="badges.length" class="flex flex-wrap gap-1.5">
<span
v-for="badge in badges"
:key="badge.label"
:class="[badge.class, 'inline-flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-bold uppercase tracking-wider']"
>
<iconify-icon v-if="badge.icon" :icon="badge.icon"></iconify-icon>
{{ badge.label }}
</span>
</div>
<div v-if="fuelTypes.length" class="flex flex-wrap gap-1.5">
<span
v-for="type in fuelTypes"
:key="type"
class="inline-block bg-zinc-200 text-zinc-600 text-[10px] font-bold px-2 py-0.5 rounded"
>
{{ type }}
</span>
</div>
<div class="flex flex-wrap items-center gap-2 text-xs text-zinc-500">
<span>{{ distanceMiles }} mi</span>
<span
v-if="openStatus"
:class="[
openChipClass,
'inline-flex items-center gap-1 px-2 py-0.5 rounded text-[11px] font-bold',
]"
>
<span
:class="[openDotClass, 'inline-block size-1.5 rounded-full']"
aria-hidden="true"
></span>
{{ openStatus }}
</span>
</div>
<div v-if="amenityItems.length" class="flex flex-wrap gap-3 text-xs text-zinc-500">
<span
v-for="item in amenityItems"
:key="item.key"
class="inline-flex items-center gap-1"
>
<iconify-icon :icon="item.icon" class="text-sm"></iconify-icon>
{{ item.label }}
</span>
</div>
<p class="text-[11px] text-zinc-400">
{{ fullAddress }}<span v-if="updatedAgo"> · Updated {{ updatedAgo }}</span>
</p>
</div>
</Transition>
<div class="flex items-center justify-end gap-2 md:hidden">
<button
v-if="removable"
aria-label="Remove"
class="w-10 h-10 flex items-center justify-center rounded-lg bg-zinc-200 text-zinc-500 active:bg-zinc-300"
type="button"
@click="emit('remove', station)"
@click.stop="emit('remove', station)"
>
<iconify-icon class="text-lg" icon="lucide:trash-2"></iconify-icon>
</button>
@@ -41,6 +130,7 @@
class="flex-1 h-10 flex items-center justify-center gap-2 rounded-lg bg-accent/10 text-accent font-bold text-sm active:bg-accent/20"
rel="noopener"
target="_blank"
@click.stop
>
<iconify-icon class="text-lg" icon="lucide:navigation"></iconify-icon>
Directions
@@ -51,7 +141,7 @@
aria-label="Remove"
class="w-10 h-10 flex items-center justify-center rounded-lg bg-zinc-200 text-zinc-500 active:bg-zinc-300"
type="button"
@click="emit('remove', station)"
@click.stop="emit('remove', station)"
>
<iconify-icon class="text-lg" icon="lucide:trash-2"></iconify-icon>
</button>
@@ -60,23 +150,50 @@
</template>
<script setup>
import { computed } from 'vue'
import { computed, ref } from 'vue'
const props = defineProps({
station: { type: Object, required: true },
lowestPrice: { type: Number, default: null },
avgPence: { type: Number, default: null },
removable: { type: Boolean, default: false },
origin: { type: Object, default: null },
})
const emit = defineEmits(['remove'])
const expanded = ref(false)
function toggle() {
expanded.value = !expanded.value
}
const RELIABILITY_MAP = {
reliable: { label: 'Current', color: 'text-status-good' },
stale: { label: 'Stale', color: 'text-status-warn' },
outdated: { label: 'Outdated', color: 'text-status-bad' },
}
const AMENITY_META = {
customer_toilets: { icon: 'lucide:toilet', label: 'WC' },
car_wash: { icon: 'lucide:spray-can', label: 'Wash' },
air_pump_or_screenwash: { icon: 'lucide:wind', label: 'Air' },
adblue_pumps: { icon: 'lucide:fuel', label: 'AdBlue' },
adblue_packaged: { icon: 'lucide:package', label: 'AdBlue' },
lpg_pumps: { icon: 'lucide:flame', label: 'LPG' },
water_filling: { icon: 'lucide:droplets', label: 'Water' },
}
const AMENITY_ORDER = [
'customer_toilets',
'car_wash',
'air_pump_or_screenwash',
'adblue_pumps',
'adblue_packaged',
'lpg_pumps',
'water_filling',
]
const reliabilityInfo = computed(() => RELIABILITY_MAP[props.station.reliability] ?? RELIABILITY_MAP.reliable)
const priceColor = computed(() => {
@@ -95,6 +212,21 @@ const locationLine = computed(() => {
return parts.join(' • ')
})
const fullAddress = computed(() => {
const parts = [props.station.address, props.station.postcode].filter(Boolean)
return parts.join(', ')
})
const updatedAgo = computed(() => {
if (!props.station.price_updated_at) return ''
const diffMin = Math.floor((Date.now() - new Date(props.station.price_updated_at)) / 60000)
if (diffMin < 60) return `${Math.max(diffMin, 0)}m ago`
const hours = Math.floor(diffMin / 60)
if (hours < 24) return `${hours}h ago`
const days = Math.floor(hours / 24)
return `${days} day${days === 1 ? '' : 's'} ago`
})
const directionsUrl = computed(() => {
const { lat, lng } = props.station
const base = `https://www.google.com/maps/dir/?api=1&destination=${lat},${lng}`
@@ -103,4 +235,77 @@ const directionsUrl = computed(() => {
}
return base
})
const brandLabel = computed(() => {
const brand = props.station.brand
if (!brand) return ''
if (brand === props.station.name) return ''
return brand
})
const badges = computed(() => {
const list = []
if (props.station.is_supermarket) {
list.push({ label: 'Supermarket', icon: 'lucide:shopping-cart', class: 'bg-lime-500/15 text-lime-700' })
}
if (props.station.open_today?.is_24_hours || props.station.amenities?.includes('twenty_four_hour_fuel')) {
list.push({ label: '24h', icon: 'lucide:clock', class: 'bg-zinc-800 text-white' })
}
if (props.station.is_motorway) {
list.push({ label: 'Motorway', icon: 'lucide:road', class: 'bg-blue-500/15 text-blue-700' })
}
return list
})
const fuelTypes = computed(() => {
const types = props.station.fuel_types_available
if (!Array.isArray(types)) return []
return types.map(t => t.replace('_STANDARD', '').replace('_PREMIUM', '+').toUpperCase())
})
const amenityItems = computed(() => {
const amenities = props.station.amenities
if (!Array.isArray(amenities)) return []
return AMENITY_ORDER
.filter(key => amenities.includes(key) && AMENITY_META[key])
.map(key => ({ key, ...AMENITY_META[key] }))
})
const openStatus = computed(() => {
const open = props.station.open_today
if (!open) return ''
if (open.is_24_hours) return ''
if (open.is_open_now) return open.close ? `Open until ${open.close}` : 'Open now'
return open.open ? `Closed — opens ${open.open}` : 'Closed'
})
const isOpenNow = computed(() => {
const open = props.station.open_today
return Boolean(open?.is_24_hours || open?.is_open_now)
})
const openChipClass = computed(() => (
isOpenNow.value
? 'bg-status-good/15 text-status-good'
: 'bg-status-bad/10 text-status-bad'
))
const openDotClass = computed(() => (
isOpenNow.value ? 'bg-status-good' : 'bg-status-bad'
))
const priceDelta = computed(() => {
if (props.avgPence == null) return ''
const delta = props.station.price_pence - props.avgPence
const pence = Math.abs(delta) / 100
if (pence < 0.1) return 'as expected'
return `${pence.toFixed(1)}p ${delta < 0 ? 'below' : 'above'} average`
})
const priceDeltaColor = computed(() => {
if (props.avgPence == null) return 'text-zinc-500'
if (props.station.price_pence < props.avgPence) return 'text-status-good'
if (props.station.price_pence > props.avgPence) return 'text-status-bad'
return 'text-zinc-500'
})
</script>

View File

@@ -1,13 +1,13 @@
<template>
<div class="space-y-3">
<!-- Sort tabs -->
<div class="flex gap-2 flex-wrap">
<!-- Sort tabs + brand filter -->
<div class="flex gap-2 flex-wrap items-center">
<button
v-for="option in sortOptions"
:key="option.value"
@click="emit('sort', option.value)"
:class="[
'px-4 py-1.5 rounded-full text-sm font-bold transition-colors',
'h-10 px-4 rounded-xl text-sm font-bold transition-colors',
currentSort === option.value
? 'bg-accent text-white'
: 'bg-white border border-zinc-300 text-zinc-500 hover:border-accent'
@@ -15,11 +15,23 @@
>
{{ option.label }}
</button>
<select
v-if="availableBrands.length > 1"
v-model="brandFilter"
aria-label="Filter by brand"
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="">All brands</option>
<option v-for="brand in availableBrands" :key="brand" :value="brand">{{ brand }}</option>
</select>
</div>
<!-- Count -->
<p class="text-sm text-zinc-500 font-medium">
{{ stations.length }} station{{ stations.length !== 1 ? 's' : '' }} found
{{ filteredStations.length }} station{{ filteredStations.length !== 1 ? 's' : '' }}
<span v-if="brandFilter">matching <strong>{{ brandFilter }}</strong></span>
<span v-else>found</span>
</p>
<!-- Grouped results when sorting by reliability -->
@@ -33,6 +45,7 @@
<StationCard
v-for="station in reliable"
:key="station.station_id"
:avg-pence="avgPence"
:lowest-price="lowestPrice"
:origin="origin"
:station="station"
@@ -49,7 +62,9 @@
<StationCard
v-for="station in stale"
:key="station.station_id"
:avg-pence="avgPence"
:lowest-price="lowestPrice"
:origin="origin"
:station="station"
class="mb-2"
/>
@@ -66,7 +81,9 @@
<StationCard
v-for="station in outdated"
:key="station.station_id"
:avg-pence="avgPence"
:lowest-price="lowestPrice"
:origin="origin"
:station="station"
class="mb-2"
/>
@@ -77,18 +94,19 @@
<!-- Flat list for other sort modes -->
<div v-else class="space-y-2">
<StationCard
v-for="station in stations"
v-for="station in filteredStations"
:key="station.station_id"
:station="station"
:avg-pence="avgPence"
:lowest-price="lowestPrice"
:origin="origin"
:station="station"
/>
</div>
</div>
</template>
<script setup>
import { computed } from 'vue'
import { computed, ref } from 'vue'
import StationCard from './StationCard.vue'
const props = defineProps({
@@ -99,21 +117,41 @@ const props = defineProps({
const emit = defineEmits(['sort'])
const brandFilter = ref('')
const sortOptions = [
{ label: 'Reliable', value: 'reliable' },
{ label: 'Price', value: 'price' },
{ label: 'Distance', value: 'distance' },
{ label: 'Updated', value: 'updated' },
{ label: 'Brand', value: 'brand' },
]
const reliable = computed(() => props.stations.filter(s => s.reliability === 'reliable'))
const stale = computed(() => props.stations.filter(s => s.reliability === 'stale'))
const outdated = computed(() => props.stations.filter(s => s.reliability === 'outdated'))
const availableBrands = computed(() => {
const brands = new Set()
props.stations.forEach(s => {
if (s.brand) brands.add(s.brand)
})
return [...brands].sort((a, b) => a.localeCompare(b))
})
const filteredStations = computed(() => {
if (!brandFilter.value) return props.stations
return props.stations.filter(s => s.brand === brandFilter.value)
})
const reliable = computed(() => filteredStations.value.filter(s => s.reliability === 'reliable'))
const stale = computed(() => filteredStations.value.filter(s => s.reliability === 'stale'))
const outdated = computed(() => filteredStations.value.filter(s => s.reliability === 'outdated'))
const lowestPrice = computed(() => {
if (!reliable.value.length && !props.stations.length) return null
const pool = reliable.value.length ? reliable.value : props.stations
if (!reliable.value.length && !filteredStations.value.length) return null
const pool = reliable.value.length ? reliable.value : filteredStations.value
return Math.min(...pool.map(s => s.price_pence))
})
const avgPence = computed(() => {
const prices = filteredStations.value.map(s => s.price_pence).filter(p => typeof p === 'number')
if (!prices.length) return null
return prices.reduce((a, b) => a + b, 0) / prices.length
})
</script>

View File

@@ -30,15 +30,19 @@
</nav>
<!-- Hero -->
<section id="hero" class="relative pt-24 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-6 md:pb-10 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 class="inline-flex items-center gap-2 px-3 py-1 text-accent text-xs tracking-wider">
<span class="inline-flex items-center gap-1.5 font-bold uppercase">
<span class="size-1.5 rounded-full bg-status-good animate-pulse"></span>
Live
</span>
<span v-if="liveStats.stationCount">· {{ formattedStationCount }} UK stations</span>
<span>· updated {{ updatedAgo || '…' }}</span>
</div>
<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>
Know exactly <br class="hidden sm:block"><span class="text-accent">when</span> to fuel.
</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.
@@ -46,14 +50,14 @@
<SearchBar :initial="searchInitial" @search="onSearch" />
<div class="flex items-center gap-4 pt-4">
<!-- <div class="flex items-center gap-4 pt-4">
<div class="flex -space-x-2">
<img alt="User" class="w-8 h-8 rounded-full border-2 border-white" src="https://api.dicebear.com/7.x/avataaars/svg?seed=1">
<img alt="User" class="w-8 h-8 rounded-full border-2 border-white" src="https://api.dicebear.com/7.x/avataaars/svg?seed=2">
<img alt="User" class="w-8 h-8 rounded-full border-2 border-white" src="https://api.dicebear.com/7.x/avataaars/svg?seed=3">
</div>
<span class="text-sm text-zinc-500 font-medium italic">"Saved me £12 on my first tank!"</span>
</div>
</div>-->
</div>
<!-- Visual mockup card -->
@@ -427,16 +431,58 @@
</template>
<script setup>
import { ref, computed, watch } from 'vue'
import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
import { RouterLink, useRoute, useRouter } from 'vue-router'
import { useAuth } from '../composables/useAuth.js'
import { useStations } from '../composables/useStations.js'
import api from '../axios.js'
import SearchBar from '../components/SearchBar.vue'
import LeafletMap from '../components/LeafletMap.vue'
import StationList from '../components/StationList.vue'
const { isAuthenticated, userTier } = useAuth()
const liveStats = ref({ stationCount: null, latestPriceAt: null })
const now = ref(Date.now())
let nowTicker = null
const formattedStationCount = computed(() => {
const n = liveStats.value.stationCount
return n == null ? '' : n.toLocaleString('en-GB')
})
const updatedAgo = computed(() => {
const iso = liveStats.value.latestPriceAt
if (!iso) return ''
const diffMin = Math.floor((now.value - new Date(iso).getTime()) / 60000)
if (diffMin < 1) return 'just now'
if (diffMin < 60) return `${diffMin} min ago`
const hours = Math.floor(diffMin / 60)
if (hours < 24) return `${hours} hr ago`
const days = Math.floor(hours / 24)
return `${days} day${days === 1 ? '' : 's'} ago`
})
onMounted(async () => {
try {
const { data } = await api.get('/stats/live')
liveStats.value = {
stationCount: data.station_count,
latestPriceAt: data.latest_price_at,
}
} catch {
// leave defaults; hero line degrades to "Live" only
}
nowTicker = setInterval(() => {
now.value = Date.now()
}, 60000)
})
onUnmounted(() => {
if (nowTicker) clearInterval(nowTicker)
})
const cadence = ref('monthly')
function ctaHref(tier) {

View File

@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>FuelAlert</title>
<title>{{ __('Welcome') }} - {{ config('app.name', 'Laravel') }}</title>
<script>
window['FUEL_TYPES'] = @json(
collect(App\Enums\FuelType::cases())

View File

@@ -20,6 +20,8 @@ Route::get('/fuel-types', function () {
->values());
});
Route::get('/stats/live', [StatsController::class, 'live']);
// Protected endpoints (API key required)
Route::middleware(['throttle:60,1', VerifyApiKey::class])->group(function (): void {
Route::get('/stations', [StationController::class, 'index']);