diff --git a/frontend/src/lib/routines.js b/frontend/src/lib/routines.js new file mode 100644 index 0000000..7613b30 --- /dev/null +++ b/frontend/src/lib/routines.js @@ -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 +} diff --git a/frontend/src/lib/routines.test.js b/frontend/src/lib/routines.test.js new file mode 100644 index 0000000..8c6912b --- /dev/null +++ b/frontend/src/lib/routines.test.js @@ -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') + }) +}) diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.js index 2874b21..4c84a00 100644 --- a/frontend/src/locales/de.js +++ b/frontend/src/locales/de.js @@ -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…', diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js index 0c4f8f0..3f3b361 100644 --- a/frontend/src/locales/es.js +++ b/frontend/src/locales/es.js @@ -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.', diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.js index 49dd9db..654e131 100644 --- a/frontend/src/locales/fr.js +++ b/frontend/src/locales/fr.js @@ -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.', diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.js index ea3cc2d..66b2794 100644 --- a/frontend/src/locales/hi.js +++ b/frontend/src/locales/hi.js @@ -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.': 'अभी कोई वर्कआउट नहीं।', diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.js index 7db3376..b40d7ac 100644 --- a/frontend/src/locales/hu.js +++ b/frontend/src/locales/hu.js @@ -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…', diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.js index ea66bc5..5c04c36 100644 --- a/frontend/src/locales/it.js +++ b/frontend/src/locales/it.js @@ -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.', diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.js index a1834b0..5a29281 100644 --- a/frontend/src/locales/ko.js +++ b/frontend/src/locales/ko.js @@ -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.': '아직 운동 기록이 없어요.', diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.js index 1fd55c0..40b2359 100644 --- a/frontend/src/locales/pl.js +++ b/frontend/src/locales/pl.js @@ -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.', diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.js index a6060bd..0e6fe5e 100644 --- a/frontend/src/locales/pt-BR.js +++ b/frontend/src/locales/pt-BR.js @@ -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}', diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.js index 7336910..6ad33e3 100644 --- a/frontend/src/locales/pt.js +++ b/frontend/src/locales/pt.js @@ -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.', diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.js index f296cae..fd8054f 100644 --- a/frontend/src/locales/ru.js +++ b/frontend/src/locales/ru.js @@ -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.': 'Тренировок пока нет.', diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.js index 7ad3a61..bb94261 100644 --- a/frontend/src/locales/th.js +++ b/frontend/src/locales/th.js @@ -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…': 'ค้นหา…', diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.js index 225edf1..610249d 100644 --- a/frontend/src/locales/tr.js +++ b/frontend/src/locales/tr.js @@ -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.', diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.js index 4571116..a8cd713 100644 --- a/frontend/src/locales/zh.js +++ b/frontend/src/locales/zh.js @@ -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.': '还没有训练。', diff --git a/frontend/src/views/RoutineEdit.jsx b/frontend/src/views/RoutineEdit.jsx index 701b062..bedef96 100644 --- a/frontend/src/views/RoutineEdit.jsx +++ b/frontend/src/views/RoutineEdit.jsx @@ -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() {