{onPick ? : <>
{best > 0 && {fmtNum(best)}}
diff --git a/frontend/src/index.css b/frontend/src/index.css
index e684a11..76a51d0 100644
--- a/frontend/src/index.css
+++ b/frontend/src/index.css
@@ -416,6 +416,11 @@ h4.sec{
font-weight:500;text-transform:capitalize;
}
.tag.acc{background:var(--acc-soft);color:var(--acc)}
+/* favourite marker (issue #6): a small yellow star glued to the exercise name — distinct from
+ the accent "chosen" tag at the row's end, which means "already in a routine or the log" */
+.fav-star{color:var(--yellow);font-size:12px;display:inline-block;margin-right:5px;vertical-align:-1px}
+.fav-btn{margin-top:-4px}
+.fav-btn.on{color:var(--yellow)}
/* ---------------------------------------------------------------- chips -- */
.chips{
diff --git a/frontend/src/lib/favourites.js b/frontend/src/lib/favourites.js
new file mode 100644
index 0000000..1ba870a
--- /dev/null
+++ b/frontend/src/lib/favourites.js
@@ -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))]
+}
diff --git a/frontend/src/lib/favourites.test.js b/frontend/src/lib/favourites.test.js
new file mode 100644
index 0000000..84e3d5f
--- /dev/null
+++ b/frontend/src/lib/favourites.test.js
@@ -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)
+ })
+})
diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.js
index b251a31..826417b 100644
--- a/frontend/src/locales/de.js
+++ b/frontend/src/locales/de.js
@@ -93,6 +93,12 @@ export default {
'Search {0} exercises…': '{0} Übungen durchsuchen…',
'Chosen': 'Gewählt',
'Nothing chosen yet — add exercises and they’ll show up here.': 'Noch nichts gewählt — füge Übungen hinzu, dann erscheinen sie hier.',
+ 'Add to favourites': 'Zu Favoriten hinzufügen',
+ 'Remove from favourites': 'Aus Favoriten entfernen',
+ 'Added to favourites': 'Zu Favoriten hinzugefügt',
+ 'Removed from favourites': 'Aus Favoriten entfernt',
+ 'Favourites': 'Favoriten',
+ 'No favourites here — tap the star on an exercise to add it.': 'Keine Favoriten hier — tippe bei einer Übung auf den Stern.',
'No match': 'Kein Treffer',
'Show more': 'Mehr anzeigen',
'Intervals': 'Intervalle',
diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js
index 94cea47..ef393e1 100644
--- a/frontend/src/locales/es.js
+++ b/frontend/src/locales/es.js
@@ -89,6 +89,12 @@ export default {
'Search {0} exercises…': 'Buscar entre {0} ejercicios…',
'Chosen': 'Elegidos',
'Nothing chosen yet — add exercises and they’ll show up here.': 'Nada elegido aún — añade ejercicios y aparecerán aquí.',
+ 'Add to favourites': 'Añadir a favoritos',
+ 'Remove from favourites': 'Quitar de favoritos',
+ 'Added to favourites': 'Añadido a favoritos',
+ 'Removed from favourites': 'Quitado de favoritos',
+ 'Favourites': 'Favoritos',
+ 'No favourites here — tap the star on an exercise to add it.': 'Sin favoritos aquí — toca la estrella de un ejercicio para añadirlo.',
'No match': 'Sin resultados',
'Show more': 'Mostrar más',
'Intervals': 'Intervalos',
diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.js
index 49d44b8..133ff2f 100644
--- a/frontend/src/locales/fr.js
+++ b/frontend/src/locales/fr.js
@@ -89,6 +89,12 @@ export default {
'Search {0} exercises…': 'Rechercher parmi {0} exercices…',
'Chosen': 'Choisis',
'Nothing chosen yet — add exercises and they’ll show up here.': 'Rien de choisi — ajoute des exercices et ils apparaîtront ici.',
+ 'Add to favourites': 'Ajouter aux favoris',
+ 'Remove from favourites': 'Retirer des favoris',
+ 'Added to favourites': 'Ajouté aux favoris',
+ 'Removed from favourites': 'Retiré des favoris',
+ 'Favourites': 'Favoris',
+ 'No favourites here — tap the star on an exercise to add it.': 'Aucun favori ici — touche l’étoile d’un exercice pour l’ajouter.',
'No match': 'Aucun résultat',
'Show more': 'Afficher plus',
'Intervals': 'Intervalles',
diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.js
index b0768c3..8f1314a 100644
--- a/frontend/src/locales/hi.js
+++ b/frontend/src/locales/hi.js
@@ -89,6 +89,12 @@ export default {
'Search {0} exercises…': '{0} व्यायामों में खोजें…',
'Chosen': 'चुने हुए',
'Nothing chosen yet — add exercises and they’ll show up here.': 'अभी कुछ नहीं चुना — व्यायाम जोड़ें तो वे यहाँ दिखेंगे।',
+ 'Add to favourites': 'पसंदीदा में जोड़ें',
+ 'Remove from favourites': 'पसंदीदा से हटाएँ',
+ 'Added to favourites': 'पसंदीदा में जोड़ा गया',
+ 'Removed from favourites': 'पसंदीदा से हटाया गया',
+ 'Favourites': 'पसंदीदा',
+ 'No favourites here — tap the star on an exercise to add it.': 'यहाँ कोई पसंदीदा नहीं — किसी व्यायाम पर तारे को टैप करें।',
'No match': 'कोई परिणाम नहीं',
'Show more': 'और दिखाएँ',
'Intervals': 'इंटरवल',
diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.js
index f3c7b0f..74b7bc5 100644
--- a/frontend/src/locales/hu.js
+++ b/frontend/src/locales/hu.js
@@ -92,6 +92,12 @@ export default {
'Search {0} exercises…': '{0} gyakorlat keresése…',
'Chosen': 'Kiválasztva',
'Nothing chosen yet — add exercises and they’ll show up here.': 'Még nincs kiválasztva semmi — adj hozzá gyakorlatokat, és itt fognak megjelenni.',
+ 'Add to favourites': 'Kedvencekhez adás',
+ 'Remove from favourites': 'Eltávolítás a kedvencekből',
+ 'Added to favourites': 'Hozzáadva a kedvencekhez',
+ 'Removed from favourites': 'Eltávolítva a kedvencekből',
+ 'Favourites': 'Kedvencek',
+ 'No favourites here — tap the star on an exercise to add it.': 'Itt nincs kedvenc — koppints egy gyakorlat csillagára.',
'No match': 'Nincs találat',
'Show more': 'Több megjelenítése',
'Intervals': 'Intervallumok',
diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.js
index 747ec04..64174d0 100644
--- a/frontend/src/locales/it.js
+++ b/frontend/src/locales/it.js
@@ -89,6 +89,12 @@ export default {
'Search {0} exercises…': 'Cerca tra {0} esercizi…',
'Chosen': 'Scelti',
'Nothing chosen yet — add exercises and they’ll show up here.': 'Ancora niente — aggiungi esercizi e appariranno qui.',
+ 'Add to favourites': 'Aggiungi ai preferiti',
+ 'Remove from favourites': 'Rimuovi dai preferiti',
+ 'Added to favourites': 'Aggiunto ai preferiti',
+ 'Removed from favourites': 'Rimosso dai preferiti',
+ 'Favourites': 'Preferiti',
+ 'No favourites here — tap the star on an exercise to add it.': 'Nessun preferito qui — tocca la stella di un esercizio per aggiungerlo.',
'No match': 'Nessun risultato',
'Show more': 'Mostra altro',
'Intervals': 'Intervalli',
diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.js
index bd0e05a..9d5281e 100644
--- a/frontend/src/locales/ko.js
+++ b/frontend/src/locales/ko.js
@@ -87,8 +87,14 @@ export default {
'Create one and start with this exercise': '새로 만들어 이 운동으로 시작',
'Add exercise': '운동 추가',
'Search {0} exercises…': '{0}개 운동 검색…',
- 'Chosen': '즐겨찾기',
+ 'Chosen': '선택됨',
'Nothing chosen yet — add exercises and they’ll show up here.': '아직 없어요 — 운동을 추가하면 여기에 표시됩니다.',
+ 'Add to favourites': '즐겨찾기에 추가',
+ 'Remove from favourites': '즐겨찾기에서 제거',
+ 'Added to favourites': '즐겨찾기에 추가했어요',
+ 'Removed from favourites': '즐겨찾기에서 제거했어요',
+ 'Favourites': '즐겨찾기',
+ 'No favourites here — tap the star on an exercise to add it.': '즐겨찾기가 없어요 — 운동의 별을 눌러 추가하세요.',
'No match': '검색 결과 없음',
'Show more': '더 보기',
'Intervals': '인터벌',
diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.js
index c919a8d..665045c 100644
--- a/frontend/src/locales/pl.js
+++ b/frontend/src/locales/pl.js
@@ -89,6 +89,12 @@ export default {
'Search {0} exercises…': 'Szukaj wśród {0} ćwiczeń…',
'Chosen': 'Wybrane',
'Nothing chosen yet — add exercises and they’ll show up here.': 'Nic nie wybrano — dodaj ćwiczenia, a pojawią się tutaj.',
+ 'Add to favourites': 'Dodaj do ulubionych',
+ 'Remove from favourites': 'Usuń z ulubionych',
+ 'Added to favourites': 'Dodano do ulubionych',
+ 'Removed from favourites': 'Usunięto z ulubionych',
+ 'Favourites': 'Ulubione',
+ 'No favourites here — tap the star on an exercise to add it.': 'Brak ulubionych — dotknij gwiazdki przy ćwiczeniu, aby je dodać.',
'No match': 'Brak wyników',
'Show more': 'Pokaż więcej',
'Intervals': 'Interwały',
diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.js
index e5e3ecb..ebcb22c 100644
--- a/frontend/src/locales/pt-BR.js
+++ b/frontend/src/locales/pt-BR.js
@@ -33,6 +33,7 @@ export const PT_BR_OVERRIDES = {
'Create one and start with this exercise': 'Crie uma e comece com este exercício',
'Search {0} exercises…': 'Buscar entre {0} exercícios…',
'Nothing chosen yet — add exercises and they’ll show up here.': 'Nenhum exercício escolhido — adicione exercícios e eles aparecerão aqui.',
+ 'No favourites here — tap the star on an exercise to add it.': 'Sem favoritos aqui — toque na estrela de um exercício para adicioná-lo.',
'The sets you logged for this exercise in this session will be lost.': 'As séries registradas para este exercício nesta sessão serão perdidas.',
'Swap exercise': 'Trocar exercício',
'Swap exercise?': 'Trocar exercício?',
diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.js
index feda480..7ceb526 100644
--- a/frontend/src/locales/pt.js
+++ b/frontend/src/locales/pt.js
@@ -89,6 +89,12 @@ export default {
'Search {0} exercises…': 'Pesquisar {0} exercícios…',
'Chosen': 'Escolhidos',
'Nothing chosen yet — add exercises and they’ll show up here.': 'Ainda nada escolhido — adiciona exercícios e eles aparecem aqui.',
+ 'Add to favourites': 'Adicionar aos favoritos',
+ 'Remove from favourites': 'Remover dos favoritos',
+ 'Added to favourites': 'Adicionado aos favoritos',
+ 'Removed from favourites': 'Removido dos favoritos',
+ 'Favourites': 'Favoritos',
+ 'No favourites here — tap the star on an exercise to add it.': 'Sem favoritos aqui — toca na estrela de um exercício para o adicionar.',
'No match': 'Sem resultados',
'Show more': 'Mostrar mais',
'Intervals': 'Intervalos',
diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.js
index 47f93d4..1565435 100644
--- a/frontend/src/locales/ru.js
+++ b/frontend/src/locales/ru.js
@@ -87,8 +87,14 @@ export default {
'Create one and start with this exercise': 'Создай новую и начни с этого упражнения',
'Add exercise': 'Добавить упражнение',
'Search {0} exercises…': 'Поиск среди {0} упражнений…',
- 'Chosen': 'Избранные',
+ 'Chosen': 'Выбранные',
'Nothing chosen yet — add exercises and they’ll show up here.': 'Пока ничего нет — добавляй упражнения, и они появятся здесь.',
+ 'Add to favourites': 'В избранное',
+ 'Remove from favourites': 'Убрать из избранного',
+ 'Added to favourites': 'Добавлено в избранное',
+ 'Removed from favourites': 'Убрано из избранного',
+ 'Favourites': 'Избранное',
+ 'No favourites here — tap the star on an exercise to add it.': 'Здесь нет избранного — нажми на звезду у упражнения.',
'No match': 'Ничего не найдено',
'Show more': 'Показать ещё',
'Intervals': 'Интервалы',
diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.js
index 8efcf51..d4e31a3 100644
--- a/frontend/src/locales/th.js
+++ b/frontend/src/locales/th.js
@@ -92,6 +92,12 @@ export default {
'Search {0} exercises…': 'ค้นหาใน {0} ท่า…',
'Chosen': 'ที่เลือกไว้',
'Nothing chosen yet — add exercises and they’ll show up here.': 'ยังไม่ได้เลือกอะไรเลย — เพิ่มท่าออกกำลังกายแล้วจะโผล่มาที่นี่',
+ 'Add to favourites': 'เพิ่มในรายการโปรด',
+ 'Remove from favourites': 'นำออกจากรายการโปรด',
+ 'Added to favourites': 'เพิ่มในรายการโปรดแล้ว',
+ 'Removed from favourites': 'นำออกจากรายการโปรดแล้ว',
+ 'Favourites': 'รายการโปรด',
+ 'No favourites here — tap the star on an exercise to add it.': 'ยังไม่มีรายการโปรดที่นี่ — แตะดาวที่ท่าออกกำลังกายเพื่อเพิ่ม',
'No match': 'ไม่พบผลลัพธ์',
'Show more': 'แสดงเพิ่ม',
'Intervals': 'อินเทอร์วัล',
diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.js
index 7215e2a..2154da3 100644
--- a/frontend/src/locales/tr.js
+++ b/frontend/src/locales/tr.js
@@ -89,6 +89,12 @@ export default {
'Search {0} exercises…': '{0} egzersiz içinde ara…',
'Chosen': 'Seçilenler',
'Nothing chosen yet — add exercises and they’ll show up here.': 'Henüz seçim yok — egzersiz ekledikçe burada görünecekler.',
+ 'Add to favourites': 'Favorilere ekle',
+ 'Remove from favourites': 'Favorilerden çıkar',
+ 'Added to favourites': 'Favorilere eklendi',
+ 'Removed from favourites': 'Favorilerden çıkarıldı',
+ 'Favourites': 'Favoriler',
+ 'No favourites here — tap the star on an exercise to add it.': 'Burada favori yok — eklemek için bir egzersizin yıldızına dokun.',
'No match': 'Sonuç yok',
'Show more': 'Daha fazla göster',
'Intervals': 'Aralıklar',
diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.js
index bc61428..d69ee45 100644
--- a/frontend/src/locales/zh.js
+++ b/frontend/src/locales/zh.js
@@ -89,6 +89,12 @@ export default {
'Search {0} exercises…': '搜索 {0} 个动作…',
'Chosen': '常用',
'Nothing chosen yet — add exercises and they’ll show up here.': '还没有常用动作——添加后会显示在这里。',
+ 'Add to favourites': '加入收藏',
+ 'Remove from favourites': '取消收藏',
+ 'Added to favourites': '已加入收藏',
+ 'Removed from favourites': '已取消收藏',
+ 'Favourites': '收藏',
+ 'No favourites here — tap the star on an exercise to add it.': '这里还没有收藏——点动作旁的星标即可加入。',
'No match': '没有匹配',
'Show more': '显示更多',
'Intervals': '间歇数',
diff --git a/frontend/src/sheets.favourites.test.jsx b/frontend/src/sheets.favourites.test.jsx
new file mode 100644
index 0000000..1a82491
--- /dev/null
+++ b/frontend/src/sheets.favourites.test.jsx
@@ -0,0 +1,96 @@
+// @vitest-environment happy-dom
+// Favourites (issue #6): the detail sheet's star writes S.favEx, and the picker floats
+// favourites to the top of its list without disturbing the order of everything else.
+import React, { act } from 'react'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { createRoot } from 'react-dom/client'
+import { EXDB } from './lib/exercises.js'
+import { DEF, useStore } from './store/useStore.js'
+import { useUI } from './store/useUI.js'
+import { exerciseDetailSheet, exercisePicker } from './sheets.jsx'
+
+const mounted = []
+const S = () => useStore.getState().S
+
+// Renders whatever sheet is on top and returns its host element.
+function renderTop() {
+ const sheet = useUI.getState().sheets.at(-1)
+ const host = document.createElement('div')
+ document.body.appendChild(host)
+ const root = createRoot(host)
+ mounted.push(root)
+ act(() => root.render(sheet.render(() => useUI.getState().closeSheet(sheet.id))))
+ return host
+}
+
+const names = host => [...host.querySelectorAll('.item .tt')].map(el => el.textContent)
+const starOf = host => host.querySelector('.fav-btn')
+
+beforeEach(() => {
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true
+ useUI.setState({ sheets: [], toastMsg: '' })
+ useStore.setState({ S: structuredClone(DEF), user: null })
+ document.body.innerHTML = ''
+})
+
+afterEach(() => {
+ act(() => { mounted.splice(0).forEach(root => root.unmount()) })
+})
+
+describe('exercise detail star', () => {
+ it('adds and removes the exercise from favourites with a toast', () => {
+ const ex = EXDB[0]
+ exerciseDetailSheet(ex)
+ const host = renderTop()
+ expect(starOf(host).getAttribute('aria-label')).toBe('Add to favourites')
+ act(() => starOf(host).click())
+ expect(S().favEx).toEqual([ex.id])
+ expect(useUI.getState().toastMsg).toBe('Added to favourites')
+ expect(starOf(host).getAttribute('aria-label')).toBe('Remove from favourites')
+ expect(starOf(host).getAttribute('aria-pressed')).toBe('true')
+ act(() => starOf(host).click())
+ expect(S().favEx).toEqual([])
+ expect(useUI.getState().toastMsg).toBe('Removed from favourites')
+ })
+
+ it('tolerates a profile written before the field existed', () => {
+ useStore.setState(s => { const next = { ...s.S }; delete next.favEx; return { S: next } })
+ exerciseDetailSheet(EXDB[0])
+ const host = renderTop()
+ act(() => starOf(host).click())
+ expect(S().favEx).toEqual([EXDB[0].id])
+ })
+})
+
+describe('exercise picker', () => {
+ it('lists favourites first and marks them, keeping the rest in catalogue order', () => {
+ const plain = names((exercisePicker(vi.fn()), renderTop())).slice(1) // drop "Create your own"
+ useUI.setState({ sheets: [] })
+ const fav = [plain[7], plain[3]]
+ const favIds = fav.map(n => EXDB.find(e => e.n === n).id)
+ useStore.setState(s => ({ S: { ...s.S, favEx: favIds } }))
+ exercisePicker(vi.fn())
+ const host = renderTop()
+ const shown = names(host).slice(1)
+ // Favourites keep the list's own order among themselves — not the order they were starred in.
+ 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.slice(0, 2).every(r => r.querySelector('.tt .fav-star'))).toBe(true)
+ expect(rows[2].querySelector('.tt .fav-star')).toBeNull()
+ })
+
+ it('offers a Favourites chip only when there are favourites, and it filters to them', () => {
+ exercisePicker(vi.fn())
+ let host = renderTop()
+ const chip = h => [...h.querySelectorAll('.chips .chip')].find(b => b.textContent.startsWith('Favourites'))
+ expect(chip(host)).toBeUndefined()
+ useUI.setState({ sheets: [] })
+ useStore.setState(s => ({ S: { ...s.S, favEx: [EXDB[5].id, EXDB[9].id] } }))
+ exercisePicker(vi.fn())
+ host = renderTop()
+ expect(chip(host).textContent).toBe('Favourites (2)')
+ act(() => chip(host).click())
+ expect(names(host)).toEqual([EXDB[5].n, EXDB[9].n])
+ })
+})
diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx
index 1819c24..dbad680 100644
--- a/frontend/src/sheets.jsx
+++ b/frontend/src/sheets.jsx
@@ -33,6 +33,7 @@ import { isWarmupRow } from './lib/workout-model.js'
import { nextUnfinishedUnit } from './lib/supersetFlow.js'
import { swapActiveExercise } from './lib/active-exercise-swap.js'
import { useSheetKeyboard, useRevealActiveChip, tappable } from './lib/use-sheet-keyboard.js'
+import { isFav, toggleFav, sortFavouritesFirst } from './lib/favourites.js'
import { buildSessionEntries } from './lib/session-start.js'
import { workoutsOn, backfillStart, backfillEnd, completeBackfill } from './lib/backfill.js'
@@ -624,8 +625,20 @@ function ExerciseDetail({ ex, close }) {
const st = useStore(s => s.S)
const last = lastEntryFor(st, ex.id)
const best = bestWeightFor(st, ex.id)
+ const fav = isFav(st, ex.id)
+ const flipFav = () => {
+ let on = false
+ update(s => { on = toggleFav(s, ex.id) })
+ toast(on ? t('Added to favourites') : t('Removed from favourites'))
+ }
return <>
-
{exerciseNameFor(ex)}
+
+
{exerciseNameFor(ex)}
+
+
{t(ex.bp)}
@@ -822,6 +835,7 @@ export function deleteCustomEx(ex, afterDelete) {
s.customEx = (s.customEx || []).filter(x => x.id !== ex.id)
s.routines.forEach(r => { r.ex = r.ex.filter(e => e.id !== ex.id); cleanupSg(r.ex) })
delete s.exWeights[ex.id]
+ s.favEx = (s.favEx || []).filter(id => id !== ex.id)
})
toast(t('Exercise deleted'))
afterDelete && afterDelete()
@@ -841,7 +855,7 @@ function ExercisePicker({ onPick, close }) {
const st = useStore(s => s.S)
const usage = usageMap(st)
const [q, setQ] = useState('')
- const [bp, setBp] = useState('') // '' = all, '★' = chosen, else a body part
+ const [bp, setBp] = useState('') // '' = all, '★' = chosen, '☆' = favourites, else a body part
const [eq, setEq] = useState('') // '' = any equipment
const [showAll, setShowAll] = useState(false)
const [shown, setShown] = useState(50)
@@ -851,16 +865,18 @@ function ExercisePicker({ onPick, close }) {
const onSearchFocus = useSheetKeyboard(searchRef)
const all = allExercises(st)
const profile = activeProfile(st)
- let base = all.filter(e =>
- (bp === '★' ? usage[e.id] : (!bp || e.bp === bp)) &&
- matchExercise(e, q))
+ const inScope = e => bp === '★' ? usage[e.id] : bp === '☆' ? isFav(st, e.id) : (!bp || e.bp === bp)
+ let base = all.filter(e => inScope(e) && matchExercise(e, q))
if (bp === '★') base = [...base].sort((a, b) => (usage[b.id] - usage[a.id]) || exerciseNameFor(a).localeCompare(exerciseNameFor(b)))
const eqFiltered = (profile && !showAll) ? base.filter(e => exAvailable(st, e)) : base
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, st)
const chosenCount = Object.keys(usage).length
+ const favCount = (st.favEx || []).length
+ const special = bp === '★' || bp === '☆'
useRevealActiveChip(bpStrip, bp)
useRevealActiveChip(eqStrip, eqOn)
if (byMuscle) return <>
@@ -886,6 +902,7 @@ function ExercisePicker({ onPick, close }) {
customExSheet(null, ex => onPick(ex), q.trim()))}>
+ {!special &&
customExSheet(null, ex => onPick(ex), q.trim()))}>
{t('Create your own exercise')}
{t('name + body part, no animation')}
}
{f.slice(0, shown).map(e =>
onPick(e))}>
-
{exerciseNameFor(e)}
{t(e.tg || e.bp)} · {t(e.eq)}
+
{isFav(st, e.id) && }{exerciseNameFor(e)}
{t(e.tg || e.bp)} · {t(e.eq)}
+ {/* Accent tag = already in a routine/log ("Chosen"); the yellow star by the name = favourite. */}
{usage[e.id] && }
{/* A "+" glyph reads as "add this now" — it used to just open the same detail sheet as
tapping the row, so it added nothing until you'd scrolled past the sets/reps config
@@ -911,6 +929,7 @@ function ExercisePicker({ onPick, close }) {
onClick={ev => { ev.stopPropagation(); onPick(e, true) }}>
)}
{f.length === 0 && bp === '★' &&
{t('Nothing chosen yet — add exercises and they’ll show up here.')}
}
+ {f.length === 0 && bp === '☆' &&
{t('No favourites here — tap the star on an exercise to add it.')}
}
{f.length > shown && <>>}
>
diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.js
index 15f74dc..33dd4a7 100644
--- a/frontend/src/store/useStore.js
+++ b/frontend/src/store/useStore.js
@@ -36,6 +36,9 @@ export const DEF = {
// every time you do the movement ("seat 4, pin 7"). Distinct from a routine's `note`, which
// belongs to one exercise in one plan, and from a session note, which belongs to one day.
exNotes: {},
+ // Favourite exercise ids (issue #6) — sorted to the top of the picker/Library. Personal, so
+ // it syncs with the profile but is never part of a shared plan bundle (lib/favourites.js).
+ favEx: [],
// First day of the week as a getDay() index — 1 Monday, 0 Sunday. Monday is the default so
// every profile written before this setting existed keeps the week it has been looking at.
// See lib/format.js: nothing reads this field directly, everything goes through the helpers.
diff --git a/frontend/src/views/Library.jsx b/frontend/src/views/Library.jsx
index b591abb..52eac47 100644
--- a/frontend/src/views/Library.jsx
+++ b/frontend/src/views/Library.jsx
@@ -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
exerciseDetailSheet(e))}>
-
{exerciseNameFor(e)}
{t(e.tg || e.bp)} · {t(e.eq)}
+
{isFav(S, e.id) && }{exerciseNameFor(e)}
{t(e.tg || e.bp)} · {t(e.eq)}
{best > 0 && {fmtNum(best)}}
diff --git a/frontend/src/views/Library.test.jsx b/frontend/src/views/Library.test.jsx
new file mode 100644
index 0000000..b4d9543
--- /dev/null
+++ b/frontend/src/views/Library.test.jsx
@@ -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())
+ 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)
+ })
+})