summaryrefslogtreecommitdiff
path: root/app/(tabs)/index.tsx
diff options
context:
space:
mode:
authorJustZvan <justzvan@justzvan.xyz>2026-02-06 13:22:33 +0100
committerJustZvan <justzvan@justzvan.xyz>2026-02-06 13:22:33 +0100
commit7eb8ccae48b0cc18a9dcaa9c3626a02df8e6d919 (patch)
tree57b7dd06ac9aa7053c671d916f7183e3b4fa9410 /app/(tabs)/index.tsx
feat: initial commit!
Diffstat (limited to 'app/(tabs)/index.tsx')
-rw-r--r--app/(tabs)/index.tsx135
1 files changed, 135 insertions, 0 deletions
diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx
new file mode 100644
index 0000000..a29ec87
--- /dev/null
+++ b/app/(tabs)/index.tsx
@@ -0,0 +1,135 @@
+import { Ionicons } from "@expo/vector-icons";
+import { useEffect, useState } from "react";
+import { getHomeData, HomeData } from "../../api";
+import { useDevice } from "../../lib/device";
+import { t } from "../../lib/locales";
+import { colors } from "../../lib/theme";
+import {
+ Card,
+ DeviceSelector,
+ Divider,
+ H2,
+ Muted,
+ Pill,
+ Row,
+ Screen,
+} from "../../lib/ui";
+
+export default function Index() {
+ const [data, setData] = useState<HomeData | null>(null);
+ const {
+ devices,
+ selectedDevice,
+ selectDevice,
+ isLoading: isDeviceLoading,
+ } = useDevice();
+
+ useEffect(() => {
+ if (selectedDevice) {
+ getHomeData(selectedDevice.id).then(setData);
+ }
+ }, [selectedDevice]);
+
+ if (!selectedDevice && !isDeviceLoading)
+ return (
+ <Screen>
+ <DeviceSelector
+ devices={devices}
+ selectedDevice={selectedDevice}
+ onSelectDevice={selectDevice}
+ isLoading={isDeviceLoading}
+ />
+ <Muted>{t("noDeviceSelectedPleaseLinkFirst")}</Muted>
+ </Screen>
+ );
+
+ if (!data)
+ return (
+ <Screen>
+ <DeviceSelector
+ devices={devices}
+ selectedDevice={selectedDevice}
+ onSelectDevice={selectDevice}
+ isLoading={isDeviceLoading}
+ />
+ </Screen>
+ );
+
+ return (
+ <Screen>
+ <DeviceSelector
+ devices={devices}
+ selectedDevice={selectedDevice}
+ onSelectDevice={selectDevice}
+ isLoading={isDeviceLoading}
+ />
+
+ <Card>
+ <Row
+ left={
+ <Row
+ left={
+ <H2>
+ {data.overallStatus === "all_clear"
+ ? t("allClear")
+ : t("attentionNeeded")}
+ </H2>
+ }
+ right={
+ <Pill
+ label={
+ data.overallStatus === "all_clear"
+ ? t("today")
+ : t("review")
+ }
+ tone={
+ data.overallStatus === "all_clear" ? "good" : "attention"
+ }
+ />
+ }
+ />
+ }
+ />
+ <Muted>
+ {data.overallStatus === "all_clear"
+ ? t("nothingNeedsAttention")
+ : t("fewItemsNeedReview")}
+ </Muted>
+
+ <Divider />
+
+ <Row
+ left={
+ <Row
+ left={
+ <Row
+ left={
+ <Ionicons
+ name={data.deviceOnline ? "wifi" : "wifi"}
+ size={18}
+ color={
+ data.deviceOnline ? colors.onBackground : colors.primary
+ }
+ />
+ }
+ right={
+ <H2>
+ {data.deviceOnline
+ ? t("deviceIsOnline")
+ : t("deviceIsOffline")}
+ </H2>
+ }
+ />
+ }
+ />
+ }
+ />
+ <Muted>
+ {data.deviceOnline
+ ? t("protectionActive")
+ : t("reconnectingAutomatically")}
+ </Muted>
+ </Card>
+ </Screen>
+ );
+}