parent
054ae4557d
commit
e65c053a62
15
App.tsx
15
App.tsx
|
@ -20,6 +20,7 @@ import { emitter } from "./emitter";
|
||||||
import { TickEvent } from "./TimerPage";
|
import { TickEvent } from "./TimerPage";
|
||||||
import { TOAST } from "./toast";
|
import { TOAST } from "./toast";
|
||||||
import { ThemeContext } from "./use-theme";
|
import { ThemeContext } from "./use-theme";
|
||||||
|
import Settings from "./settings";
|
||||||
|
|
||||||
export const CombinedDefaultTheme = {
|
export const CombinedDefaultTheme = {
|
||||||
...NavigationDefaultTheme,
|
...NavigationDefaultTheme,
|
||||||
|
@ -45,6 +46,7 @@ const App = () => {
|
||||||
const [snackbar, setSnackbar] = useState("");
|
const [snackbar, setSnackbar] = useState("");
|
||||||
const [appTheme, setAppTheme] = useState("system");
|
const [appTheme, setAppTheme] = useState("system");
|
||||||
const [progress, setProgress] = useState(0);
|
const [progress, setProgress] = useState(0);
|
||||||
|
const [settings, setSettings] = useState<Settings>();
|
||||||
|
|
||||||
const [lightColor, setLightColor] = useState<string>(
|
const [lightColor, setLightColor] = useState<string>(
|
||||||
CombinedDefaultTheme.colors.primary
|
CombinedDefaultTheme.colors.primary
|
||||||
|
@ -57,12 +59,15 @@ const App = () => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
if (!AppDataSource.isInitialized) await AppDataSource.initialize();
|
if (!AppDataSource.isInitialized) await AppDataSource.initialize();
|
||||||
const settings = await settingsRepo.findOne({ where: {} });
|
const gotSettings = await settingsRepo.findOne({ where: {} });
|
||||||
setAppTheme(settings.theme);
|
console.log({ gotSettings });
|
||||||
if (settings.lightColor) setLightColor(settings.lightColor);
|
setSettings(gotSettings);
|
||||||
if (settings.darkColor) setDarkColor(settings.darkColor);
|
setAppTheme(gotSettings.theme);
|
||||||
|
if (gotSettings.lightColor) setLightColor(gotSettings.lightColor);
|
||||||
|
if (gotSettings.darkColor) setDarkColor(gotSettings.darkColor);
|
||||||
setInitialized(true);
|
setInitialized(true);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const descriptions = [
|
const descriptions = [
|
||||||
emitter.addListener(TOAST, ({ value }: { value: string }) => {
|
emitter.addListener(TOAST, ({ value }: { value: string }) => {
|
||||||
setSnackbar(value);
|
setSnackbar(value);
|
||||||
|
@ -110,7 +115,7 @@ const App = () => {
|
||||||
setDarkColor,
|
setDarkColor,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<AppStack />
|
<AppStack settings={settings} />
|
||||||
</ThemeContext.Provider>
|
</ThemeContext.Provider>
|
||||||
)}
|
)}
|
||||||
</NavigationContainer>
|
</NavigationContainer>
|
||||||
|
|
|
@ -10,10 +10,19 @@ import SettingsPage from "./SettingsPage";
|
||||||
import TimerPage from "./TimerPage";
|
import TimerPage from "./TimerPage";
|
||||||
import useDark from "./use-dark";
|
import useDark from "./use-dark";
|
||||||
import WeightList from "./WeightList";
|
import WeightList from "./WeightList";
|
||||||
|
import Settings from "./settings";
|
||||||
|
import { StackScreenProps } from "@react-navigation/stack";
|
||||||
|
|
||||||
const Drawer = createDrawerNavigator<DrawerParams>();
|
const Drawer = createDrawerNavigator<DrawerParams>();
|
||||||
|
|
||||||
export default function AppDrawer() {
|
interface AppDrawerParams {
|
||||||
|
settings: Settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function AppDrawer({
|
||||||
|
route,
|
||||||
|
}: StackScreenProps<{ settings: AppDrawerParams }>) {
|
||||||
|
console.log(route.params.settings.startup);
|
||||||
const dark = useDark();
|
const dark = useDark();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -23,6 +32,9 @@ export default function AppDrawer() {
|
||||||
swipeEdgeWidth: 1000,
|
swipeEdgeWidth: 1000,
|
||||||
headerShown: false,
|
headerShown: false,
|
||||||
}}
|
}}
|
||||||
|
initialRouteName={
|
||||||
|
(route.params.settings.startup || "Home") as keyof DrawerParams
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<Drawer.Screen
|
<Drawer.Screen
|
||||||
name="Home"
|
name="Home"
|
||||||
|
|
10
AppStack.tsx
10
AppStack.tsx
|
@ -13,6 +13,7 @@ import ViewGraph from "./ViewGraph";
|
||||||
import ViewSetList from "./ViewSetList";
|
import ViewSetList from "./ViewSetList";
|
||||||
import ViewWeightGraph from "./ViewWeightGraph";
|
import ViewWeightGraph from "./ViewWeightGraph";
|
||||||
import Weight from "./weight";
|
import Weight from "./weight";
|
||||||
|
import Settings from "./settings";
|
||||||
|
|
||||||
export type StackParams = {
|
export type StackParams = {
|
||||||
Drawer: {};
|
Drawer: {};
|
||||||
|
@ -49,12 +50,17 @@ export type StackParams = {
|
||||||
|
|
||||||
const Stack = createStackNavigator<StackParams>();
|
const Stack = createStackNavigator<StackParams>();
|
||||||
|
|
||||||
export default function AppStack() {
|
export default function AppStack({ settings }: { settings: Settings }) {
|
||||||
|
console.log({ settings });
|
||||||
return (
|
return (
|
||||||
<Stack.Navigator
|
<Stack.Navigator
|
||||||
screenOptions={{ headerShown: false, animationEnabled: false }}
|
screenOptions={{ headerShown: false, animationEnabled: false }}
|
||||||
>
|
>
|
||||||
<Stack.Screen name="Drawer" component={AppDrawer} />
|
<Stack.Screen
|
||||||
|
name="Drawer"
|
||||||
|
component={AppDrawer}
|
||||||
|
initialParams={{ settings }}
|
||||||
|
/>
|
||||||
<Stack.Screen name="EditSet" component={EditSet} />
|
<Stack.Screen name="EditSet" component={EditSet} />
|
||||||
<Stack.Screen name="EditSets" component={EditSets} />
|
<Stack.Screen name="EditSets" component={EditSets} />
|
||||||
<Stack.Screen name="EditPlan" component={EditPlan} />
|
<Stack.Screen name="EditPlan" component={EditPlan} />
|
||||||
|
|
|
@ -122,6 +122,30 @@ export default function SettingsPage() {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
|
|
||||||
const data: Item[] = [
|
const data: Item[] = [
|
||||||
|
{
|
||||||
|
name: "Start up page",
|
||||||
|
renderItem: (name: string) => (
|
||||||
|
<Select
|
||||||
|
label={name}
|
||||||
|
items={[
|
||||||
|
{ label: "Home", value: "Home" },
|
||||||
|
{ label: "Exercises", value: "Exercises" },
|
||||||
|
{ label: "Plans", value: "Plans" },
|
||||||
|
{ label: "Graphs", value: "Graphs" },
|
||||||
|
{ label: "Timer", value: "Timer" },
|
||||||
|
{ label: "Weight", value: "Weight" },
|
||||||
|
{ label: "Insights", value: "Insights" },
|
||||||
|
{ label: "Settings", value: "Settings" },
|
||||||
|
]}
|
||||||
|
value={settings.startup}
|
||||||
|
onChange={async (value) => {
|
||||||
|
setValue("startup", value);
|
||||||
|
await update("startup", value);
|
||||||
|
toast(`App will always start on ${value}`);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "Theme",
|
name: "Theme",
|
||||||
renderItem: (name: string) => (
|
renderItem: (name: string) => (
|
||||||
|
|
|
@ -33,6 +33,7 @@ import { settingsDuration1699743753975 } from "./migrations/1699743753975-settin
|
||||||
import { Plan } from "./plan";
|
import { Plan } from "./plan";
|
||||||
import Settings from "./settings";
|
import Settings from "./settings";
|
||||||
import Weight from "./weight";
|
import Weight from "./weight";
|
||||||
|
import { settingsStartup1699783784680 } from "./migrations/1699783784680-settings-startup";
|
||||||
|
|
||||||
export const AppDataSource = new DataSource({
|
export const AppDataSource = new DataSource({
|
||||||
type: "react-native",
|
type: "react-native",
|
||||||
|
@ -72,5 +73,6 @@ export const AppDataSource = new DataSource({
|
||||||
exercises1699508495726,
|
exercises1699508495726,
|
||||||
exercisesFix1699613077628,
|
exercisesFix1699613077628,
|
||||||
settingsDuration1699743753975,
|
settingsDuration1699743753975,
|
||||||
|
settingsStartup1699783784680,
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
export type DrawerParams = {
|
export type DrawerParams = {
|
||||||
Home: {};
|
Home: {};
|
||||||
Settings: {};
|
|
||||||
Graphs: {};
|
|
||||||
Plans: {};
|
|
||||||
Exercises: {};
|
Exercises: {};
|
||||||
|
Plans: {};
|
||||||
|
Graphs: {};
|
||||||
Timer: {};
|
Timer: {};
|
||||||
Weight: {};
|
Weight: {};
|
||||||
Insights: {};
|
Insights: {};
|
||||||
|
Settings: {};
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class settingsStartup1699783784680 implements MigrationInterface {
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query("ALTER TABLE settings ADD COLUMN startup TEXT");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {}
|
||||||
|
}
|
|
@ -49,4 +49,7 @@ export default class Settings {
|
||||||
|
|
||||||
@Column("int")
|
@Column("int")
|
||||||
duration: number;
|
duration: number;
|
||||||
|
|
||||||
|
@Column("text")
|
||||||
|
startup: string;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue