From efbecd4c618fed548910932e20da1641ea2daecf Mon Sep 17 00:00:00 2001 From: Arnab Chakraborty <11457760+Rocky43007@users.noreply.github.com> Date: Mon, 30 Sep 2024 11:35:59 -0400 Subject: [PATCH] Fix type errors & add notif logging on mobile --- apps/desktop/src/commands.ts | 2 +- apps/mobile/src/App.tsx | 17 ++++++++++++++++- .../mobile/src/components/overview/Devices.tsx | 4 ++-- .../mobile/src/screens/settings/info/Debug.tsx | 4 +--- .../settings/client/account/Profile.tsx | 10 ++++------ packages/client/src/core.ts | 18 ++++++++++++------ 6 files changed, 36 insertions(+), 19 deletions(-) diff --git a/apps/desktop/src/commands.ts b/apps/desktop/src/commands.ts index bde568c77..81581cf81 100644 --- a/apps/desktop/src/commands.ts +++ b/apps/desktop/src/commands.ts @@ -203,7 +203,7 @@ export type Update = { version: string }; type __EventObj__ = { listen: (cb: TAURI_API_EVENT.EventCallback) => ReturnType>; once: (cb: TAURI_API_EVENT.EventCallback) => ReturnType>; - emit: T extends null + emit: null extends T ? (payload?: T) => ReturnType : (payload: T) => ReturnType; }; diff --git a/apps/mobile/src/App.tsx b/apps/mobile/src/App.tsx index 64f53b630..767b22c83 100644 --- a/apps/mobile/src/App.tsx +++ b/apps/mobile/src/App.tsx @@ -26,6 +26,7 @@ import { P2PContextProvider, RspcProvider, useBridgeQuery, + useBridgeSubscription, useClientContext, useInvalidateQuery, usePlausibleEvent, @@ -34,7 +35,7 @@ import { } from '@sd/client'; import { GlobalModals } from './components/modal/GlobalModals'; -import { Toast, toastConfig } from './components/primitive/Toast'; +import { toast, Toast, toastConfig } from './components/primitive/Toast'; import { useTheme } from './hooks/useTheme'; import { changeTwTheme, tw } from './lib/tailwind'; import RootNavigator from './navigation'; @@ -131,6 +132,20 @@ function AppContainer() { useInvalidateQuery(); const { id } = useSnapshot(currentLibraryStore); + useBridgeSubscription(['cloud.listenCloudServicesNotifications'], { + onData: (d) => { + console.log('Received cloud service notification', d); + switch (d.kind) { + case 'ReceivedJoinSyncGroupRequest': + // TODO: Show modal to accept or reject + break; + default: + // TODO: Show notification/toast for other kinds + toast.info(`Cloud Service Notification -> ${d.kind}`); + break; + } + } + }); return ( diff --git a/apps/mobile/src/components/overview/Devices.tsx b/apps/mobile/src/components/overview/Devices.tsx index a78cafe96..5aea0fcce 100644 --- a/apps/mobile/src/components/overview/Devices.tsx +++ b/apps/mobile/src/components/overview/Devices.tsx @@ -117,8 +117,8 @@ const Devices = ({ node, stats }: Props) => { name={device.name} // TODO (Optional): Use Brand Type for Different Android Models/iOS Models using DeviceInfo.getBrand() icon={hardwareModelToIcon(device.hardware_model)} - totalSpace={device.storage_size.toString()} - freeSpace={(device.storage_size - device.used_storage).toString()} + totalSpace={"0"} + freeSpace={"0"} color="#0362FF" connectionType={'cloud'} /> diff --git a/apps/mobile/src/screens/settings/info/Debug.tsx b/apps/mobile/src/screens/settings/info/Debug.tsx index bc2d916b1..1c4689d14 100644 --- a/apps/mobile/src/screens/settings/info/Debug.tsx +++ b/apps/mobile/src/screens/settings/info/Debug.tsx @@ -39,9 +39,7 @@ const DebugScreen = ({ navigation }: SettingsStackScreenProps<'Debug'>) => { 'cloud.syncGroups.get', { pub_id: '0192376a-19ff-73a0-98ac-c4fa4043d401', - with_library: true, - with_devices: true, - with_used_storage: true + kind: 'FullData' } ]); // console.log(getGroup.data); diff --git a/interface/app/$libraryId/settings/client/account/Profile.tsx b/interface/app/$libraryId/settings/client/account/Profile.tsx index 4aea97abc..400fbcbbd 100644 --- a/interface/app/$libraryId/settings/client/account/Profile.tsx +++ b/interface/app/$libraryId/settings/client/account/Profile.tsx @@ -40,15 +40,13 @@ const Profile = ({ const addLibraryToCloud = useLibraryMutation('cloud.libraries.create'); const listLibraries = useBridgeQuery(['cloud.libraries.list', true]); const createSyncGroup = useLibraryMutation('cloud.syncGroups.create'); - const listSyncGroups = useBridgeQuery(['cloud.syncGroups.list', true]); + const listSyncGroups = useBridgeQuery(['cloud.syncGroups.list']); const requestJoinSyncGroup = useBridgeMutation('cloud.syncGroups.request_join'); const getGroup = useBridgeQuery([ 'cloud.syncGroups.get', { pub_id: '019237a1-586c-7651-afd3-525047b02375', - with_library: true, - with_devices: true, - with_used_storage: true + kind: 'FullData' } ]); const currentDevice = useBridgeQuery(['cloud.devices.get_current_device']); @@ -178,8 +176,8 @@ const Profile = ({ name={device.name} // TODO (Optional): Use Brand Type for Different Android Models/iOS Models using DeviceInfo.getBrand() icon={hardwareModelToIcon(device.hardware_model)} - totalSpace={device.storage_size.toString()} - freeSpace={(device.storage_size - device.used_storage).toString()} + totalSpace={'0'} + freeSpace={'0'} color="#0362FF" connectionType={'cloud'} /> diff --git a/packages/client/src/core.ts b/packages/client/src/core.ts index 6d6a8a5f8..c27e7b25c 100644 --- a/packages/client/src/core.ts +++ b/packages/client/src/core.ts @@ -11,9 +11,9 @@ export type Procedures = { { key: "cloud.libraries.get", input: CloudGetLibraryArgs, result: CloudLibrary } | { key: "cloud.libraries.list", input: boolean, result: CloudLibrary[] } | { key: "cloud.locations.list", input: CloudListLocationsArgs, result: CloudLocation[] } | - { key: "cloud.syncGroups.get", input: CloudGetSyncGroupArgs, result: CloudSyncGroup } | + { key: "cloud.syncGroups.get", input: CloudGetSyncGroupArgs, result: CloudSyncGroupGetResponseKind } | { key: "cloud.syncGroups.leave", input: CloudSyncGroupPubId, result: null } | - { key: "cloud.syncGroups.list", input: boolean, result: CloudSyncGroup[] } | + { key: "cloud.syncGroups.list", input: never, result: CloudSyncGroupBaseData[] } | { key: "cloud.syncGroups.remove_device", input: CloudSyncGroupsRemoveDeviceArgs, result: null } | { key: "ephemeralFiles.getMediaData", input: string, result: MediaData | null } | { key: "files.get", input: LibraryArgs, result: ObjectWithFilePaths2 | null } | @@ -184,13 +184,13 @@ export type Chapter = { id: number; start: [number, number]; end: [number, numbe export type CloudCreateLocationArgs = { pub_id: CloudLocationPubId; name: string; library_pub_id: CloudLibraryPubId; device_pub_id: CloudDevicePubId } -export type CloudDevice = { pub_id: CloudDevicePubId; name: string; os: DeviceOS; storage_size: bigint; used_storage: bigint; connection_id: string; created_at: string; updated_at: string; hardware_model: HardwareModel } +export type CloudDevice = { pub_id: CloudDevicePubId; name: string; os: DeviceOS; hardware_model: HardwareModel; connection_id: string; created_at: string; updated_at: string } export type CloudDevicePubId = string export type CloudGetLibraryArgs = { pub_id: CloudLibraryPubId; with_device: boolean } -export type CloudGetSyncGroupArgs = { pub_id: CloudSyncGroupPubId; with_library: boolean; with_devices: boolean; with_used_storage: boolean } +export type CloudGetSyncGroupArgs = { pub_id: CloudSyncGroupPubId; kind: CloudSyncGroupGetRequestKind } export type CloudLibrary = { pub_id: CloudLibraryPubId; name: string; original_device: CloudDevice | null; created_at: string; updated_at: string } @@ -210,7 +210,13 @@ export type CloudP2PTicket = bigint export type CloudP2PUserResponse = { kind: "AcceptDeviceInSyncGroup"; data: { ticket: CloudP2PTicket; accepted: BasicLibraryCreationArgs | null } } -export type CloudSyncGroup = { pub_id: CloudSyncGroupPubId; latest_key_hash: CloudSyncKeyHash; library: CloudLibrary | null; devices: CloudDevice[] | null; total_sync_messages_bytes: bigint | null; total_space_files_bytes: bigint | null; created_at: string; updated_at: string } +export type CloudSyncGroup = { pub_id: CloudSyncGroupPubId; latest_key_hash: CloudSyncKeyHash; library: CloudLibrary; devices: CloudDevice[]; total_sync_messages_bytes: bigint; total_space_files_bytes: bigint; created_at: string; updated_at: string } + +export type CloudSyncGroupBaseData = { pub_id: CloudSyncGroupPubId; latest_key_hash: CloudSyncKeyHash; library: CloudLibrary; created_at: string; updated_at: string } + +export type CloudSyncGroupGetRequestKind = "WithDevices" | "FullData" + +export type CloudSyncGroupGetResponseKind = { WithDevices: CloudSyncGroupWithLibraryAndDevices } | { FullData: CloudSyncGroup } export type CloudSyncGroupPubId = string @@ -220,7 +226,7 @@ export type CloudSyncGroupsRemoveDeviceArgs = { group_pub_id: CloudSyncGroupPubI export type CloudSyncKeyHash = string -export type CloudUpdateDeviceArgs = { pub_id: CloudDevicePubId; name: string; storage_size: bigint; used_storage: bigint } +export type CloudUpdateDeviceArgs = { pub_id: CloudDevicePubId; name: string } export type Codec = { kind: string | null; sub_kind: string | null; tag: string | null; name: string | null; profile: string | null; bit_rate: number; props: Props | null }