diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 79def5b7..f4b9c02f 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -20,7 +20,7 @@ import { useSignalR } from '@/composables/useSignalR' import { useGatewayStatus } from '@/composables/useGatewayStatus' import { useSettledAvailability } from '@/composables/useSettledAvailability' import { useFavicon } from '@/composables/useFavicon' -import { usePageTitle } from '@/composables/usePageTitle' +import { APP_NAME, usePageTitle } from '@/composables/usePageTitle' import { useScreenWakeLock } from '@/composables/useScreenWakeLock' import { usePhoneGpsRecorder } from '@/composables/usePhoneGpsRecorder' import { useRelativeTime } from '@/composables/useRelativeTime' @@ -257,10 +257,11 @@ watch( > - + - GarageStack + +
diff --git a/frontend/src/assets/main.css b/frontend/src/assets/main.css index e7006adb..fd706415 100644 --- a/frontend/src/assets/main.css +++ b/frontend/src/assets/main.css @@ -1019,6 +1019,26 @@ body, padding-inline: 0.65rem; } + /* The heading has gone up to the top bar, so the row keeps the caption, the info button and the + actions, all on one middle. */ + .view-header { + align-items: center; + } + + .view-header__caption { + margin: 0; + } + + .view-header__info { + width: var(--touch-target); + height: var(--touch-target); + } + + /* First in its row, its icon starts on the cards' left edge. */ + .view-header__info:first-child { + margin-left: calc((1rem - var(--touch-target)) / 2); + } + .sidebar-meta .app-footer__meta { flex-wrap: wrap; gap: 0.5rem; diff --git a/frontend/src/assets/map.css b/frontend/src/assets/map.css index f193984b..2ca5590e 100644 --- a/frontend/src/assets/map.css +++ b/frontend/src/assets/map.css @@ -60,6 +60,55 @@ margin-bottom: 0; } +/* Only a wrapper to fold: the list's rows stay the sidebar's own flex items. */ +.trip-sidebar__body { + display: contents; +} + +/* Above the map the title folds the list away: drawn as the title itself across the header, with + a chevron at the end that points down while the list is open. */ +.trip-sidebar__title:has(.trip-sidebar__toggle) { + flex: 1; +} + +.trip-sidebar__toggle { + display: flex; + align-items: center; + gap: inherit; + width: 100%; + min-height: var(--touch-target); + margin-block: calc((1lh - var(--touch-target)) / 2); + padding: 0; + border: none; + background: none; + color: inherit; + font: inherit; + letter-spacing: inherit; + text-align: left; + text-transform: inherit; + cursor: pointer; +} + +.trip-sidebar__chevron { + margin-left: auto; + transition: transform 0.2s ease; +} + +.trip-sidebar__toggle[aria-expanded='false'] .trip-sidebar__chevron { + transform: rotate(-90deg); +} + +/* Folded, the sidebar is its title row and the map takes the rest. */ +.trip-sidebar--folded { + padding-bottom: 0; + overflow: hidden; +} + +.trip-sidebar--folded .trip-sidebar__header { + border-bottom: none; + padding-bottom: 1rem; +} + .trip-list { list-style: none; display: flex; @@ -388,6 +437,23 @@ color: var(--color-text); } +.map-control-btn:disabled { + background: var(--color-surface) padding-box; + color: var(--color-text-muted); + cursor: not-allowed; +} + +/* The map's own buttons on the right, level with the zoom control on the left: Find car. */ +.map-controls-end { + position: absolute; + top: 10px; + right: 10px; + z-index: var(--z-map-overlay); + display: flex; + flex-direction: column; + gap: 6px; +} + /* Status overlays on the map canvas: POI loading, trip snapping. Stacked in one column so two of them never land on top of each other. */ .map-pill-stack { diff --git a/frontend/src/assets/shell.css b/frontend/src/assets/shell.css index 9ed2cd6d..bf1050a0 100644 --- a/frontend/src/assets/shell.css +++ b/frontend/src/assets/shell.css @@ -76,17 +76,39 @@ background: var(--color-surface-2); } +/* The app's car, the way home. The page's heading beside it says where you are. */ .mobile-brand { display: flex; align-items: center; - gap: 0.5rem; - font-size: 1rem; - font-weight: 700; + justify-content: center; + width: var(--touch-target); + height: var(--touch-target); + flex-shrink: 0; + margin-left: calc(-1 * var(--topbar-icon-inset)); + font-size: var(--topbar-icon-size); color: var(--color-primary); + border-radius: 6px; text-decoration: none; +} + +.mobile-brand:hover { + background: var(--color-surface-2); +} + +/* The page's heading (ViewHeader moves it here on a phone), on one line: a long one ends in an + ellipsis rather than pushing the buttons off the bar. */ +.mobile-topbar__title { flex: 1; min-width: 0; +} + +.mobile-topbar__title h1 { + margin: 0; overflow: hidden; + font-size: 1.05rem; + font-weight: 700; + line-height: 1.3; + text-overflow: ellipsis; white-space: nowrap; } @@ -201,10 +223,27 @@ margin: 0.15rem 0 0; } -/* A line about the page, tucked under its title rather than spaced like a section of its own. */ -.view-subtitle { - margin-top: -1rem; - margin-bottom: 1.5rem; +/* The button that opens the line about the page, close beside the heading and as tall as its + line, so the actions keep their place on the right. */ +.view-header__info { + display: flex; + align-items: center; + justify-content: center; + width: var(--page-title-height); + height: var(--page-title-height); + margin-left: -0.5rem; + padding: 0; + border: none; + border-radius: 6px; + background: none; + color: var(--color-text-muted); + font-size: 1rem; + cursor: pointer; +} + +.view-header__info:hover { + background: var(--color-surface-2); + color: var(--color-text); } /* ── App footer ───────────────────────────────────────────── */ diff --git a/frontend/src/components/ViewHeader.vue b/frontend/src/components/ViewHeader.vue index 3bc9e6a8..223ac31f 100644 --- a/frontend/src/components/ViewHeader.vue +++ b/frontend/src/components/ViewHeader.vue @@ -1,27 +1,56 @@ diff --git a/frontend/src/components/__tests__/ViewHeader.spec.ts b/frontend/src/components/__tests__/ViewHeader.spec.ts new file mode 100644 index 00000000..44613e3e --- /dev/null +++ b/frontend/src/components/__tests__/ViewHeader.spec.ts @@ -0,0 +1,69 @@ +import { afterEach, describe, expect, it, vi } from 'vitest' +import { flushPromises, mount } from '@vue/test-utils' +import { createI18n } from 'vue-i18n' +import ViewHeader from '../ViewHeader.vue' +import en from '@/locales/en.json' +import { PHONE_MEDIA_QUERY } from '@/utils/viewport' + +vi.mock('@/components/OfflineNotice.vue', () => ({ default: { template: '
' } })) + +const i18n = createI18n({ legacy: false, locale: 'en', messages: { en } }) + +function mountHeader(props: { title: string; caption?: string; subtitle?: string }) { + return mount(ViewHeader, { + props, + attachTo: document.body, + global: { plugins: [i18n], stubs: { FontAwesomeIcon: true } }, + }) +} + +describe('ViewHeader', () => { + afterEach(() => { + vi.unstubAllGlobals() + document.body.innerHTML = '' + }) + + it('shows the heading and caption in its own row off a phone', () => { + const wrapper = mountHeader({ title: 'Map', caption: '27 Aug - 25 Nov 2026' }) + + expect(wrapper.get('.view-header h1').text()).toBe('Map') + expect(wrapper.get('.view-header__caption').text()).toBe('27 Aug - 25 Nov 2026') + }) + + it('offers no info button for a page without a line about it', () => { + const wrapper = mountHeader({ title: 'Map' }) + + expect(wrapper.find('.view-header__info').exists()).toBe(false) + }) + + it('opens the line about the page from its info button', async () => { + const wrapper = mountHeader({ title: 'Trip log', subtitle: 'Every trip, for the taxman.' }) + const info = wrapper.get('.view-header__info') + expect(info.attributes('aria-label')).toBe(en.common.aboutPage) + expect(document.body.textContent).not.toContain('Every trip, for the taxman.') + + await info.trigger('click') + + const dialog = document.querySelector('[role="dialog"]') + expect(dialog?.getAttribute('aria-label')).toBe('Trip log') + expect(dialog?.textContent).toContain('Every trip, for the taxman.') + }) + + it('puts the heading in the top bar on a phone, leaving the caption in the row', async () => { + vi.stubGlobal('matchMedia', (query: string) => ({ + matches: query === PHONE_MEDIA_QUERY, + media: query, + addEventListener: () => {}, + removeEventListener: () => {}, + })) + const topbar = document.body.appendChild(document.createElement('div')) + topbar.id = 'mobile-topbar-title' + + const wrapper = mountHeader({ title: 'Map', caption: '27 Aug - 25 Nov 2026' }) + await flushPromises() + + expect(topbar.querySelector('h1')?.textContent).toBe('Map') + expect(wrapper.find('.view-header h1').exists()).toBe(false) + expect(wrapper.get('.view-header__caption').text()).toBe('27 Aug - 25 Nov 2026') + }) +}) diff --git a/frontend/src/components/map/TripSidebar.vue b/frontend/src/components/map/TripSidebar.vue index 7a5cc2a9..65644589 100644 --- a/frontend/src/components/map/TripSidebar.vue +++ b/frontend/src/components/map/TripSidebar.vue @@ -1,6 +1,8 @@ diff --git a/frontend/src/components/map/__tests__/TripSidebar.spec.ts b/frontend/src/components/map/__tests__/TripSidebar.spec.ts index 4cbd2645..eece4637 100644 --- a/frontend/src/components/map/__tests__/TripSidebar.spec.ts +++ b/frontend/src/components/map/__tests__/TripSidebar.spec.ts @@ -1,8 +1,9 @@ -import { describe, it, expect, vi } from 'vitest' +import { afterEach, describe, it, expect, vi } from 'vitest' import { flushPromises, mount } from '@vue/test-utils' import { createI18n } from 'vue-i18n' import TripSidebar from '../TripSidebar.vue' import type { TripRow } from '@/utils/tripRows' +import { WIDE_MEDIA_QUERY } from '@/utils/viewport' const i18n = createI18n({ legacy: false, locale: 'en', missingWarn: false, fallbackWarn: false }) @@ -87,4 +88,41 @@ describe('TripSidebar', () => { expect(scrollBy).toHaveBeenCalledWith({ top: 360, behavior: 'instant' }) }) + + describe('folding above the map', () => { + afterEach(() => vi.unstubAllGlobals()) + + it('folds the list to its title and asks to keep it that way', async () => { + const wrapper = mountSidebar() + const toggle = wrapper.get('.trip-sidebar__toggle') + const body = wrapper.get('.trip-sidebar__body') + expect(toggle.attributes('aria-expanded')).toBe('true') + expect(toggle.attributes('aria-controls')).toBe(body.attributes('id')) + + await toggle.trigger('click') + + expect(wrapper.emitted('update:expanded')).toEqual([[false]]) + await wrapper.setProps({ expanded: false }) + expect(wrapper.get('.trip-sidebar').classes()).toContain('trip-sidebar--folded') + expect(toggle.attributes('aria-expanded')).toBe('false') + expect((body.element as HTMLElement).style.display).toBe('none') + + await toggle.trigger('click') + expect(wrapper.emitted('update:expanded')).toEqual([[false], [true]]) + }) + + it('keeps the list open beside the map, where folding would free nothing', () => { + vi.stubGlobal('matchMedia', (query: string) => ({ + matches: query === WIDE_MEDIA_QUERY, + media: query, + addEventListener: () => {}, + removeEventListener: () => {}, + })) + const wrapper = mountSidebar({ expanded: false }) + + expect(wrapper.find('.trip-sidebar__toggle').exists()).toBe(false) + expect(wrapper.get('.trip-sidebar').classes()).not.toContain('trip-sidebar--folded') + expect((wrapper.get('.trip-sidebar__body').element as HTMLElement).style.display).toBe('') + }) + }) }) diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.json index 6f938efd..de5c8cd4 100644 --- a/frontend/src/locales/en.json +++ b/frontend/src/locales/en.json @@ -848,6 +848,7 @@ "higherIsBetter": "higher is better" }, "common": { + "aboutPage": "About this page", "apply": "Apply", "kwh": "kWh", "on": "On", diff --git a/frontend/src/locales/es.json b/frontend/src/locales/es.json index 7dc664c1..d2af5f99 100644 --- a/frontend/src/locales/es.json +++ b/frontend/src/locales/es.json @@ -848,6 +848,7 @@ "higherIsBetter": "más alto es mejor" }, "common": { + "aboutPage": "Acerca de esta página", "apply": "Aplicar", "kwh": "kWh", "on": "Encendido", diff --git a/frontend/src/locales/nl.json b/frontend/src/locales/nl.json index 8c8aed89..eecb0ea3 100644 --- a/frontend/src/locales/nl.json +++ b/frontend/src/locales/nl.json @@ -848,6 +848,7 @@ "higherIsBetter": "hoger beter is" }, "common": { + "aboutPage": "Over deze pagina", "apply": "Toepassen", "kwh": "kWh", "on": "Aan", diff --git a/frontend/src/locales/pt-PT.json b/frontend/src/locales/pt-PT.json index 49c838ad..fe57ce91 100644 --- a/frontend/src/locales/pt-PT.json +++ b/frontend/src/locales/pt-PT.json @@ -848,6 +848,7 @@ "higherIsBetter": "maior é melhor" }, "common": { + "aboutPage": "Sobre esta página", "apply": "Aplicar", "kwh": "kWh", "on": "Ligado", diff --git a/frontend/src/locales/pt.json b/frontend/src/locales/pt.json index 8c9d0be0..35a027c7 100644 --- a/frontend/src/locales/pt.json +++ b/frontend/src/locales/pt.json @@ -848,6 +848,7 @@ "higherIsBetter": "maior é melhor" }, "common": { + "aboutPage": "Sobre esta página", "apply": "Aplicar", "kwh": "kWh", "on": "Ligado", diff --git a/frontend/src/stores/__tests__/settingsStores.spec.ts b/frontend/src/stores/__tests__/settingsStores.spec.ts index 760d415b..48392772 100644 --- a/frontend/src/stores/__tests__/settingsStores.spec.ts +++ b/frontend/src/stores/__tests__/settingsStores.spec.ts @@ -667,6 +667,22 @@ describe('useMapSettingsStore', () => { expect(useMapSettingsStore().legendExpanded).toBe(false) }) + + it('remembers whether the trip list was folded, and leaves it open until then', async () => { + expect(useMapSettingsStore().tripListExpanded).toBeNull() + + useMapSettingsStore().tripListExpanded = false + await nextTick() + vi.advanceTimersByTime(SAVE_DEBOUNCE_MS) + setActivePinia(createPinia()) + + expect(useMapSettingsStore().tripListExpanded).toBe(false) + }) + + it('reads a stored trip list state that is not true or false as not chosen yet', () => { + localStorage.setItem(MAP_KEY, JSON.stringify({ tripListExpanded: 'yes' })) + expect(useMapSettingsStore().tripListExpanded).toBeNull() + }) }) describe('useDashboardSettingsStore', () => { diff --git a/frontend/src/stores/__tests__/settingsSync.spec.ts b/frontend/src/stores/__tests__/settingsSync.spec.ts index 5192e4c4..69a6217f 100644 --- a/frontend/src/stores/__tests__/settingsSync.spec.ts +++ b/frontend/src/stores/__tests__/settingsSync.spec.ts @@ -92,7 +92,7 @@ describe('settings kept on the account', () => { // here on. expect(Object.keys(changes).sort()).toEqual( Object.keys(map.$state) - .filter((key) => key !== 'legendExpanded') + .filter((key) => key !== 'legendExpanded' && key !== 'tripListExpanded') .sort(), ) expect(changes.heatmapEnabled).toBe(false) diff --git a/frontend/src/stores/settingsMap.ts b/frontend/src/stores/settingsMap.ts index e179d4de..7ba85cd7 100644 --- a/frontend/src/stores/settingsMap.ts +++ b/frontend/src/stores/settingsMap.ts @@ -30,6 +30,11 @@ interface MapSettings { * follows the screen. Kept per device, as a phone's map is too short for what suits a desktop. */ legendExpanded: boolean | null + /** + * Whether the trip list above a narrow map is open; null until it is folded or opened, when it + * is open. Kept per device, as only a narrow screen folds it. + */ + tripListExpanded: boolean | null } // A function rather than a constant: the lists in it are the store's own once loaded, and a @@ -55,6 +60,7 @@ function defaultsFor(): MapSettings { garagesEnabled: false, phoneGpsEnabled: true, legendExpanded: null, + tripListExpanded: null, } } @@ -90,6 +96,7 @@ function parseMapFields(parsed: Record): MapSettings { // On unless switched off, as the map drew phone points before this was a layer. phoneGpsEnabled: parsed.phoneGpsEnabled !== false, legendExpanded: typeof parsed.legendExpanded === 'boolean' ? parsed.legendExpanded : null, + tripListExpanded: typeof parsed.tripListExpanded === 'boolean' ? parsed.tripListExpanded : null, } } @@ -100,7 +107,7 @@ export const useMapSettingsStore = defineStore('settingsMap', () => { section: 'map', state: settings, parse: parseMapFields, - localKeys: ['legendExpanded'], + localKeys: ['legendExpanded', 'tripListExpanded'], }) return toRefs(settings) }) diff --git a/frontend/src/views/MapView.vue b/frontend/src/views/MapView.vue index 34c26539..affe1d80 100644 --- a/frontend/src/views/MapView.vue +++ b/frontend/src/views/MapView.vue @@ -253,6 +253,15 @@ const legendExpanded = computed({ }, }) +// Above the map, the trip list folds to its title to give the map its height. Open until it is +// folded, and then it stays that way on this device. +const tripListExpanded = computed({ + get: () => settingsStore.tripListExpanded ?? true, + set: (expanded: boolean) => { + settingsStore.tripListExpanded = expanded + }, +}) + // ── Drawing ──────────────────────────────────────────────────────────────────── const tripLayers = useTripLayers({ map: mapInstance, @@ -434,16 +443,13 @@ onMounted(async () => { :speed-cameras-available="speedCamerasAvailable" :phone-gps-available="phoneGpsAvailable" /> -
{ +
+ +
+