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
58 changes: 38 additions & 20 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import { useGatewayStatus } from '@/composables/useGatewayStatus'
import { useSettledAvailability } from '@/composables/useSettledAvailability'
import { useFavicon } from '@/composables/useFavicon'
import { usePageTitle } from '@/composables/usePageTitle'
import { useRefresh } from '@/composables/useRefresh'
import { useMediaQuery } from '@/composables/useMediaQuery'
import { PHONE_MEDIA_QUERY } from '@/utils/viewport'
import { useScreenWakeLock } from '@/composables/useScreenWakeLock'
import { usePhoneGpsRecorder } from '@/composables/usePhoneGpsRecorder'
import { useRelativeTime } from '@/composables/useRelativeTime'
Expand Down Expand Up @@ -182,6 +185,18 @@ const lastFetched = computed(() => {
return formatTime(d)
})

// On a phone, where the footer and its Refresh button are hidden, the menu's "Fetched" line asks
// the car for fresh data itself, its turning icon in the place the other lines have theirs.
const { canRefresh, refreshing, disabled: refreshDisabled, refresh } = useRefresh()
const isPhone = useMediaQuery(PHONE_MEDIA_QUERY)
const refreshFromMenu = computed(() => isPhone.value && canRefresh.value)
const refreshLineAttrs = computed(() => ({
type: 'button',
disabled: refreshDisabled.value,
title: t('control.refresh'),
'aria-label': t('control.refreshFetched', { time: lastFetched.value }),
}))

const lastRecorded = computed(() => {
const ts = vehicleStore.currentStatus?.recordedAt
if (!ts) return null
Expand Down Expand Up @@ -374,27 +389,30 @@ watch(
>
</template>
</div>
<!-- v-show, not v-if: AppFooter moves Refresh into this line on a phone, and a line
rebuilt after hiding would leave the button in the old one. -->
<div v-show="isInitialLoading || lastFetched" class="sidebar-timestamp">
<template v-if="isInitialLoading">
<span class="skeleton skeleton--icon" />
<span class="skeleton skeleton--text skeleton--text-sm" />
</template>
<template v-else>
<font-awesome-icon
icon="rotate"
class="sidebar-timestamp__icon"
:spin="vehicleStore.loading"
aria-hidden="true"
/>
<span class="sidebar-footer__text" :title="`${t('common.fetched')} ${lastFetched}`"
>{{ t('common.fetched') }} {{ lastFetched }}</span
>
</template>
<!-- Refresh, which AppFooter moves here on a phone: beside the time it renews. -->
<span id="sidebar-refresh" class="sidebar-timestamp__action" />
<div v-if="isInitialLoading" class="sidebar-timestamp">
<span class="skeleton skeleton--icon" />
<span class="skeleton skeleton--text skeleton--text-sm" />
</div>
<!-- On a phone the fetched time is also the way to renew it, as the footer and its
Refresh button are hidden there. -->
<component
:is="refreshFromMenu ? 'button' : 'div'"
v-else-if="lastFetched"
class="sidebar-timestamp"
:class="{ 'sidebar-timestamp--refresh': refreshFromMenu }"
v-bind="refreshFromMenu ? refreshLineAttrs : {}"
@click="refreshFromMenu && refresh()"
>
<font-awesome-icon
icon="rotate"
class="sidebar-timestamp__icon"
:spin="refreshing"
aria-hidden="true"
/>
<span class="sidebar-footer__text" :title="`${t('common.fetched')} ${lastFetched}`"
>{{ t('common.fetched') }} {{ lastFetched }}</span
>
</component>
<div v-if="isInitialLoading || lastRecorded" class="sidebar-timestamp">
<template v-if="isInitialLoading">
<span class="skeleton skeleton--icon" />
Expand Down
72 changes: 67 additions & 5 deletions frontend/src/__tests__/App.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const vehicle = vi.hoisted(() => ({
type: 'bev',
active: null as { id: number } | null,
status: null as { isAvailable: boolean | null } | null,
lastUpdated: null as Date | null,
}))
// What the routed page is keyed on, reactive so a test can play the list arriving or a switch.
const live = vi.hoisted(() => ({
Expand All @@ -45,7 +46,7 @@ vi.mock('@/stores/vehicle', async () => {
hasMultipleVehicles: false,
effectiveVehicleType: vehicle.type,
loading: false,
lastUpdated: null,
lastUpdated: vehicle.lastUpdated,
}),
}
})
Expand Down Expand Up @@ -89,6 +90,23 @@ vi.mock('@/composables/useBrowserNotifications', () => ({
useBrowserNotifications: () => ({ show: vi.fn<() => void>() }),
}))

const refreshing = vi.hoisted(() => ({
available: true,
refresh: vi.fn<() => void>(),
}))

vi.mock('@/composables/useRefresh', async () => {
const { computed } = await import('vue')
return {
useRefresh: () => ({
canRefresh: computed(() => refreshing.available),
refreshing: computed(() => false),
disabled: computed(() => false),
refresh: refreshing.refresh,
}),
}
})

vi.mock('@/composables/useFavicon', () => ({ useFavicon: vi.fn<() => void>() }))
vi.mock('@/composables/useScreenWakeLock', () => ({ useScreenWakeLock: vi.fn<() => void>() }))
vi.mock('@/composables/usePhoneGpsRecorder', () => ({ usePhoneGpsRecorder: vi.fn<() => void>() }))
Expand Down Expand Up @@ -177,13 +195,57 @@ describe('App top bar', () => {
expect(bar[0]?.classList.contains('hamburger')).toBe(true)
expect(bar[1]?.id).toBe('mobile-topbar-title')
})
})

describe('App fetched line', () => {
function screenIsPhone(phone: boolean) {
vi.stubGlobal('matchMedia', (query: string) => ({
matches: phone && query === '(width <= 767px)',
media: query,
addEventListener: () => {},
removeEventListener: () => {},
}))
}

afterEach(() => {
vi.unstubAllGlobals()
vehicle.lastUpdated = null
refreshing.available = true
refreshing.refresh.mockClear()
})

// The footer and its Refresh button are hidden on a phone: the time it was fetched renews it.
it('refreshes from the fetched line on a phone, its icon in the place the others have', async () => {
screenIsPhone(true)
vehicle.lastUpdated = new Date('2026-11-26T08:34:00')
const wrapper = await mountAt('/')

const line = wrapper.get('.sidebar-timestamp--refresh')
expect(line.element.tagName).toBe('BUTTON')
expect(line.attributes('aria-label')).toContain('control.refreshFetched')
expect(line.element.firstElementChild?.classList.contains('sidebar-timestamp__icon')).toBe(true)

await line.trigger('click')
expect(refreshing.refresh).toHaveBeenCalledOnce()
})

it('keeps the fetched line a plain line off a phone, where the footer refreshes', async () => {
screenIsPhone(false)
vehicle.lastUpdated = new Date('2026-11-26T08:34:00')
const wrapper = await mountAt('/')

expect(wrapper.find('.sidebar-timestamp--refresh').exists()).toBe(false)
expect(wrapper.text()).toContain('common.fetched')
})

// Refresh moves next to the time it renews, which stays in the page while it hides, so the
// button moved into it is never left in a removed line.
it('keeps a place for Refresh on the fetched line of the menu', async () => {
// No command reaches the car without the server, so the line offers none meanwhile.
it('keeps the fetched line a plain line without the server', async () => {
screenIsPhone(true)
refreshing.available = false
vehicle.lastUpdated = new Date('2026-11-26T08:34:00')
const wrapper = await mountAt('/')

expect(wrapper.find('.sidebar-timestamp #sidebar-refresh').exists()).toBe(true)
expect(wrapper.find('.sidebar-timestamp--refresh').exists()).toBe(false)
})
})

Expand Down
19 changes: 8 additions & 11 deletions frontend/src/assets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -980,18 +980,17 @@ body,
display: flex;
}

/* The footer's row goes back to the page: AppFooter moves Settings into the top bar, Refresh
into the menu beside the time it renews, and the copyright and update notice into the menu. */
/* The footer's row goes back to the page: AppFooter moves Settings into the top bar, and the
copyright and update notice into the menu, whose "Fetched" line refreshes. */
.app-footer {
display: none;
}

/* The top bar's buttons (the page's own from ViewHeader, then Settings) and Refresh in the menu
are drawn like the bell: an icon in a touch-sized square, no box. A page button's words stay
for screen readers and in its tooltip. */
/* The top bar's buttons (the page's own from ViewHeader, then Settings) are drawn like the bell:
an icon in a touch-sized square, no box. A page button's words stay for screen readers and in
its tooltip. */
.mobile-topbar .app-footer__btn,
.mobile-topbar .view-header__actions .btn,
.sidebar-timestamp__action .app-footer__btn {
.mobile-topbar .view-header__actions .btn {
width: var(--touch-target);
height: var(--touch-target);
padding: 0;
Expand All @@ -1004,8 +1003,7 @@ body,
}

.mobile-topbar .app-footer__btn:hover,
.mobile-topbar .view-header__actions .btn:hover,
.sidebar-timestamp__action .app-footer__btn:hover {
.mobile-topbar .view-header__actions .btn:hover {
background: var(--color-surface-2);
color: var(--color-text);
}
Expand All @@ -1019,8 +1017,7 @@ body,
color: var(--color-success);
}

.mobile-topbar .app-footer__btn-label,
.sidebar-timestamp__action .app-footer__btn-label {
.mobile-topbar .app-footer__btn-label {
display: none;
}

Expand Down
36 changes: 25 additions & 11 deletions frontend/src/assets/shell.css
Original file line number Diff line number Diff line change
Expand Up @@ -443,19 +443,33 @@
white-space: nowrap;
}

/* Refresh, which AppFooter moves here on a phone, at the end of the line with the time it renews.
It reaches into the line's padding, so the line grows no more than the touch target needs. */
.sidebar-timestamp__action {
display: flex;
margin-block: -0.25rem;
margin-left: auto;
margin-right: -0.5rem;
/* On a phone the "Fetched" line is the Refresh button (App.vue). Its icon and words stay where the
lines around it have theirs; what marks it as something to press is its icon in the accent
colour and a soft rounded ground, as tall as a finger needs, that brightens under a press. */
.sidebar-timestamp--refresh {
width: 100%;
min-height: var(--touch-target);
margin-block: 0.25rem;
border: none;
border-radius: 6px;
background: var(--field-bg);
font-family: inherit;
text-align: left;
cursor: pointer;
}

.sidebar-timestamp--refresh .sidebar-timestamp__icon {
color: var(--color-primary-light);
}

.sidebar-timestamp--refresh:hover:not(:disabled) {
background: var(--color-surface-2);
color: var(--color-text);
}

/* The line's own turning icon gives way to the button, which turns while a refresh runs. Its place
stays, so the text keeps in line with the lines under it. */
.sidebar-timestamp:has(.sidebar-timestamp__action > *) .sidebar-timestamp__icon {
visibility: hidden;
/* While a refresh runs the icon turns; the line waits rather than greying out. */
.sidebar-timestamp--refresh:disabled {
cursor: progress;
}

.sidebar-user__email {
Expand Down
49 changes: 17 additions & 32 deletions frontend/src/components/AppFooter.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<script setup lang="ts">
import { computed, nextTick, shallowRef } from 'vue'
import { nextTick, shallowRef } from 'vue'
import { useI18n } from 'vue-i18n'
import { useVehicleStore } from '@/stores/vehicle'
import { useVehicleCommand } from '@/composables/useVehicleCommand'
import { useConnection } from '@/composables/useConnection'
import { useRefresh } from '@/composables/useRefresh'
import { useModal } from '@/composables/useModal'
import { useUpdateNotice } from '@/composables/useUpdateNotice'
import { useMediaQuery } from '@/composables/useMediaQuery'
Expand All @@ -12,11 +10,8 @@ import { APP_VERSION } from '@/utils/appVersion'
import type SettingsModalComponent from './settings/SettingsModal.vue'

const { t } = useI18n()
const vehicleStore = useVehicleStore()
const { sending, send } = useVehicleCommand()
// Without the server no command reaches the car: the controls are hidden meanwhile.
const connection = useConnection()
const canSend = computed(() => connection.reachable)
// Without the server no command reaches the car: Refresh is hidden meanwhile.
const { canRefresh, refreshing, disabled: refreshDisabled, refresh } = useRefresh()
const { isOpen: modalOpen, open: showModal, close: closeModal } = useModal()
const { notice: updateNotice } = useUpdateNotice()

Expand All @@ -37,17 +32,10 @@ async function openModal() {
// Joined in script rather than the template, which drops a whitespace-only text node before the version
const copyrightLabel = ['© 2026 GarageStack', APP_VERSION].filter(Boolean).join(' ')

const vin = computed(() => vehicleStore.activeVin)

// A phone hides the footer and gives its row to the page: Settings goes to the top bar, Refresh to
// the menu beside the time it renews, and the copyright and update notice to the bottom of the
// menu (every target is in App.vue).
// A phone hides the footer and gives its row to the page: Settings goes to the top bar, and the
// copyright and update notice to the bottom of the menu (both targets are in App.vue). Refresh
// stays behind, as the menu's "Fetched" line refreshes on a phone.
const isPhone = useMediaQuery(PHONE_MEDIA_QUERY)

function refresh() {
if (!vin.value) return
send(vin.value, 'refresh', 'force')
}
</script>

<template>
Expand Down Expand Up @@ -78,19 +66,16 @@ function refresh() {
</div>
</Teleport>
<div class="app-footer__actions">
<Teleport defer to="#sidebar-refresh" :disabled="!isPhone">
<button
v-if="canSend"
class="app-footer__btn"
:aria-label="t('control.refresh')"
:title="t('control.refresh')"
:disabled="vehicleStore.loading || sending === 'refresh' || !vin"
@click="refresh"
>
<font-awesome-icon icon="rotate" :spin="vehicleStore.loading || sending === 'refresh'" />
<span class="app-footer__btn-label">{{ t('control.refresh') }}</span>
</button>
</Teleport>
<button
v-if="canRefresh"
class="app-footer__btn"
:aria-label="t('control.refresh')"
:disabled="refreshDisabled"
@click="refresh"
>
<font-awesome-icon icon="rotate" :spin="refreshing" />
<span class="app-footer__btn-label">{{ t('control.refresh') }}</span>
</button>
<Teleport defer to="#mobile-topbar-actions" :disabled="!isPhone">
<button class="app-footer__btn" :aria-label="t('settings.title')" @click="openModal">
<font-awesome-icon icon="gear" />
Expand Down
8 changes: 2 additions & 6 deletions frontend/src/components/__tests__/AppFooter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('AppFooter', () => {
expect(wrapper.findComponent({ name: 'SettingsModal' }).props('open')).toBe(true)
})

it('moves Settings to the top bar, Refresh and the copyright to the menu on a phone', async () => {
it('moves Settings to the top bar and the copyright to the menu on a phone', async () => {
vi.stubGlobal('matchMedia', (query: string) => ({
matches: query === PHONE_MEDIA_QUERY,
media: query,
Expand All @@ -99,8 +99,6 @@ describe('AppFooter', () => {
topbar.id = 'mobile-topbar-actions'
const menu = document.body.appendChild(document.createElement('div'))
menu.id = 'sidebar-meta'
const fetchedLine = document.body.appendChild(document.createElement('div'))
fetchedLine.id = 'sidebar-refresh'

const wrapper = mount(AppFooter, {
attachTo: document.body,
Expand All @@ -109,16 +107,14 @@ describe('AppFooter', () => {
await flushPromises()

expect(topbar.querySelector('button[aria-label="settings.title"]')).not.toBeNull()
// Refresh sits beside the time it renews, no longer in the top bar.
expect(fetchedLine.querySelector('button[aria-label="control.refresh"]')).not.toBeNull()
// Refresh stays in the hidden footer: on a phone the menu's fetched line refreshes.
expect(topbar.querySelector('button[aria-label="control.refresh"]')).toBeNull()
expect(menu.querySelector('.app-footer__copyright')).not.toBeNull()
expect(wrapper.find('.app-footer__copyright').exists()).toBe(false)

wrapper.unmount()
topbar.remove()
menu.remove()
fetchedLine.remove()
vi.unstubAllGlobals()
})

Expand Down
Loading
Loading