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,
});
console.log("Rerendered App");
useEffect(() => {
(async () => {
if (!AppDataSource.isInitialized) await AppDataSource.initialize();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

14
plan.ts
View File

@ -3,14 +3,20 @@ import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
@Entity("plans")
export class Plan {
@PrimaryGeneratedColumn()
id?: number;
@Column("text")
title?: string;
id: number;
@Column("text")
days: string;
@Column("text")
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()
export default class Settings {
@PrimaryColumn("boolean")
alarm: boolean;
alarm = false;
@Column("boolean")
vibrate: boolean;
vibrate = true;
@Column("text")
sound: string;
sound: string | null;
@Column("boolean")
notify: boolean;
notify = false;
@Column("boolean")
images: boolean;
images = true;
@Column("boolean")
showUnit: boolean;
showUnit = true;
@Column("text")
lightColor?: string;
lightColor: string | null;
@Column("text")
darkColor?: string;
darkColor: string | null;
@Column("boolean")
steps: boolean;
steps = true;
@Column("text")
date: string;
date: string | null;
@Column("boolean")
showDate: boolean;
showDate = false;
@Column("text")
theme: string;
theme: string | null;
@Column("boolean")
showSets: boolean;
noSound = false;
@Column("boolean")
noSound: boolean;
@Column("boolean")
backup: boolean;
backup = false;
@Column("text")
backupDir: string;
backupDir: string | null;
@Column("int")
duration: number;
duration: number | null;
@Column("text")
startup: string;
startup: string | null;
}

View File

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