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
@@ -0,0 +1,29 @@
|
||||
// Favourite exercises (issue #6): a personal shortlist that floats to the top of the picker,
|
||||
// the Library and the muscle explorer so building a routine takes fewer scrolls.
|
||||
//
|
||||
// Stored as a flat id list in synced state (S.favEx) — catalogue or custom ids alike. It is
|
||||
// personal, so it stays out of shared plan bundles (lib/plan-share.js) on purpose. Profiles
|
||||
// written before the field existed simply have no list, hence every reader tolerates undefined.
|
||||
|
||||
export const favIds = S => (Array.isArray(S?.favEx) ? S.favEx : [])
|
||||
|
||||
export const isFav = (S, id) => favIds(S).includes(id)
|
||||
|
||||
/** Flip one exercise in a state draft. Returns true when it is a favourite afterwards. */
|
||||
export function toggleFav(s, id) {
|
||||
const list = favIds(s)
|
||||
const on = !list.includes(id)
|
||||
s.favEx = on ? [...list, id] : list.filter(x => x !== id)
|
||||
return on
|
||||
}
|
||||
|
||||
/**
|
||||
* Favourites first, everything else after — both halves keep the order they came in, so a
|
||||
* list that is already sorted by name (or by usage) stays that way within each half.
|
||||
*/
|
||||
export function sortFavouritesFirst(list, S) {
|
||||
const fav = favIds(S)
|
||||
if (!fav.length) return list
|
||||
const set = new Set(fav)
|
||||
return [...list.filter(e => set.has(e.id)), ...list.filter(e => !set.has(e.id))]
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { favIds, isFav, toggleFav, sortFavouritesFirst } from './favourites.js'
|
||||
|
||||
const ex = id => ({ id, n: id })
|
||||
|
||||
describe('favourites', () => {
|
||||
it('reads a profile without the field as no favourites', () => {
|
||||
expect(favIds({})).toEqual([])
|
||||
expect(favIds({ favEx: null })).toEqual([])
|
||||
expect(isFav({}, '0001')).toBe(false)
|
||||
})
|
||||
|
||||
it('toggles an id in and out of the list and reports the new state', () => {
|
||||
const s = {}
|
||||
expect(toggleFav(s, '0001')).toBe(true)
|
||||
expect(toggleFav(s, 'c123')).toBe(true)
|
||||
expect(s.favEx).toEqual(['0001', 'c123'])
|
||||
expect(isFav(s, '0001')).toBe(true)
|
||||
expect(toggleFav(s, '0001')).toBe(false)
|
||||
expect(s.favEx).toEqual(['c123'])
|
||||
})
|
||||
|
||||
it('moves favourites to the front and keeps both halves in their original order', () => {
|
||||
const list = ['a', 'b', 'c', 'd', 'e'].map(ex)
|
||||
const S = { favEx: ['d', 'b', 'zzz-not-listed'] }
|
||||
expect(sortFavouritesFirst(list, S).map(e => e.id)).toEqual(['b', 'd', 'a', 'c', 'e'])
|
||||
})
|
||||
|
||||
it('returns the very same list when there are no favourites', () => {
|
||||
const list = ['a', 'b'].map(ex)
|
||||
expect(sortFavouritesFirst(list, {})).toBe(list)
|
||||
})
|
||||
})
|
||||
@@ -27,11 +27,11 @@ describe('Brazilian Portuguese locale', () => {
|
||||
.sort(byCodeUnit)
|
||||
const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')
|
||||
|
||||
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(620)
|
||||
expect(inherited).toHaveLength(598)
|
||||
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(621)
|
||||
expect(inherited).toHaveLength(603)
|
||||
// If this fails, review the changed keys and wording before accepting a new hash. From
|
||||
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list
|
||||
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('5f1f5dcac5d51dd96f9d1e3506c6a65fd098071b971739686f3cc0360cca35ec')
|
||||
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('45ca712c8ea299590a096c9ee98c12932734ee27fee460660df8a687a2b065f6')
|
||||
})
|
||||
|
||||
test('does not leak European Portuguese UI terms', () => {
|
||||
|
||||
Reference in new issue
Block a user