From 314b09017be6b8d9c00f4c663c93b498f623aff4 Mon Sep 17 00:00:00 2001 From: Leon Babic Date: Mon, 21 Aug 2023 14:25:29 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20title=20to=20Plan?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EditPlan.tsx | 16 ++++++++++-- PlanItem.tsx | 43 +++++++++++++++++++------------ PlanList.tsx | 5 +++- migrations/1667186124792-plans.ts | 3 ++- plan.ts | 3 +++ 5 files changed, 49 insertions(+), 21 deletions(-) diff --git a/EditPlan.tsx b/EditPlan.tsx index 8afb93e..03c8ec0 100644 --- a/EditPlan.tsx +++ b/EditPlan.tsx @@ -14,10 +14,12 @@ import { PlanPageParams } from "./plan-page-params"; import StackHeader from "./StackHeader"; import Switch from "./Switch"; import { DAYS } from "./time"; +import AppInput from "./AppInput"; export default function EditPlan() { const { params } = useRoute>(); const { plan } = params; + const [title, setTitle] = useState(plan?.title); const [days, setDays] = useState( plan.days ? plan.days.split(",") : [] ); @@ -45,8 +47,13 @@ export default function EditPlan() { if (!days || !workouts) return; const newWorkouts = workouts.filter((workout) => workout).join(","); const newDays = days.filter((day) => day).join(","); - await planRepo.save({ days: newDays, workouts: newWorkouts, id: plan.id }); - }, [days, workouts, plan]); + await planRepo.save({ + title: title, + days: newDays, + workouts: newWorkouts, + id: plan.id, + }); + }, [title, days, workouts, plan]); const toggleWorkout = useCallback( (on: boolean, name: string) => { @@ -96,6 +103,11 @@ export default function EditPlan() { + setTitle(value)} + /> Days {DAYS.map((day) => ( ( + + {day === today ? ( + + {day} + + ) : ( + day + )} + {index === days.length - 1 ? "" : ", "} + + )); + const title = useMemo( () => - days.map((day, index) => ( - - {day === today ? ( - - {day} - - ) : ( - day - )} - {index === days.length - 1 ? "" : ", "} - - )), - [days, today] + item.title ? ( + {item.title} + ) : ( + currentDays + ), + [item.title, currentDays] ); const description = useMemo( - () => item.workouts.replace(/,/g, ", "), - [item.workouts] + () => (item.title ? currentDays : item.workouts.replace(/,/g, ", ")), + [item.title, currentDays, item.workouts] ); const backgroundColor = useMemo(() => { diff --git a/PlanList.tsx b/PlanList.tsx index 4cc5cca..fabf0a7 100644 --- a/PlanList.tsx +++ b/PlanList.tsx @@ -25,6 +25,7 @@ export default function PlanList() { planRepo .find({ where: [ + { title: Like(`%${value.trim()}%`) }, { days: Like(`%${value.trim()}%`) }, { workouts: Like(`%${value.trim()}%`) }, ], @@ -54,7 +55,9 @@ export default function PlanList() { ); const onAdd = () => - navigation.navigate("EditPlan", { plan: { days: "", workouts: "" } }); + navigation.navigate("EditPlan", { + plan: { title: "", days: "", workouts: "" }, + }); const edit = useCallback(async () => { const plan = await planRepo.findOne({ where: { id: ids.pop() } }); diff --git a/migrations/1667186124792-plans.ts b/migrations/1667186124792-plans.ts index 81fa4cc..9f8401b 100644 --- a/migrations/1667186124792-plans.ts +++ b/migrations/1667186124792-plans.ts @@ -5,10 +5,11 @@ export class plans1667186124792 implements MigrationInterface { await queryRunner.query(` CREATE TABLE IF NOT EXISTS plans ( id INTEGER PRIMARY KEY AUTOINCREMENT, + title TEXT NOT NULL, days TEXT NOT NULL, workouts TEXT NOT NULL ) -`) +`); } public async down(queryRunner: QueryRunner): Promise { diff --git a/plan.ts b/plan.ts index 1b747b8..6107581 100644 --- a/plan.ts +++ b/plan.ts @@ -5,6 +5,9 @@ export class Plan { @PrimaryGeneratedColumn() id?: number; + @Column("text") + title?: string; + @Column("text") days: string;