jump to new connected device
parent
e821719fac
commit
06c22b6a5e
|
@ -181,7 +181,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"noDevicesConnected": {
|
"noDevicesConnected": {
|
||||||
"pageTitle": "No devices connected"
|
"pageTitle": "No devices connected",
|
||||||
|
"textDescription": "No devices are connected to the app. Connect a device to use it.",
|
||||||
|
"buttonSearchForNewDevices": "Search for New Devices"
|
||||||
},
|
},
|
||||||
"help": {
|
"help": {
|
||||||
"pageTitle": "Help",
|
"pageTitle": "Help",
|
||||||
|
|
|
@ -1,7 +1,14 @@
|
||||||
import { ScrollView, Text, View } from "react-native";
|
import { ScrollView, Text, View } from "react-native";
|
||||||
import Card from "../../Components/Card";
|
import Card from "../../Components/Card";
|
||||||
import { useContext, useEffect, useState } from "react";
|
import { useContext, useEffect, useState } from "react";
|
||||||
import { AppContext, AppStyles, Constants, GetDevice } from "../../utils";
|
import {
|
||||||
|
AppContext,
|
||||||
|
AppSelectedUserDevice,
|
||||||
|
AppSelectedUserDeviceDefaultData,
|
||||||
|
AppStyles,
|
||||||
|
Constants,
|
||||||
|
GetDevice,
|
||||||
|
} from "../../utils";
|
||||||
import { Divider } from "../../Components/Divider";
|
import { Divider } from "../../Components/Divider";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import MySwitch from "../../Components/Switch";
|
import MySwitch from "../../Components/Switch";
|
||||||
|
@ -74,6 +81,7 @@ export default function SettingsView({ navigation }) {
|
||||||
// show no devices connected screen if there are no devices left
|
// show no devices connected screen if there are no devices left
|
||||||
if (appContext.devices.length < 2) {
|
if (appContext.devices.length < 2) {
|
||||||
navigation.navigate("_noDevicesConnected");
|
navigation.navigate("_noDevicesConnected");
|
||||||
|
AppSelectedUserDevice.current = AppSelectedUserDeviceDefaultData;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove device from app async storage if it is not already handled by appContext
|
// TODO: remove device from app async storage if it is not already handled by appContext
|
||||||
|
|
|
@ -2,12 +2,23 @@ import { useTranslation } from "react-i18next";
|
||||||
import { View } from "react-native";
|
import { View } from "react-native";
|
||||||
import MyResult from "../../Components/Result";
|
import MyResult from "../../Components/Result";
|
||||||
import { MyTextButton } from "../../Components/Button";
|
import { MyTextButton } from "../../Components/Button";
|
||||||
|
import { useCallback, useContext } from "react";
|
||||||
|
import { useFocusEffect } from "@react-navigation/native";
|
||||||
|
import { AppContext } from "../../utils";
|
||||||
|
|
||||||
// this screen is shown when no devices are connected to the app
|
// this screen is shown when no devices are connected to the app
|
||||||
export default function NoDevicesConnectedScreen({ navigation }) {
|
export default function NoDevicesConnectedScreen({ navigation }) {
|
||||||
|
const appContext = useContext(AppContext);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
// TODO: add ref to faq for help to connect a new device
|
useFocusEffect(
|
||||||
|
useCallback(() => {
|
||||||
|
// navigate user to first device in list after he has added a new device
|
||||||
|
if (appContext.devices.length > 0) {
|
||||||
|
navigation.navigate(appContext.devices[0].displayName);
|
||||||
|
}
|
||||||
|
}, [appContext.devices])
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={{ alignItems: "center", margin: 20, gap: 10 }}>
|
<View style={{ alignItems: "center", margin: 20, gap: 10 }}>
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { useContext, useEffect, useState } from "react";
|
||||||
import {
|
import {
|
||||||
AddNewDevice,
|
AddNewDevice,
|
||||||
AppContext,
|
AppContext,
|
||||||
|
AppSelectedUserDevice,
|
||||||
AppStyles,
|
AppStyles,
|
||||||
Constants,
|
Constants,
|
||||||
ModalContainer,
|
ModalContainer,
|
||||||
|
@ -301,18 +302,29 @@ function FoundDevice({ item, appContext, t }) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setConnectingState(FoundDeviceState.connected);
|
setConnectingState(FoundDeviceState.connected);
|
||||||
|
|
||||||
|
// TODO: other way for this
|
||||||
// generate random two digit number code
|
// generate random two digit number code
|
||||||
let code = Math.floor(Math.random() * 100);
|
let code = Math.floor(Math.random() * 100);
|
||||||
|
|
||||||
// TODO: add device and fill up with information provided by the esp
|
const newDevice = AddNewDevice(
|
||||||
appContext.setDevices((prev) => [
|
|
||||||
...prev,
|
|
||||||
AddNewDevice(
|
|
||||||
"New Device " + code,
|
"New Device " + code,
|
||||||
item.deviceModel,
|
item.deviceModel,
|
||||||
item.deviceIp
|
item.deviceIp
|
||||||
),
|
);
|
||||||
]);
|
|
||||||
|
// TODO: add device to app storage and fill up with information provided by the esp
|
||||||
|
appContext.setDevices((prev) => [...prev, newDevice]);
|
||||||
|
/*
|
||||||
|
AppSelectedUserDevice.current = {
|
||||||
|
id: newDevice.id,
|
||||||
|
routeName: newDevice.displayName,
|
||||||
|
}; */
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
"appS",
|
||||||
|
newDevice.id,
|
||||||
|
AppSelectedUserDevice.current
|
||||||
|
);
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}}
|
}}
|
||||||
buttonLeftComponent={
|
buttonLeftComponent={
|
||||||
|
|
|
@ -640,8 +640,11 @@ const appContextPreview = {
|
||||||
userColorSwatchesFavorites: [],
|
userColorSwatchesFavorites: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
export const AppSelectedUserDevice = createRef();
|
export const AppSelectedUserDeviceDefaultData = { id: "", routeName: "" };
|
||||||
AppSelectedUserDevice.current = { id: "", routeName: "" };
|
|
||||||
|
export const AppSelectedUserDevice = createRef(
|
||||||
|
AppSelectedUserDeviceDefaultData
|
||||||
|
);
|
||||||
|
|
||||||
export const AppContext = createContext(appContextPreview);
|
export const AppContext = createContext(appContextPreview);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue