Fix some database drift

This commit is contained in:
Brandon Presley 2023-11-13 18:13:23 +13:00
parent 6950cd04f4
commit 1ac78de724
12 changed files with 60 additions and 60 deletions

View File

@ -46,8 +46,6 @@ const App = () => {
darkColor: CombinedDarkTheme.colors.primary, darkColor: CombinedDarkTheme.colors.primary,
}); });
console.log("Rerendered App");
useEffect(() => { useEffect(() => {
(async () => { (async () => {
if (!AppDataSource.isInitialized) await AppDataSource.initialize(); if (!AppDataSource.isInitialized) await AppDataSource.initialize();

View File

@ -6,39 +6,38 @@ import EditPlan from "./EditPlan";
import EditSet from "./EditSet"; import EditSet from "./EditSet";
import EditSets from "./EditSets"; import EditSets from "./EditSets";
import EditWeight from "./EditWeight"; import EditWeight from "./EditWeight";
import GymSet from "./gym-set";
import { Plan } from "./plan";
import StartPlan from "./StartPlan"; import StartPlan from "./StartPlan";
import ViewGraph from "./ViewGraph"; import ViewGraph from "./ViewGraph";
import ViewSetList from "./ViewSetList"; import ViewSetList from "./ViewSetList";
import ViewWeightGraph from "./ViewWeightGraph"; import ViewWeightGraph from "./ViewWeightGraph";
import GymSet from "./gym-set";
import { Plan } from "./plan";
import Weight from "./weight"; import Weight from "./weight";
import Settings from "./settings";
export type StackParams = { export type StackParams = {
Drawer: {}; Drawer: {};
EditSet: { EditSet: {
set: GymSet; set: Partial<GymSet>;
}; };
EditSets: { EditSets: {
ids: number[]; ids: number[];
}; };
EditPlan: { EditPlan: {
plan: Plan; plan: Partial<Plan>;
}; };
StartPlan: { StartPlan: {
plan: Plan; plan: Plan;
first?: GymSet; first: Partial<GymSet>;
}; };
ViewGraph: { ViewGraph: {
name: string; name: string;
}; };
EditWeight: { EditWeight: {
weight: Weight; weight: Partial<Weight>;
}; };
ViewWeightGraph: {}; ViewWeightGraph: {};
EditExercise: { EditExercise: {
gymSet: GymSet; gymSet: Partial<GymSet>;
}; };
EditExercises: { EditExercises: {
names: string[]; names: string[];

View File

@ -21,7 +21,7 @@ import { MARGIN, PADDING } from "./constants";
import { DAYS } from "./days"; import { DAYS } from "./days";
import { planRepo, setRepo } from "./db"; import { planRepo, setRepo } from "./db";
import { DrawerParams } from "./drawer-param-list"; import { DrawerParams } from "./drawer-param-list";
import { defaultSet } from "./gym-set"; import GymSet, { defaultSet } from "./gym-set";
import StackHeader from "./StackHeader"; import StackHeader from "./StackHeader";
import Switch from "./Switch"; import Switch from "./Switch";
@ -144,7 +144,7 @@ export default function EditPlan() {
const newPlan = await planRepo.findOne({ const newPlan = await planRepo.findOne({
where: { id: plan.id }, where: { id: plan.id },
}); });
let first = await setRepo.findOne({ let first: Partial<GymSet> = await setRepo.findOne({
where: { name: exercises[0] }, where: { name: exercises[0] },
order: { created: "desc" }, order: { created: "desc" },
}); });

View File

@ -12,7 +12,7 @@ import { LIMIT } from "./constants";
import { setRepo, settingsRepo } from "./db"; import { setRepo, settingsRepo } from "./db";
import DrawerHeader from "./DrawerHeader"; import DrawerHeader from "./DrawerHeader";
import ExerciseItem from "./ExerciseItem"; import ExerciseItem from "./ExerciseItem";
import GymSet from "./gym-set"; import GymSet, { defaultSet } from "./gym-set";
import ListMenu from "./ListMenu"; import ListMenu from "./ListMenu";
import Page from "./Page"; import Page from "./Page";
import SetList from "./SetList"; import SetList from "./SetList";
@ -92,7 +92,7 @@ export default function ExerciseList() {
const onAdd = useCallback(async () => { const onAdd = useCallback(async () => {
navigation.navigate("EditExercise", { navigation.navigate("EditExercise", {
gymSet: new GymSet(), gymSet: defaultSet,
}); });
}, [navigation]); }, [navigation]);

View File

@ -10,7 +10,7 @@ import { StackParams } from "./AppStack";
import { DARK_RIPPLE, LIGHT_RIPPLE } from "./constants"; import { DARK_RIPPLE, LIGHT_RIPPLE } from "./constants";
import { DAYS } from "./days"; import { DAYS } from "./days";
import { setRepo } from "./db"; import { setRepo } from "./db";
import { defaultSet } from "./gym-set"; import GymSet, { defaultSet } from "./gym-set";
import { Plan } from "./plan"; import { Plan } from "./plan";
import useDark from "./use-dark"; import useDark from "./use-dark";
@ -37,7 +37,7 @@ export default function PlanItem({
const start = useCallback(async () => { const start = useCallback(async () => {
const exercise = item.exercises.split(",")[0]; const exercise = item.exercises.split(",")[0];
let first = await setRepo.findOne({ let first: Partial<GymSet> = await setRepo.findOne({
where: { name: exercise }, where: { name: exercise },
order: { created: "desc" }, order: { created: "desc" },
}); });

View File

@ -12,7 +12,7 @@ import { planRepo } from "./db";
import DrawerHeader from "./DrawerHeader"; import DrawerHeader from "./DrawerHeader";
import ListMenu from "./ListMenu"; import ListMenu from "./ListMenu";
import Page from "./Page"; import Page from "./Page";
import { Plan } from "./plan"; import { Plan, defaultPlan } from "./plan";
import PlanItem from "./PlanItem"; import PlanItem from "./PlanItem";
export default function PlanList() { export default function PlanList() {
@ -58,7 +58,7 @@ export default function PlanList() {
const onAdd = () => const onAdd = () =>
navigation.navigate("EditPlan", { navigation.navigate("EditPlan", {
plan: { title: "", days: "", exercises: "" }, plan: defaultPlan,
}); });
const edit = useCallback(async () => { const edit = useCallback(async () => {

View File

@ -8,13 +8,13 @@ import { FlatList } from "react-native";
import { List } from "react-native-paper"; import { List } from "react-native-paper";
import { Like } from "typeorm"; import { Like } from "typeorm";
import { StackParams } from "./AppStack"; import { StackParams } from "./AppStack";
import { LIMIT } from "./constants";
import { getNow, setRepo, settingsRepo } from "./db";
import DrawerHeader from "./DrawerHeader"; import DrawerHeader from "./DrawerHeader";
import GymSet, { defaultSet } from "./gym-set";
import ListMenu from "./ListMenu"; import ListMenu from "./ListMenu";
import Page from "./Page"; import Page from "./Page";
import SetItem from "./SetItem"; import SetItem from "./SetItem";
import { LIMIT } from "./constants";
import { getNow, setRepo, settingsRepo } from "./db";
import GymSet, { defaultSet } from "./gym-set";
import Settings from "./settings"; import Settings from "./settings";
export default function SetList() { export default function SetList() {
@ -35,8 +35,8 @@ export default function SetList() {
skip: 0, skip: 0,
order: { created: "DESC" }, order: { created: "DESC" },
}); });
console.log(`${SetList.name}.reset:`, { value, offset });
setSets(newSets); setSets(newSets);
console.log(`${SetList.name}.reset:`, { value, offset });
setEnd(false); setEnd(false);
}, },
[offset] [offset]
@ -95,7 +95,7 @@ export default function SetList() {
const onAdd = useCallback(async () => { const onAdd = useCallback(async () => {
const now = await getNow(); const now = await getNow();
let set = sets?.[0]; let set: Partial<GymSet> = { ...sets[0] };
if (!set) set = { ...defaultSet }; if (!set) set = { ...defaultSet };
set.created = now; set.created = now;
delete set.id; delete set.id;
@ -150,7 +150,7 @@ export default function SetList() {
onEndReached={next} onEndReached={next}
onEndReachedThreshold={0.5} onEndReachedThreshold={0.5}
refreshing={refreshing} refreshing={refreshing}
keyExtractor={(set) => set.id?.toString()} keyExtractor={(set) => set.id.toString()}
onRefresh={() => { onRefresh={() => {
setOffset(0); setOffset(0);
setRefreshing(true); setRefreshing(true);

View File

@ -100,7 +100,7 @@ export default function WeightList() {
const onAdd = useCallback(async () => { const onAdd = useCallback(async () => {
const now = await getNow(); const now = await getNow();
let weight = weights?.[0]; let weight: Partial<Weight> = { ...weights[0] };
if (!weight) weight = { ...defaultWeight }; if (!weight) weight = { ...defaultWeight };
weight.created = now; weight.created = now;
delete weight.id; delete weight.id;

View File

@ -7,7 +7,7 @@ export const GYM_SET_CREATED = "gym-set-created";
@Entity("sets") @Entity("sets")
export default class GymSet { export default class GymSet {
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
id?: number; id: number;
@Column("text") @Column("text")
name: string; name: string;
@ -18,6 +18,9 @@ export default class GymSet {
@Column("int") @Column("int")
weight: number; weight: number;
@Column("text")
created: string;
@Column("int") @Column("int")
sets = 3; sets = 3;
@ -31,19 +34,16 @@ export default class GymSet {
hidden = false; hidden = false;
@Column("text") @Column("text")
created: string; unit = "kg";
@Column("text") @Column("text")
unit: string; image: string | null;
@Column("text") @Column("text")
image: string; steps: string | null;
@Column("text")
steps?: string;
} }
export const defaultSet: GymSet = { export const defaultSet: Partial<GymSet> = {
created: "", created: "",
name: "", name: "",
image: "", image: "",

14
plan.ts
View File

@ -3,14 +3,20 @@ import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
@Entity("plans") @Entity("plans")
export class Plan { export class Plan {
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
id?: number; id: number;
@Column("text")
title?: string;
@Column("text") @Column("text")
days: string; days: string;
@Column("text") @Column("text")
exercises: string; exercises: string;
@Column("text")
title: string | null;
} }
export const defaultPlan: Partial<Plan> = {
days: "",
exercises: "",
title: "",
};

View File

@ -3,56 +3,53 @@ import { Column, Entity, PrimaryColumn } from "typeorm";
@Entity() @Entity()
export default class Settings { export default class Settings {
@PrimaryColumn("boolean") @PrimaryColumn("boolean")
alarm: boolean; alarm = false;
@Column("boolean") @Column("boolean")
vibrate: boolean; vibrate = true;
@Column("text") @Column("text")
sound: string; sound: string | null;
@Column("boolean") @Column("boolean")
notify: boolean; notify = false;
@Column("boolean") @Column("boolean")
images: boolean; images = true;
@Column("boolean") @Column("boolean")
showUnit: boolean; showUnit = true;
@Column("text") @Column("text")
lightColor?: string; lightColor: string | null;
@Column("text") @Column("text")
darkColor?: string; darkColor: string | null;
@Column("boolean") @Column("boolean")
steps: boolean; steps = true;
@Column("text") @Column("text")
date: string; date: string | null;
@Column("boolean") @Column("boolean")
showDate: boolean; showDate = false;
@Column("text") @Column("text")
theme: string; theme: string | null;
@Column("boolean") @Column("boolean")
showSets: boolean; noSound = false;
@Column("boolean") @Column("boolean")
noSound: boolean; backup = false;
@Column("boolean")
backup: boolean;
@Column("text") @Column("text")
backupDir: string; backupDir: string | null;
@Column("int") @Column("int")
duration: number; duration: number | null;
@Column("text") @Column("text")
startup: string; startup: string | null;
} }

View File

@ -3,7 +3,7 @@ import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
@Entity("weights") @Entity("weights")
export default class Weight { export default class Weight {
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
id?: number; id: number;
@Column("int") @Column("int")
value: number; value: number;
@ -12,10 +12,10 @@ export default class Weight {
created: string; created: string;
@Column("text") @Column("text")
unit: string; unit = "kg";
} }
export const defaultWeight: Weight = { export const defaultWeight: Partial<Weight> = {
created: "", created: "",
unit: "kg", unit: "kg",
value: 0, value: 0,