Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

search: your own exercises come right after favourites, "leg press" finds the 45° sled

Duarte Santos143b853ac1bf
diff --git a/frontend/src/lib/exercises.js b/frontend/src/lib/exercises.js
index a3cea7ffe..b2efda2c1 100644
--- a/frontend/src/lib/exercises.js
+++ b/frontend/src/lib/exercises.js
@@ -527,7 +527,10 @@ function tokenScore(entry, tok, ctx) {
const CLASSIC = new Set(V13_IDS)
const EQ_PRIOR = { barbell: 4, dumbbell: 4, cable: 3, 'leverage machine': 3, 'body weight': 3, 'smith machine': 2, kettlebell: 2, 'ez barbell': 2, 'sled machine': 2 }
const CAT_PRIOR = { strength: 3, calisthenics: 3, olympic: 2, plyometrics: 1, isometric: 1, stretching: -3, mobility: -3, rehab: -4, yoga: -2, pilates: -2 }
-const priorOf = e => (CLASSIC.has(e.id) ? 3 : 0) + (EQ_PRIOR[e.eq] || 0) + (CAT_PRIOR[e.cat] || 0)
+// The one version every gym has, where the catalogue's name hides it: "leg press" means the 45°
+// sled, not the Smith machine or a one-leg variant (Discord, 2026-10-09).
+const EVERYDAY = { '0739': 6 }
+const priorOf = e => (CLASSIC.has(e.id) ? 3 : 0) + (EQ_PRIOR[e.eq] || 0) + (CAT_PRIOR[e.cat] || 0) + (EVERYDAY[e.id] || 0)
// A name that is the query itself wins outright: as typed or in the singular 50, with the typos
// the search allows for its length 40 ("sqat" is the exercise called "squat", not "dumbbell squat").
diff --git a/frontend/src/lib/exercises.test.js b/frontend/src/lib/exercises.test.js
index 8d58fd80f..b88acf3e9 100644
--- a/frontend/src/lib/exercises.test.js
+++ b/frontend/src/lib/exercises.test.js
@@ -136,3 +136,11 @@ describe('the exercise dataset', () => {
expect(found).toEqual(expect.arrayContaining(['0739', '1464', '0740']))
})
})
+
+describe('search: the everyday version first', () => {
+ it('"leg press" finds the 45° sled leg press before the Smith and one-leg versions', async () => {
+ const { EXDB, searchExercises } = await import('./exercises.js')
+ expect(searchExercises(EXDB, 'leg press')[0].id).toBe('0739')
+ expect(searchExercises(EXDB, 'smith leg press')[0].id).toBe('0760')
+ })
+})
diff --git a/frontend/src/lib/favourites.js b/frontend/src/lib/favourites.js
index 1ba870a85..b3b058834 100644
--- a/frontend/src/lib/favourites.js
+++ b/frontend/src/lib/favourites.js
@@ -27,3 +27,24 @@ export function sortFavouritesFirst(list, S) {
const set = new Set(fav)
return [...list.filter(e => set.has(e.id)), ...list.filter(e => !set.has(e.id))]
}
+
+/**
+ * A search's results the way a person scans them: favourites, then the exercises they have
+ * already logged or planned (`usage`: id -> count, the picker's "Chosen"), then the rest. Each
+ * group keeps the search's own order. Someone who imported years of history types "press" and
+ * wants their press on top, not the best name match among 5,000.
+ */
+export function sortYoursFirst(list, S, usage) {
+ const fav = new Set(favIds(S))
+ const group = e => (fav.has(e.id) ? 0 : usage?.[e.id] ? 1 : 2)
+ if (!fav.size && !list.some(e => usage?.[e.id])) return list
+ return [0, 1, 2].flatMap(g => list.filter(e => group(e) === g))
+}
+
+/** How often each exercise sits in a routine or a logged workout: id -> count. */
+export function usageOf(S) {
+ const u = {}
+ for (const r of S?.routines || []) for (const e of r.ex || []) u[e.id] = (u[e.id] || 0) + 1
+ for (const w of S?.workouts || []) for (const e of w.entries || []) u[e.id] = (u[e.id] || 0) + 1
+ return u
+}
diff --git a/frontend/src/lib/favourites.test.js b/frontend/src/lib/favourites.test.js
index 84e3d5f8d..8a7fde30d 100644
--- a/frontend/src/lib/favourites.test.js
+++ b/frontend/src/lib/favourites.test.js
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
-import { favIds, isFav, toggleFav, sortFavouritesFirst } from './favourites.js'
+import { favIds, isFav, toggleFav, sortFavouritesFirst, sortYoursFirst, usageOf } from './favourites.js'
const ex = id => ({ id, n: id })
@@ -31,3 +31,16 @@ describe('favourites', () => {
expect(sortFavouritesFirst(list, {})).toBe(list)
})
})
+
+describe('sortYoursFirst', () => {
+ const list = [{ id: 'a' }, { id: 'b' }, { id: 'c' }, { id: 'd' }]
+ it('puts favourites, then exercises you use, then the rest, each in search order', () => {
+ expect(sortYoursFirst(list, { favEx: ['d'] }, { c: 3, b: 1 }).map(e => e.id)).toEqual(['d', 'b', 'c', 'a'])
+ })
+ it('leaves the search order alone when nothing is yours', () => {
+ expect(sortYoursFirst(list, {}, {})).toBe(list)
+ })
+ it('counts routines and logged workouts as use', () => {
+ expect(usageOf({ routines: [{ ex: [{ id: 'a' }] }], workouts: [{ entries: [{ id: 'a' }, { id: 'b' }] }] })).toEqual({ a: 2, b: 1 })
+ })
+})
diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx
index d9a5f36c2..61e4b972d 100644
--- a/frontend/src/sheets.jsx
+++ b/frontend/src/sheets.jsx
@@ -50,7 +50,7 @@ import { repeatSessionEntries } from './lib/session-repeat.js'
import { swapActiveExercise } from './lib/active-exercise-swap.js'
import { useSheetKeyboard, useRevealActiveChip, tappable } from './lib/use-sheet-keyboard.js'
import { useAutoMore } from './lib/use-auto-more.js'
-import { isFav, toggleFav, sortFavouritesFirst } from './lib/favourites.js'
+import { isFav, toggleFav, sortFavouritesFirst, sortYoursFirst } from './lib/favourites.js'
import { buildSessionEntries, buildPlannedEntry, builtOutOfProgression } from './lib/session-start.js'
import { finishCompare, finishCardio } from './lib/finish-compare.js'
import { workoutFit, fitFileName } from './lib/fit-export.js'
@@ -1307,7 +1307,9 @@ function ExercisePicker({ onPick, title, close, like }) {
// Favourites float to the top of whatever the filters left (issue #6), the rest keeps its order.
// On the same-muscle list the equipment order wins: what is on the same kit comes first,
// favourites leading within each half.
- const ranked = sortFavouritesFirst(eqOn ? eqFiltered.filter(e => e.eq === eqOn) : eqFiltered, st)
+ // While searching, what you have logged or planned follows right after them.
+ const narrowedList = eqOn ? eqFiltered.filter(e => e.eq === eqOn) : eqFiltered
+ const ranked = q.trim() ? sortYoursFirst(narrowedList, st, usage) : sortFavouritesFirst(narrowedList, st)
const f = bp === SAME ? sameMuscleFirst(ranked, likeEx) : ranked
const chosenCount = Object.keys(usage).length
const favCount = (st.favEx || []).length
diff --git a/frontend/src/views/Library.jsx b/frontend/src/views/Library.jsx
index 58f204ca1..f0180a73e 100644
--- a/frontend/src/views/Library.jsx
+++ b/frontend/src/views/Library.jsx
@@ -1,4 +1,4 @@
-import { useDeferredValue, useRef, useState } from 'react'
+import { useDeferredValue, useMemo, useRef, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { useStore } from '../store/useStore.js'
import { EXDB, BODYPARTS, allExercises, equipmentOf, categoriesOf, searchExercises, similarExercises } from '../lib/exercises.js'
@@ -14,7 +14,7 @@ import ExerciseViewToggle from '../components/ExerciseViewToggle.jsx'
import { Button } from '../components/ui.jsx'
import { tappable, useRevealActiveChip } from '../lib/use-sheet-keyboard.js'
import { useAutoMore } from '../lib/use-auto-more.js'
-import { isFav, sortFavouritesFirst } from '../lib/favourites.js'
+import { isFav, sortFavouritesFirst, sortYoursFirst, usageOf } from '../lib/favourites.js'
export default function Library() {
const nav = useNavigate()
@@ -41,8 +41,11 @@ 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 : ''
- // 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)
+ // Favourites float to the top of whatever the filters left (issue #6), the rest keeps its order;
+ // while searching, the exercises you have logged or planned follow right after them.
+ const narrowedList = eqOn ? eqFiltered.filter(e => e.eq === eqOn) : eqFiltered
+ const usage = useMemo(() => (q.trim() ? usageOf(S) : null), [q, S.routines, S.workouts])
+ const f = usage ? sortYoursFirst(narrowedList, S, usage) : sortFavouritesFirst(narrowedList, S)
useRevealActiveChip(bpStrip, bp)
useRevealActiveChip(eqStrip, eqOn)
useRevealActiveChip(catStrip, catOn)