parent
054ae4557d
commit
e65c053a62
15
App.tsx
15
App.tsx
|
@ -20,6 +20,7 @@ import { emitter } from "./emitter";
|
|||
import { TickEvent } from "./TimerPage";
|
||||
import { TOAST } from "./toast";
|
||||
import { ThemeContext } from "./use-theme";
|
||||
import Settings from "./settings";
|
||||
|
||||
export const CombinedDefaultTheme = {
|
||||
...NavigationDefaultTheme,
|
||||
|
@ -45,6 +46,7 @@ const App = () => {
|
|||
const [snackbar, setSnackbar] = useState("");
|
||||
const [appTheme, setAppTheme] = useState("system");
|
||||
const [progress, setProgress] = useState(0);
|
||||
const [settings, setSettings] = useState<Settings>();
|
||||
|
||||
const [lightColor, setLightColor] = useState<string>(
|
||||
CombinedDefaultTheme.colors.primary
|
||||
|
@ -57,12 +59,15 @@ const App = () => {
|
|||
useEffect(() => {
|
||||
(async () => {
|
||||
if (!AppDataSource.isInitialized) await AppDataSource.initialize();
|
||||
const settings = await settingsRepo.findOne({ where: {} });
|
||||
setAppTheme(settings.theme);
|
||||
if (settings.lightColor) setLightColor(settings.lightColor);
|
||||
if (settings.darkColor) setDarkColor(settings.darkColor);
|
||||
const gotSettings = await settingsRepo.findOne({ where: {} });
|
||||
console.log({ gotSettings });
|
||||
setSettings(gotSettings);
|
||||
setAppTheme(gotSettings.theme);
|
||||
if (gotSettings.lightColor) setLightColor(gotSettings.lightColor);
|
||||
if (gotSettings.darkColor) setDarkColor(gotSettings.darkColor);
|
||||
setInitialized(true);
|
||||
})();
|
||||
|
||||
const descriptions = [
|
||||
emitter.addListener(TOAST, ({ value }: { value: string }) => {
|
||||
setSnackbar(value);
|
||||
|
@ -110,7 +115,7 @@ const App = () => {
|
|||
setDarkColor,
|
||||
}}
|
||||
>
|
||||
<AppStack />
|
||||
<AppStack settings={settings} />
|
||||
</ThemeContext.Provider>
|
||||
)}
|
||||
</NavigationContainer>
|
||||
|
|
|
@ -10,10 +10,19 @@ import SettingsPage from "./SettingsPage";
|
|||
import TimerPage from "./TimerPage";
|
||||
import useDark from "./use-dark";
|
||||
import WeightList from "./WeightList";
|
||||
import Settings from "./settings";
|
||||
import { StackScreenProps } from "@react-navigation/stack";
|
||||
|
||||
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();
|
||||
|
||||
return (
|
||||
|
@ -23,6 +32,9 @@ export default function AppDrawer() {
|
|||
swipeEdgeWidth: 1000,
|
||||
headerShown: false,
|
||||
}}
|
||||
initialRouteName={
|
||||
(route.params.settings.startup || "Home") as keyof DrawerParams
|
||||
}
|
||||
>
|
||||
<Drawer.Screen
|
||||
name="Home"
|
||||
|
|
10
AppStack.tsx
10
AppStack.tsx
|
@ -13,6 +13,7 @@ import ViewGraph from "./ViewGraph";
|
|||
import ViewSetList from "./ViewSetList";
|
||||
import ViewWeightGraph from "./ViewWeightGraph";
|
||||
import Weight from "./weight";
|
||||
import Settings from "./settings";
|
||||
|
||||
export type StackParams = {
|
||||
Drawer: {};
|
||||
|
@ -49,12 +50,17 @@ export type StackParams = {
|
|||
|
||||
const Stack = createStackNavigator<StackParams>();
|
||||
|
||||
export default function AppStack() {
|
||||
export default function AppStack({ settings }: { settings: Settings }) {
|
||||
console.log({ settings });
|
||||
return (
|
||||
<Stack.Navigator
|
||||
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="EditSets" component={EditSets} />
|
||||
<Stack.Screen name="EditPlan" component={EditPlan} />
|
||||
|
|
|
@ -122,6 +122,30 @@ export default function SettingsPage() {
|
|||
const today = new Date();
|
||||
|
||||
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",
|
||||
renderItem: (name: string) => (
|
||||
|
|
|
@ -33,6 +33,7 @@ import { settingsDuration1699743753975 } from "./migrations/1699743753975-settin
|
|||
import { Plan } from "./plan";
|
||||
import Settings from "./settings";
|
||||
import Weight from "./weight";
|
||||
import { settingsStartup1699783784680 } from "./migrations/1699783784680-settings-startup";
|
||||
|
||||
export const AppDataSource = new DataSource({
|
||||
type: "react-native",
|
||||
|
@ -72,5 +73,6 @@ export const AppDataSource = new DataSource({
|
|||
exercises1699508495726,
|
||||
exercisesFix1699613077628,
|
||||
settingsDuration1699743753975,
|
||||
settingsStartup1699783784680,
|
||||
],
|
||||
});
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
export type DrawerParams = {
|
||||
Home: {};
|
||||
Settings: {};
|
||||
Graphs: {};
|
||||
Plans: {};
|
||||
Exercises: {};
|
||||
Plans: {};
|
||||
Graphs: {};
|
||||
Timer: {};
|
||||
Weight: {};
|
||||
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")
|
||||
duration: number;
|
||||
|
||||
@Column("text")
|
||||
startup: string;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue