Skip to content

Commit 9732366

Browse files
author
Greg
committed
Demo: preselect the featured trip on a clean URL
/api/config now carries featured_sel (a new Store method; empty for real databases), and the app applies it once on first feed load when the URL has no ?sel=. Opening the demo at / lands directly in presentation view on the featured road trip — no query string needed. A shared ?sel= link still wins over the featured selection.
1 parent 335d93b commit 9732366

6 files changed

Lines changed: 23 additions & 3 deletions

File tree

src/db.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,9 @@ func classifyCharge(fast bool, geofence, addrName, city *string) (category, titl
398398
}
399399
}
400400

401+
// Featured preselection is a demo-mode concept; real data has none.
402+
func (d *DB) Featured() []string { return nil }
403+
401404
// ---- detail -------------------------------------------------------------------
402405

403406
func (d *DB) Detail(ctx context.Context, id string) (*Detail, error) {

src/demo.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ import (
1414
// demoStore generates deterministic synthetic data around a fictional area so
1515
// the app runs and renders with no database. No real locations are used.
1616
type demoStore struct {
17-
drives []demoDrive
18-
charges []demoCharge
19-
units string
17+
drives []demoDrive
18+
charges []demoCharge
19+
units string
20+
featured []string
2021
}
2122

2223
type demoDrive struct {
@@ -191,6 +192,7 @@ func (s *demoStore) addFeaturedTrip(now time.Time) {
191192
km: d.Km, durMin: d.DurMin, speedMax: d.SpeedMax,
192193
from: d.From, to: d.To, s0: d.S0, s1: d.S1, kwh: d.KWh, coords: d.Coords,
193194
})
195+
s.featured = append(s.featured, "d"+strconv.Itoa(1500+i))
194196
}
195197
for i, c := range trip.Charges {
196198
s.charges = append(s.charges, demoCharge{
@@ -199,9 +201,12 @@ func (s *demoStore) addFeaturedTrip(now time.Time) {
199201
category: "supercharger", title: c.Name,
200202
pt: []float64{c.Lng, c.Lat}, curve: c.Curve,
201203
})
204+
s.featured = append(s.featured, "c"+strconv.Itoa(2500+i))
202205
}
203206
}
204207

208+
func (s *demoStore) Featured() []string { return s.featured }
209+
205210
func (s *demoStore) Cars(ctx context.Context) ([]Car, error) {
206211
return []Car{{ID: 1, Name: "Demo", Model: "Model Y"}}, nil
207212
}

src/handlers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func registerAPI(mux *http.ServeMux, s Store, cfg Config) {
2424
"units": cfg.Units,
2525
"map_style_url": cfg.MapStyleURL,
2626
"demo": cfg.Demo,
27+
"featured_sel": s.Featured(),
2728
})
2829
})
2930

src/model.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ type Store interface {
3434
// Detail returns the panel payload for one activity id ("d123" / "c45"),
3535
// or nil when the id doesn't exist.
3636
Detail(ctx context.Context, id string) (*Detail, error)
37+
// Featured returns activity ids the UI should preselect on a fresh load
38+
// (no ?sel= in the URL). Empty outside demo mode.
39+
Featured() []string
3740
}
3841

3942
type Car struct {

src/web/src/App.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ export default function App() {
5252
const pendingShareRef = useRef<string[] | null>(
5353
new URLSearchParams(location.search).get('sel')?.split(',').filter(Boolean) ?? null,
5454
)
55+
// Without a shared link, the server's featured selection (demo mode's
56+
// showcase trip) is preselected once on the first feed load.
57+
const featuredDoneRef = useRef(false)
5558

5659
const [summary, setSummary] = useState<Summary | null>(null)
5760
const [activities, setActivities] = useState<Activity[]>([])
@@ -101,6 +104,10 @@ export default function App() {
101104
if (pendingShareRef.current) {
102105
setSelected(pendingShareRef.current)
103106
pendingShareRef.current = null
107+
featuredDoneRef.current = true
108+
} else if (!featuredDoneRef.current) {
109+
featuredDoneRef.current = true
110+
if (config.featured_sel?.length) setSelected(config.featured_sel)
104111
}
105112

106113
let all = first

src/web/src/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export type AppConfig = {
33
units: 'km' | 'mi'
44
map_style_url: string
55
demo: boolean
6+
featured_sel?: string[] | null
67
}
78

89
export type Car = { id: number; name: string; model?: string }

0 commit comments

Comments
 (0)