From 166622971924efd53fa1c959bd13f463ceffb794 Mon Sep 17 00:00:00 2001 From: Arnab Chakraborty <11457760+Rocky43007@users.noreply.github.com> Date: Tue, 17 Sep 2024 12:10:51 -0400 Subject: [PATCH] Get access token from storage in mobile --- .../src/components/overview/Devices.tsx | 32 ++++++++++++++++++- apps/mobile/src/utils/index.ts | 6 ++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 apps/mobile/src/utils/index.ts diff --git a/apps/mobile/src/components/overview/Devices.tsx b/apps/mobile/src/components/overview/Devices.tsx index b75e2a4a0..f11e24d34 100644 --- a/apps/mobile/src/components/overview/Devices.tsx +++ b/apps/mobile/src/components/overview/Devices.tsx @@ -5,8 +5,9 @@ import React, { useEffect, useState } from 'react'; import { Platform, Text, View } from 'react-native'; import DeviceInfo from 'react-native-device-info'; import { ScrollView } from 'react-native-gesture-handler'; -import { HardwareModel, NodeState, StatisticsResponse } from '@sd/client'; +import { HardwareModel, NodeState, StatisticsResponse, useBridgeQuery } from '@sd/client'; import { tw, twStyle } from '~/lib/tailwind'; +import { getAccessToken } from '~/utils'; import Fade from '../layout/Fade'; import { Button } from '../primitive/Button'; @@ -44,6 +45,23 @@ const Devices = ({ node, stats }: Props) => { Omit >({ freeSpace: 0, totalSpace: 0 }); const [deviceName, setDeviceName] = useState(''); + const [accessToken, setAccessToken] = useState(''); + useEffect(() => { + (async () => { + const at = await getAccessToken(); + setAccessToken(at ?? ''); + })(); + }, []); + + const devices = useBridgeQuery(['cloud.devices.list', { access_token: accessToken.trim() }]); + + // Refetch devices every 10 seconds + useEffect(() => { + const interval = setInterval(async () => { + await devices.refetch(); + }, 10000); + return () => clearInterval(interval); + }, []); useEffect(() => { const getFSInfo = async () => { @@ -93,6 +111,18 @@ const Devices = ({ node, stats }: Props) => { connectionType={null} /> )} + {/* {devices.data?.map((device) => ( + + ))} */}