Merge !85: feat: add copy routine button to RoutineEdit view
# Conflicts: # frontend/src/lib/pt-br-locale.test.js
This commit is contained in:
commit
4bca5336d1
17 files changed
+126
No files matched your search
@@ -0,0 +1,12 @@
|
||||
import { uid } from './format.js'
|
||||
|
||||
/**
|
||||
* Create a deep copy of a routine with a new id and a "(Copy)" suffix.
|
||||
* All exercises and their configuration are preserved independently.
|
||||
*/
|
||||
export function copyRoutine(routine, suffix = 'Copy') {
|
||||
const copy = structuredClone(routine)
|
||||
copy.id = uid()
|
||||
copy.name = routine.name + ' (' + suffix + ')'
|
||||
return copy
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { copyRoutine } from './routines.js'
|
||||
|
||||
const routine = {
|
||||
id: 'r1',
|
||||
name: 'Push Day',
|
||||
emoji: 'arm',
|
||||
prog: 'linear',
|
||||
ex: [
|
||||
{ id: 'ex1', sets: 3, reps: 10, weight: 60, sg: 'sg1' },
|
||||
{ id: 'ex2', sets: 4, reps: 8, weight: 80, sg: 'sg1' },
|
||||
{ id: 'ex3', sets: 3, reps: 12, weight: 20 }
|
||||
]
|
||||
}
|
||||
|
||||
describe('copyRoutine', () => {
|
||||
it('returns a new routine with a different id', () => {
|
||||
const copy = copyRoutine(routine)
|
||||
expect(copy.id).not.toBe(routine.id)
|
||||
expect(copy.id).toBeTruthy()
|
||||
})
|
||||
|
||||
it('appends "(Copy)" to the name by default', () => {
|
||||
const copy = copyRoutine(routine)
|
||||
expect(copy.name).toBe('Push Day (Copy)')
|
||||
})
|
||||
|
||||
it('uses a custom suffix when provided', () => {
|
||||
const copy = copyRoutine(routine, 'Kopie')
|
||||
expect(copy.name).toBe('Push Day (Kopie)')
|
||||
})
|
||||
|
||||
it('deep-copies all exercises with their configuration', () => {
|
||||
const copy = copyRoutine(routine)
|
||||
expect(copy.ex).toHaveLength(3)
|
||||
expect(copy.ex[0]).toEqual(routine.ex[0])
|
||||
expect(copy.ex[1]).toEqual(routine.ex[1])
|
||||
expect(copy.ex[2]).toEqual(routine.ex[2])
|
||||
})
|
||||
|
||||
it('preserves exercise ids (references to the global library)', () => {
|
||||
const copy = copyRoutine(routine)
|
||||
expect(copy.ex[0].id).toBe('ex1')
|
||||
expect(copy.ex[1].id).toBe('ex2')
|
||||
expect(copy.ex[2].id).toBe('ex3')
|
||||
})
|
||||
|
||||
it('preserves superset groupings', () => {
|
||||
const copy = copyRoutine(routine)
|
||||
expect(copy.ex[0].sg).toBe('sg1')
|
||||
expect(copy.ex[1].sg).toBe('sg1')
|
||||
expect(copy.ex[2].sg).toBeUndefined()
|
||||
})
|
||||
|
||||
it('preserves the emoji and progression settings', () => {
|
||||
const copy = copyRoutine(routine)
|
||||
expect(copy.emoji).toBe('arm')
|
||||
expect(copy.prog).toBe('linear')
|
||||
})
|
||||
|
||||
it('produces an independent copy — mutating it does not affect the original', () => {
|
||||
const copy = copyRoutine(routine)
|
||||
copy.name = 'Modified'
|
||||
copy.ex[0].weight = 999
|
||||
copy.ex.push({ id: 'ex4', sets: 5, reps: 5 })
|
||||
|
||||
expect(routine.name).toBe('Push Day')
|
||||
expect(routine.ex[0].weight).toBe(60)
|
||||
expect(routine.ex).toHaveLength(3)
|
||||
})
|
||||
|
||||
it('handles a routine with no exercises', () => {
|
||||
const empty = { id: 'r2', name: 'Empty', emoji: 'dumbbell', ex: [] }
|
||||
const copy = copyRoutine(empty)
|
||||
expect(copy.ex).toEqual([])
|
||||
expect(copy.name).toBe('Empty (Copy)')
|
||||
expect(copy.id).not.toBe('r2')
|
||||
})
|
||||
})
|
||||
@@ -247,6 +247,8 @@ export default {
|
||||
'Delete routine?': 'Routine löschen?',
|
||||
'“{0}” and its exercises will be removed.': '„{0}“ und ihre Übungen werden entfernt.',
|
||||
'Delete routine': 'Routine löschen',
|
||||
'Copy routine': 'Routine kopieren',
|
||||
'Copy': 'Kopie',
|
||||
// --- library / history ---
|
||||
'{0} exercises with animations': '{0} Übungen mit Animationen',
|
||||
'Search…': 'Suchen…',
|
||||
|
||||
@@ -236,6 +236,8 @@ export default {
|
||||
'Delete routine?': '¿Eliminar rutina?',
|
||||
'“{0}” and its exercises will be removed.': '«{0}» y sus ejercicios se eliminarán.',
|
||||
'Delete routine': 'Eliminar rutina',
|
||||
'Copy routine': 'Copiar rutina',
|
||||
'Copy': 'Copia',
|
||||
'{0} exercises with animations': '{0} ejercicios con animaciones',
|
||||
'Search…': 'Buscar…',
|
||||
'No workouts yet.': 'Aún no hay entrenamientos.',
|
||||
|
||||
@@ -236,6 +236,8 @@ export default {
|
||||
'Delete routine?': 'Supprimer la routine ?',
|
||||
'“{0}” and its exercises will be removed.': '« {0} » et ses exercices seront supprimés.',
|
||||
'Delete routine': 'Supprimer la routine',
|
||||
'Copy routine': 'Copier la routine',
|
||||
'Copy': 'Copie',
|
||||
'{0} exercises with animations': '{0} exercices avec animations',
|
||||
'Search…': 'Rechercher…',
|
||||
'No workouts yet.': 'Aucune séance pour l’instant.',
|
||||
|
||||
@@ -236,6 +236,8 @@ export default {
|
||||
'Delete routine?': 'रूटीन हटाएँ?',
|
||||
'“{0}” and its exercises will be removed.': '"{0}" और उसके व्यायाम हटा दिए जाएँगे।',
|
||||
'Delete routine': 'रूटीन हटाएँ',
|
||||
'Copy routine': 'रूटीन कॉपी करें',
|
||||
'Copy': 'कॉपी',
|
||||
'{0} exercises with animations': 'एनिमेशन के साथ {0} व्यायाम',
|
||||
'Search…': 'खोजें…',
|
||||
'No workouts yet.': 'अभी कोई वर्कआउट नहीं।',
|
||||
|
||||
@@ -240,6 +240,8 @@ export default {
|
||||
'Delete routine?': 'Törlöd a rutint?',
|
||||
'“{0}” and its exercises will be removed.': '„{0}” és a gyakorlatai el lesznek távolítva.',
|
||||
'Delete routine': 'Rutin törlése',
|
||||
'Copy routine': 'Rutin másolása',
|
||||
'Copy': 'Másolat',
|
||||
// --- library / history ---
|
||||
'{0} exercises with animations': '{0} gyakorlat animációval',
|
||||
'Search…': 'Keresés…',
|
||||
|
||||
@@ -236,6 +236,8 @@ export default {
|
||||
'Delete routine?': 'Eliminare routine?',
|
||||
'“{0}” and its exercises will be removed.': '«{0}» e i suoi esercizi verranno rimossi.',
|
||||
'Delete routine': 'Elimina routine',
|
||||
'Copy routine': 'Copia routine',
|
||||
'Copy': 'Copia',
|
||||
'{0} exercises with animations': '{0} esercizi con animazioni',
|
||||
'Search…': 'Cerca…',
|
||||
'No workouts yet.': 'Ancora nessun allenamento.',
|
||||
|
||||
@@ -236,6 +236,8 @@ export default {
|
||||
'Delete routine?': '루틴을 삭제할까요?',
|
||||
'“{0}” and its exercises will be removed.': '"{0}"과(와) 그 운동들이 삭제됩니다.',
|
||||
'Delete routine': '루틴 삭제',
|
||||
'Copy routine': '루틴 복사',
|
||||
'Copy': '복사본',
|
||||
'{0} exercises with animations': '애니메이션이 있는 운동 {0}개',
|
||||
'Search…': '검색…',
|
||||
'No workouts yet.': '아직 운동 기록이 없어요.',
|
||||
|
||||
@@ -236,6 +236,8 @@ export default {
|
||||
'Delete routine?': 'Usunąć plan?',
|
||||
'“{0}” and its exercises will be removed.': '„{0}” i jego ćwiczenia zostaną usunięte.',
|
||||
'Delete routine': 'Usuń plan',
|
||||
'Copy routine': 'Kopiuj plan',
|
||||
'Copy': 'Kopia',
|
||||
'{0} exercises with animations': '{0} ćwiczeń z animacjami',
|
||||
'Search…': 'Szukaj…',
|
||||
'No workouts yet.': 'Brak treningów.',
|
||||
|
||||
@@ -76,6 +76,8 @@ export const PT_BR_OVERRIDES = {
|
||||
'Tap the link button on an exercise to superset it with the one above — you’ll do them back-to-back.': 'Toque no botão de vínculo de um exercício para combiná-lo em um superset com o exercício acima — eles serão feitos em sequência.',
|
||||
'Delete routine?': 'Excluir rotina?',
|
||||
'Delete routine': 'Excluir rotina',
|
||||
'Copy routine': 'Copiar rotina',
|
||||
'Copy': 'Cópia',
|
||||
'Search…': 'Buscar…',
|
||||
'Starter plan loaded — Mon Push · Wed Pull · Fri Legs': 'Plano inicial carregado — Seg Push · Qua Pull · Sex Pernas',
|
||||
'{0} planned for {1}': '{0} planejado para {1}',
|
||||
|
||||
@@ -236,6 +236,8 @@ export default {
|
||||
'Delete routine?': 'Eliminar rotina?',
|
||||
'“{0}” and its exercises will be removed.': '«{0}» e os seus exercícios serão removidos.',
|
||||
'Delete routine': 'Eliminar rotina',
|
||||
'Copy routine': 'Copiar rotina',
|
||||
'Copy': 'Cópia',
|
||||
'{0} exercises with animations': '{0} exercícios com animações',
|
||||
'Search…': 'Pesquisar…',
|
||||
'No workouts yet.': 'Ainda sem treinos.',
|
||||
|
||||
@@ -236,6 +236,8 @@ export default {
|
||||
'Delete routine?': 'Удалить программу?',
|
||||
'“{0}” and its exercises will be removed.': '«{0}» и её упражнения будут удалены.',
|
||||
'Delete routine': 'Удалить программу',
|
||||
'Copy routine': 'Копировать программу',
|
||||
'Copy': 'Копия',
|
||||
'{0} exercises with animations': '{0} упражнений с анимациями',
|
||||
'Search…': 'Поиск…',
|
||||
'No workouts yet.': 'Тренировок пока нет.',
|
||||
|
||||
@@ -240,6 +240,8 @@ export default {
|
||||
'Delete routine?': 'ลบรูทีนนี้?',
|
||||
'“{0}” and its exercises will be removed.': '“{0}” และท่าทั้งหมดในนั้นจะถูกลบ',
|
||||
'Delete routine': 'ลบรูทีน',
|
||||
'Copy routine': 'คัดลอกรูทีน',
|
||||
'Copy': 'สำเนา',
|
||||
// --- library / history ---
|
||||
'{0} exercises with animations': '{0} ท่าพร้อมภาพเคลื่อนไหว',
|
||||
'Search…': 'ค้นหา…',
|
||||
|
||||
@@ -236,6 +236,8 @@ export default {
|
||||
'Delete routine?': 'Rutin silinsin mi?',
|
||||
'“{0}” and its exercises will be removed.': '“{0}” ve egzersizleri kaldırılacak.',
|
||||
'Delete routine': 'Rutini sil',
|
||||
'Copy routine': 'Rutini kopyala',
|
||||
'Copy': 'Kopya',
|
||||
'{0} exercises with animations': 'animasyonlu {0} egzersiz',
|
||||
'Search…': 'Ara…',
|
||||
'No workouts yet.': 'Henüz antrenman yok.',
|
||||
|
||||
@@ -236,6 +236,8 @@ export default {
|
||||
'Delete routine?': '删除训练日?',
|
||||
'“{0}” and its exercises will be removed.': '“{0}”及其动作将被移除。',
|
||||
'Delete routine': '删除训练日',
|
||||
'Copy routine': '复制训练日',
|
||||
'Copy': '副本',
|
||||
'{0} exercises with animations': '{0} 个带动画的动作',
|
||||
'Search…': '搜索…',
|
||||
'No workouts yet.': '还没有训练。',
|
||||
|
||||
@@ -11,6 +11,7 @@ import { glyphPicker, exercisePicker, exConfigSheet, confirmSheet } from '../she
|
||||
import Icon from '../components/Icon.jsx'
|
||||
import { glyphOf } from '../lib/glyphs.js'
|
||||
import { Button, Row, SelectRow, Switch } from '../components/ui.jsx'
|
||||
import { copyRoutine } from '../lib/routines.js'
|
||||
import { POLICIES_FOR, POLICY_NAME, POLICY_DESC } from '../lib/progression.js'
|
||||
import BodyMap from '../components/BodyMap.jsx'
|
||||
import { loadOfRoutine, rankOf, MUSCLE_NAME } from '../lib/muscles.js'
|
||||
@@ -425,6 +426,12 @@ export default function RoutineEdit() {
|
||||
<div className="small dim row" style={{ margin: '10px 2px', gap: 5 }}><Icon name="link" style={{ fontSize: 13 }} />{t('Tap the link button on an exercise to superset it with the one above — you’ll do them back-to-back.')}</div>
|
||||
<Button variant="primary" onClick={() => exercisePicker(ex => exConfigSheet(ex, null, cfg => edit(x => { x.push({ id: ex.id, ...cfg }) }), null, r))} icon="plus">{t('Add exercise')}</Button>
|
||||
<div style={{ height: 10 }} />
|
||||
<Button onClick={() => {
|
||||
const copy = copyRoutine(r, t('Copy'))
|
||||
update(s => { s.routines.push(copy) })
|
||||
nav('/plan/r/' + copy.id)
|
||||
}}>{t('Copy routine')}</Button>
|
||||
<div style={{ height: 10 }} />
|
||||
<Button variant="danger" onClick={() => confirmSheet({
|
||||
title: t('Delete routine?'), message: t('“{0}” and its exercises will be removed.', r.name), confirmText: t('Delete'), danger: true,
|
||||
onConfirm: () => {
|
||||
|
||||
Reference in new issue
Block a user