|
7 | 7 | import { useIsFocused, useNavigation, type StaticScreenProps } from "@react-navigation/native"; |
8 | 8 | import { EnvironmentId, ThreadId } from "@t3tools/contracts"; |
9 | 9 | import * as Cause from "effect/Cause"; |
10 | | -import { useCallback, useEffect, useMemo, useRef, useState, type RefObject } from "react"; |
| 10 | +import { useEffect, useRef, useState, type RefObject } from "react"; |
11 | 11 | import * as Haptics from "expo-haptics"; |
12 | 12 | import { Accelerometer } from "expo-sensors"; |
13 | 13 | import { AppState, BackHandler, Pressable, StatusBar, View } from "react-native"; |
@@ -47,7 +47,7 @@ type DevicePreviewRouteScreenProps = StaticScreenProps<{ |
47 | 47 |
|
48 | 48 | export function DevicePreviewRouteScreen({ route }: DevicePreviewRouteScreenProps) { |
49 | 49 | const navigation = useNavigation(); |
50 | | - const onClose = useCallback(() => navigation.goBack(), [navigation]); |
| 50 | + const onClose = () => navigation.goBack(); |
51 | 51 | const { environmentId, threadId } = route.params; |
52 | 52 | const isBlankLink = environmentId.trim().length === 0 || threadId.trim().length === 0; |
53 | 53 | useEffect(() => { |
@@ -85,15 +85,12 @@ function DevicePreviewScreen({ |
85 | 85 | const shutdown = useAtomCommand(deviceEnvironment.shutdown, { reportFailure: false }); |
86 | 86 | const streamRef = useRef<DeviceStreamRef>(null); |
87 | 87 | const state = useEnvironmentQuery(deviceEnvironment.state({ environmentId, input: {} })); |
88 | | - const previews = useMemo( |
89 | | - () => threadDevicePreviews(state.data, threadId), |
90 | | - [state.data, threadId], |
91 | | - ); |
| 88 | + const previews = threadDevicePreviews(state.data, threadId); |
92 | 89 | const preview = selectedThreadDevicePreview(previews, selectedKey); |
93 | | - const onInputConnected = useCallback(async (connected: boolean) => { |
| 90 | + const onInputConnected = async (connected: boolean) => { |
94 | 91 | setInputConnected(connected); |
95 | 92 | if (connected) setControlsVisible(false); |
96 | | - }, []); |
| 93 | + }; |
97 | 94 | useEffect(() => { |
98 | 95 | const subscription = AppState.addEventListener("change", (state) => |
99 | 96 | setForeground(state !== "background"), |
@@ -126,20 +123,16 @@ function DevicePreviewScreen({ |
126 | 123 | const shutDownDevice = async () => { |
127 | 124 | if (!preview || shuttingDown) return; |
128 | 125 | setShuttingDown(true); |
129 | | - try { |
130 | | - const result = await shutdown({ |
131 | | - environmentId, |
132 | | - input: { |
133 | | - hostId: preview.session.hostId, |
134 | | - deviceId: preview.session.deviceId, |
135 | | - platform: preview.session.platform, |
136 | | - }, |
137 | | - }); |
138 | | - if (result._tag === "Failure") { |
139 | | - Dialog.alert("Could not shut down device", String(Cause.squash(result.cause))); |
140 | | - } |
141 | | - } finally { |
142 | | - setShuttingDown(false); |
| 126 | + const result = await shutdown({ |
| 127 | + environmentId, |
| 128 | + input: { |
| 129 | + hostId: preview.session.hostId, |
| 130 | + deviceId: preview.session.deviceId, |
| 131 | + platform: preview.session.platform, |
| 132 | + }, |
| 133 | + }).finally(() => setShuttingDown(false)); |
| 134 | + if (result._tag === "Failure") { |
| 135 | + Dialog.alert("Could not shut down device", String(Cause.squash(result.cause))); |
143 | 136 | } |
144 | 137 | }; |
145 | 138 |
|
@@ -377,10 +370,7 @@ function OpenDevicePreview({ |
377 | 370 | const { session } = preview; |
378 | 371 | const { themeVariables } = useAppearancePreferences(); |
379 | 372 | const { access, error, refresh } = useDeviceHubAccess(environmentId, session.hostId); |
380 | | - const onUnauthorized = useCallback( |
381 | | - async () => refreshDeviceHubAccess(environmentId), |
382 | | - [environmentId], |
383 | | - ); |
| 373 | + const onUnauthorized = async () => refreshDeviceHubAccess(environmentId); |
384 | 374 | useEffect(() => { |
385 | 375 | refreshDeviceHubAccess(environmentId); |
386 | 376 | return () => void onInputConnected(false); |
|
0 commit comments