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.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
Desktop: lists on the narrow pages (Start workout's other routines, the Admin user list and the rest) are one column again on a wide screen, as the layout meant; Library, History, Stats and Plan keep their two columns
Duarte Santosd2fa5b9f4ccd
diff --git a/frontend/src/index.css b/frontend/src/index.cssindex 3de9d07f8..26e958b4f 100644--- a/frontend/src/index.css+++ b/frontend/src/index.css@@ -458,11 +458,11 @@ h4.sec{}.item:active{background:var(--surface-2)}.routine-list{position:relative}-/* One column at every width (#277). The desktop layout puts every #app list in two columns, and- the `.narrow .list` rule meant to undo that on the narrow pages loses to it on specificity. So- on a computer this list sat in a grid, while the reorder measures its rows top to bottom and- draws the drop line across the whole list: an exercise dragged just below the next one in its- column landed at the end. Supersets ("the exercise above") read as a column too. */+/* One column at every width (#277), whatever page it is on. The desktop layout puts the #app+ lists outside a .narrow page in two columns, and before the .narrow rule below won on+ specificity this list sat in that grid on a computer, while the reorder measures its rows top+ to bottom and draws the drop line across the whole list: an exercise dragged just below the+ next one in its column landed at the end. Supersets ("the exercise above") read as a column too. */#app .list.routine-list{display:flex;flex-direction:column}.routine-drag-row{touch-action:pan-y;-webkit-touch-callout:none;position:relative;transition:transform var(--fast) var(--ease)}.routine-list.is-reordering{user-select:none;-webkit-user-select:none}@@ -1491,8 +1491,13 @@ body.chips-dragging *{cursor:inherit}.workout-end-spacer{height:40px}.cols{display:grid;grid-template-columns:1fr 1fr;gap:14px;align-items:start}.cols>*{min-width:0}+ /* Two columns on the full-width pages (Library, History, Stats, Plan, Muscles). A .narrow page+ is a single 640px column and keeps its lists in one too. The #app in that selector is what+ lets it win: `.narrow .list` alone lost to `#app .list` on specificity, so Home, Workout,+ Admin and the rest showed their lists two-up on a computer. Sheets live in #modal-root,+ outside #app, and are one column at every width. */#app .list{display:grid;grid-template-columns:1fr 1fr;gap:8px}- #modal-root .list,.narrow .list{display:flex;flex-direction:column}+ #modal-root .list,#app .narrow .list{display:flex;flex-direction:column}.narrow{max-width:640px;margin:0 auto}.tiles{grid-template-columns:repeat(4,1fr)}.cols .tiles,.center .tiles{grid-template-columns:1fr 1fr} /* a 300px dialog has no room for four */diff --git a/frontend/src/list-columns.test.js b/frontend/src/list-columns.test.jsnew file mode 100644index 000000000..4b57f472d--- /dev/null+++ b/frontend/src/list-columns.test.js@@ -0,0 +1,102 @@+// How many columns a `.list` gets on a computer (≥1000px). The desktop layout puts the lists of+// the full-width pages in two columns; a `.narrow` page (Home, Workout, Settings, Admin, …) is+// one 640px column and its lists are meant to stay one column in it. The rule saying so lost to+// `#app .list` on specificity, so those lists showed two-up anyway. happy-dom does not apply+// media queries or the cascade, so this resolves it from index.css itself: the desktop block's+// rules and the base rules, highest specificity first and the later rule on a tie.+import { describe, expect, it } from 'vitest'+import { readFileSync } from 'node:fs'+import { resolve } from 'node:path'++const css = readFileSync(resolve(process.cwd(), 'src/index.css'), 'utf8').replace(/\/\*[\s\S]*?\*\//g, '')++// The inside of one @media block, by brace depth.+function mediaBody(query) {+ const at = css.indexOf(`@media ${query}{`)+ expect(at, query).toBeGreaterThanOrEqual(0)+ let depth = 0+ const open = css.indexOf('{', at)+ for (let i = open; i < css.length; i++) {+ if (css[i] === '{') depth+++ else if (css[i] === '}' && --depth === 0) return { body: css.slice(open + 1, i), start: open + 1, end: i }+ }+ throw new Error('unclosed ' + query)+}++// Flat `selector{declarations}` rules, in source order.+const rulesIn = (text, offset = 0) => [...text.matchAll(/([^{}@]+)\{([^{}]*)\}/g)]+ .map(m => ({ selectors: m[1].split(',').map(s => s.trim()), decls: m[2], order: offset + m.index }))++const desktop = mediaBody('(min-width:1000px)')+// Top-level rules only: every other @media block is left out, since none of them touches `.list`.+const topLevel = rulesIn(css.replace(/@media[^{]*\{(?:[^{}]*\{[^{}]*\})*[^{}]*\}/g, m => ' '.repeat(m.length)))+const rules = [...topLevel, ...rulesIn(desktop.body, desktop.start)].filter(r => /display:/.test(r.decls))++const compound = text => ({+ ids: [...text.matchAll(/#([\w-]+)/g)].map(m => m[1]),+ classes: [...text.matchAll(/\.([\w-]+)/g)].map(m => m[1]),+ other: text.replace(/#[\w-]+|\.[\w-]+/g, ''),+})+const fits = (c, el) => !c.other && c.ids.every(id => el.id === id) && c.classes.every(k => (el.classes || []).includes(k))+// Descendant selectors only, which is all the list rules use: the last compound is the element,+// the others have to be found among its ancestors, in order.+function matches(selector, el, ancestors) {+ if (/[>+~:[]/.test(selector)) return false+ const parts = selector.split(/\s+/).map(compound)+ if (!fits(parts.at(-1), el)) return false+ let i = ancestors.length - 1+ for (const part of parts.slice(0, -1).reverse()) {+ while (i >= 0 && !fits(part, ancestors[i])) i--+ if (i < 0) return false+ i--+ }+ return true+}+const specificity = selector => {+ const c = selector.split(/\s+/).map(compound)+ return [c.reduce((n, x) => n + x.ids.length, 0), c.reduce((n, x) => n + x.classes.length, 0)]+}+const beats = (a, b) => a.spec[0] - b.spec[0] || a.spec[1] - b.spec[1] || a.order - b.order++// The `display` a list resolves to, given its own classes and its ancestors from the root down.+function displayOf(classes, ancestors) {+ let best = null+ for (const rule of rules) {+ const display = rule.decls.match(/(?:^|;)\s*display:([\w-]+)/)?.[1]+ if (!display) continue+ for (const selector of rule.selectors) {+ if (!matches(selector, { classes }, ancestors)) continue+ const hit = { display, spec: specificity(selector), order: rule.order }+ if (!best || beats(hit, best) > 0) best = hit+ }+ }+ return best?.display+}++const app = { id: 'app' }+const page = cls => ({ classes: [cls] })+const modal = { id: 'modal-root' }++describe('lists on a computer', () => {+ it('stay one column on a .narrow page (Home, Workout, Settings, Admin, CheckIn, the coach pages)', () => {+ expect(displayOf(['list'], [app, page('narrow')])).toBe('flex')+ // a list inside a card on the page, not a direct child of it+ expect(displayOf(['list'], [app, page('narrow'), page('card')])).toBe('flex')+ expect(displayOf(['list', 'routine-list'], [app, page('narrow')])).toBe('flex')+ })++ it('keep two columns on the full-width pages (Library, History, Stats, Plan, Muscles)', () => {+ expect(displayOf(['list'], [app])).toBe('grid')+ expect(displayOf(['list'], [app, page('card')])).toBe('grid')+ })++ it('stay one column in a sheet, and the routine editor’s list at any width', () => {+ expect(displayOf(['list'], [modal])).toBe('flex')+ expect(displayOf(['list', 'menu-list'], [modal])).toBe('flex')+ expect(displayOf(['list', 'routine-list'], [app])).toBe('flex')+ })++ it('reads the base rule outside the desktop block too', () => {+ expect(displayOf(['list'], [])).toBe('flex')+ })+})