Favoriten-Uebungen (#6): Stern im Detail-Sheet, Favoriten zuoberst im Picker, in der Bibliothek und im Muskel-Explorer
Wer eine Routine plant, scrollt sonst jedes Mal durch 1300 Uebungen zu denselben zehn.
Ein Stern im Kopf des Uebungs-Detail-Sheets (aria-label + Toast) merkt sich eine Uebung in
S.favEx — Katalog- oder eigene Ids. Das Feld reist mit dem Profil (Sync/Export), bleibt aber
bewusst aus dem geteilten Plan-Bundle draussen (lib/plan-share.js baut das Bundle nur aus
Routinen/Woche/customEx, dort war nichts zu aendern).
- lib/favourites.js: favIds/isFav/toggleFav/sortFavouritesFirst; alte Profile ohne Feld lesen
als leer. Die Sortierung ist in beiden Haelften stabil, damit eine nach Name oder Nutzung
sortierte Liste ihre Ordnung behaelt.
- Picker, Library, MuscleExplorer sortieren erst NACH Suche/Koerperteil/Equipment, also innerhalb
der aktuellen Trefferliste; Favoriten tragen einen kleinen gelben Stern vor dem Namen. Der
Akzent-Tag am Zeilenende ("Gewaehlt" = schon in Routine/Log) bleibt unveraendert und ist
durch Position und Farbe davon unterscheidbar.
- Picker: zusaetzlicher Chip "Favoriten (n)" vor "Gewaehlt", nur sichtbar wenn es welche gibt,
mit eigenem Leer-Hinweis; die Scope-Abfrage ist jetzt eine kleine inScope-Funktion.
- Eine geloeschte eigene Uebung faellt auch aus favEx.
- ko/ru nannten den alten "Chosen"-Filter bereits "Favoriten" — umbenannt (선택됨 / Выбранные),
damit die zwei Chips nicht gleich heissen.
- 6 neue Strings in 14 Packs, pt-BR nur der Leer-Hinweis (toque/adicioná-lo); Fingerprint
in pt-br-locale.test.js nachgezogen.
- Tests: lib/favourites.test.js, sheets.favourites.test.jsx (Stern + Picker-Reihenfolge +
Chip mit echtem Store), views/Library.test.jsx (Reihenfolge + Koerperteil-Filter).
This commit is contained in:
1 parent
b5769b9c38
commit
f162505549
24 files changed
+353
-17
No files matched your search
@@ -11,6 +11,7 @@ import { exerciseDetailSheet, addToRoutineSheet, customExSheet } from '../sheets
|
||||
import Icon from '../components/Icon.jsx'
|
||||
import { Button } from '../components/ui.jsx'
|
||||
import { tappable, useRevealActiveChip } from '../lib/use-sheet-keyboard.js'
|
||||
import { isFav, sortFavouritesFirst } from '../lib/favourites.js'
|
||||
|
||||
export default function Library() {
|
||||
const nav = useNavigate()
|
||||
@@ -27,7 +28,8 @@ export default function Library() {
|
||||
const eqOpts = equipmentOf(eqFiltered)
|
||||
// Drop the equipment filter if the search narrowed it away, so you never hit a dead end.
|
||||
const eqOn = eqOpts.includes(eq) ? eq : ''
|
||||
const f = eqOn ? eqFiltered.filter(e => e.eq === eqOn) : eqFiltered
|
||||
// Favourites float to the top of whatever the filters left (issue #6), the rest keeps its order.
|
||||
const f = sortFavouritesFirst(eqOn ? eqFiltered.filter(e => e.eq === eqOn) : eqFiltered, S)
|
||||
useRevealActiveChip(bpStrip, bp)
|
||||
useRevealActiveChip(eqStrip, eqOn)
|
||||
|
||||
@@ -61,7 +63,7 @@ export default function Library() {
|
||||
const best = bestWeightFor(S, e.id)
|
||||
return <div key={e.id} className="item" {...tappable(() => exerciseDetailSheet(e))}>
|
||||
<Thumb ex={e} />
|
||||
<div className="grow"><div className="tt capitalize">{exerciseNameFor(e)}</div><div className="ss capitalize">{t(e.tg || e.bp)} · {t(e.eq)}</div></div>
|
||||
<div className="grow"><div className="tt capitalize">{isFav(S, e.id) && <Icon name="starFill" className="fav-star" />}{exerciseNameFor(e)}</div><div className="ss capitalize">{t(e.tg || e.bp)} · {t(e.eq)}</div></div>
|
||||
{best > 0 && <span className="tag acc">{fmtNum(best)}</span>}
|
||||
<Button size="sm" variant="tinted" icon="plus" onClick={ev => { ev.stopPropagation(); addToRoutineSheet(e) }}>{t('Plan')}</Button>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
// @vitest-environment happy-dom
|
||||
// Favourites (issue #6): the Library floats starred exercises to the top of the current
|
||||
// result list — after the search and body-part filters, without reordering the rest.
|
||||
import React, { act } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import Library from './Library.jsx'
|
||||
import { EXDB } from '../lib/exercises.js'
|
||||
|
||||
globalThis.IS_REACT_ACT_ENVIRONMENT = true
|
||||
|
||||
const mocks = vi.hoisted(() => {
|
||||
const state = { S: null }
|
||||
state.snapshot = () => ({ S: state.S, user: null, update: mut => { const next = structuredClone(state.S); mut(next); state.S = next } })
|
||||
return state
|
||||
})
|
||||
vi.mock('../store/useStore.js', () => {
|
||||
const useStore = selector => selector ? selector(mocks.snapshot()) : mocks.snapshot()
|
||||
useStore.getState = mocks.snapshot
|
||||
return { useStore }
|
||||
})
|
||||
vi.mock('react-router-dom', () => ({ useNavigate: () => () => {} }))
|
||||
vi.mock('../sheets.jsx', () => ({ exerciseDetailSheet: vi.fn(), addToRoutineSheet: vi.fn(), customExSheet: vi.fn() }))
|
||||
|
||||
const mounted = []
|
||||
function render() {
|
||||
const host = document.createElement('div')
|
||||
document.body.appendChild(host)
|
||||
const root = createRoot(host)
|
||||
mounted.push(root)
|
||||
act(() => root.render(<Library />))
|
||||
return host
|
||||
}
|
||||
const names = host => [...host.querySelectorAll('.item .tt')].map(el => el.textContent).slice(1) // drop "Create your own"
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.S = { unit: 'kg', lang: 'en', routines: [], workouts: [], customEx: [], exWeights: {}, equipProfiles: [], activeEquipId: null, equipFilterOn: false }
|
||||
document.body.innerHTML = ''
|
||||
})
|
||||
afterEach(() => { act(() => { mounted.splice(0).forEach(root => root.unmount()) }) })
|
||||
|
||||
describe('Library favourites', () => {
|
||||
it('puts favourites first, marked with a star, and leaves the rest in catalogue order', () => {
|
||||
const plain = names(render())
|
||||
act(() => { mounted.splice(0).forEach(root => root.unmount()) })
|
||||
const fav = [plain[6], plain[2]]
|
||||
mocks.S.favEx = fav.map(n => EXDB.find(e => e.n === n).id)
|
||||
const host = render()
|
||||
const shown = names(host)
|
||||
expect(shown.slice(0, 2)).toEqual(plain.filter(n => fav.includes(n)))
|
||||
expect(shown.slice(2)).toEqual(plain.filter(n => !fav.includes(n)))
|
||||
const rows = [...host.querySelectorAll('.item')].slice(1)
|
||||
expect(rows[0].querySelector('.fav-star')).not.toBeNull()
|
||||
expect(rows[2].querySelector('.fav-star')).toBeNull()
|
||||
})
|
||||
|
||||
it('keeps a favourite on top inside a body-part filter, but never pulls one in from elsewhere', () => {
|
||||
const chest = EXDB.filter(e => e.bp === 'chest')
|
||||
const legs = EXDB.find(e => e.bp !== 'chest')
|
||||
mocks.S.favEx = [chest[4].id, legs.id]
|
||||
const host = render()
|
||||
const chip = [...host.querySelectorAll('.chips .chip')].find(b => b.textContent === 'chest')
|
||||
act(() => chip.click())
|
||||
const shown = names(host)
|
||||
expect(shown[0]).toBe(chest[4].n)
|
||||
expect(shown).not.toContain(legs.n)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user