2023-08-12 03:22:50 +00:00
|
|
|
import { useFocusEffect } from "@react-navigation/native";
|
2023-11-28 20:25:22 +00:00
|
|
|
import React, { useCallback, useState } from "react";
|
2023-11-06 02:00:52 +00:00
|
|
|
import { NativeModules, View } from "react-native";
|
2023-10-28 02:59:03 +00:00
|
|
|
import { FAB, Text, useTheme } from "react-native-paper";
|
2023-08-12 03:22:50 +00:00
|
|
|
import AppFab from "./AppFab";
|
2023-11-12 04:05:37 +00:00
|
|
|
import DrawerHeader from "./DrawerHeader";
|
2023-11-28 20:25:22 +00:00
|
|
|
import { settingsRepo } from "./db";
|
2023-08-12 03:22:50 +00:00
|
|
|
import Settings from "./settings";
|
|
|
|
import useTimer from "./use-timer";
|
2022-10-24 01:45:21 +00:00
|
|
|
|
2022-11-10 02:15:27 +00:00
|
|
|
export interface TickEvent {
|
2023-08-12 03:22:50 +00:00
|
|
|
minutes: string;
|
|
|
|
seconds: string;
|
2022-11-03 07:04:15 +00:00
|
|
|
}
|
2022-10-24 01:45:21 +00:00
|
|
|
|
2022-11-03 07:04:15 +00:00
|
|
|
export default function TimerPage() {
|
2023-11-12 10:36:22 +00:00
|
|
|
const { minutes, seconds, update } = useTimer();
|
2023-08-12 03:22:50 +00:00
|
|
|
const [settings, setSettings] = useState<Settings>();
|
|
|
|
const { colors } = useTheme();
|
2022-10-24 01:45:21 +00:00
|
|
|
|
2022-12-02 01:48:10 +00:00
|
|
|
useFocusEffect(
|
|
|
|
useCallback(() => {
|
2023-08-12 03:22:50 +00:00
|
|
|
settingsRepo.findOne({ where: {} }).then(setSettings);
|
|
|
|
}, [])
|
|
|
|
);
|
2022-10-24 01:45:21 +00:00
|
|
|
|
|
|
|
const stop = () => {
|
2023-08-12 03:22:50 +00:00
|
|
|
NativeModules.AlarmModule.stop();
|
2023-11-12 10:36:22 +00:00
|
|
|
update();
|
2023-08-12 03:22:50 +00:00
|
|
|
};
|
2022-10-24 01:45:21 +00:00
|
|
|
|
|
|
|
const add = async () => {
|
2023-08-12 03:22:50 +00:00
|
|
|
console.log(`${TimerPage.name}.add:`, settings);
|
|
|
|
NativeModules.AlarmModule.add();
|
2023-11-12 10:36:22 +00:00
|
|
|
update();
|
2023-08-12 03:22:50 +00:00
|
|
|
};
|
2022-10-24 01:45:21 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2023-08-12 03:22:50 +00:00
|
|
|
<DrawerHeader name="Timer" />
|
2023-11-28 20:25:22 +00:00
|
|
|
<View
|
|
|
|
style={{
|
|
|
|
flex: 1,
|
|
|
|
flexGrow: 1,
|
|
|
|
justifyContent: "center",
|
|
|
|
alignItems: "center",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Text style={{ fontSize: 70, position: "absolute" }}>
|
|
|
|
{minutes}:{seconds}
|
|
|
|
</Text>
|
2022-11-03 07:04:15 +00:00
|
|
|
</View>
|
2023-10-25 23:20:04 +00:00
|
|
|
|
|
|
|
<FAB
|
|
|
|
icon="plus"
|
|
|
|
onPress={add}
|
|
|
|
style={{
|
|
|
|
position: "absolute",
|
|
|
|
left: 20,
|
|
|
|
bottom: 20,
|
2023-11-14 01:44:10 +00:00
|
|
|
backgroundColor: colors.primary,
|
2023-10-25 23:20:04 +00:00
|
|
|
}}
|
2023-11-14 01:44:10 +00:00
|
|
|
color={colors.background}
|
2023-10-25 23:20:04 +00:00
|
|
|
/>
|
2023-08-12 03:22:50 +00:00
|
|
|
<AppFab icon="stop" onPress={stop} />
|
2022-10-24 01:45:21 +00:00
|
|
|
</>
|
2023-08-12 03:22:50 +00:00
|
|
|
);
|
2022-10-24 01:45:21 +00:00
|
|
|
}
|