Skip to content

Commit

Permalink
refactor: move screens to layouts and use common for web and tauri
Browse files Browse the repository at this point in the history
  • Loading branch information
gmallios committed Aug 28, 2024
1 parent 23866d3 commit 6646a7d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 43 deletions.
15 changes: 9 additions & 6 deletions manager-ui/src/TauriApp.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import React, { useEffect } from 'react';
import './App.css';
import { useTauriManagerStore } from '@stores/tauri/useTauriManagerStore';
import { BluetoothSearchScreen } from './screens/bluetoothSearch';
import { useAsyncBridgeEvent, useAsyncBridgeRequest } from './hooks/useAsyncBridge';
import { BluetoothSearchLayout } from './layouts/bluetoothSearch';
import { useAsyncBridgeEvent, useAsyncBridgeRequest } from '@hooks/useAsyncBridge';
import { useShallow } from 'zustand/react/shallow';
import { DeviceStateScreen } from '@screens/deviceState';
import { DeviceStateLayout } from './layouts/deviceState';

export const TauriApp: React.FC = () => {
const [isFirstRender, setFirstRender] = React.useState(true);
const [handleAsyncBridgeEvent, connectedAddresses] = useTauriManagerStore(
useShallow((state) => [state.handleAsyncBridgeEvent, state.connectedAddresses])
);

const state = useTauriManagerStore((state) => state);
console.log('state', state);
const currentState = useTauriManagerStore((state) => state.currentViewedDeviceState());

// Add the event listener to the bridge, which listener is
// provided by the store.
Expand All @@ -31,7 +30,11 @@ export const TauriApp: React.FC = () => {

return (
<React.Fragment>
{connectedAddresses.size !== 0 ? <DeviceStateScreen /> : <BluetoothSearchScreen />}
{connectedAddresses.size !== 0 && currentState ? (
<DeviceStateLayout state={currentState} />
) : (
<BluetoothSearchLayout />
)}
</React.Fragment>
);
};
Expand Down
6 changes: 2 additions & 4 deletions manager-ui/src/WebApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import React, { useState } from 'react';
import { generate_soundcore_service_uuids, getSoundcoreMacPrefixes } from '@wasm/manager_wasm';
import { useWebManagerStore } from '@stores/web/useWebManagerStore';
import { DeviceStateCard } from '@components/DeviceStateCard/deviceStateCard';
import { BLEDeviceFactory } from './ble/bleDevice';
import {
Button,
Expand All @@ -17,9 +16,9 @@ import {
NavbarItem,
Spinner
} from '@nextui-org/react';
import { EqualizerCard } from '@components/EqualizerCard/equalizerCard';
import { BlurredOverlay } from '@components/atoms/blurredOverlay';
import { ChevronDown, Unplug } from 'lucide-react';
import { DeviceStateLayout } from './layouts/deviceState';

enum ConnectionDialogStatus {
DIALOG_OPEN,
Expand Down Expand Up @@ -98,8 +97,7 @@ export const WebApp: React.FC = () => {
<div className={'min-h-fit flex flex-col items-center justify-start p-4'}>
{state ? (
<div className={'flex flex-col items-stretch w-2/3 2xl:w-1/2'}>
<DeviceStateCard state={state} />
<EqualizerCard state={state} />
<DeviceStateLayout state={state} />
</div>
) : (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Button, Listbox, ListboxItem, Progress, Spinner } from '@nextui-org/rea
import { ArrowRight, RefreshCcw } from 'lucide-react';
import { BlurredOverlay } from '@components/atoms/blurredOverlay';

export const BluetoothSearchScreen: React.FC = () => {
export const BluetoothSearchLayout: React.FC = () => {
const {
isLoading: isScanLoading,
startScan,
Expand Down
13 changes: 13 additions & 0 deletions manager-ui/src/layouts/deviceState.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import { DeviceStateCard } from '@components/DeviceStateCard/deviceStateCard';
import { SoundcoreDeviceState } from '@generated-types/soundcore-lib';
import { EqualizerCard } from '@components/EqualizerCard/equalizerCard';

export const DeviceStateLayout: React.FC<{ state: SoundcoreDeviceState }> = ({ state }) => {
return (
<>
<DeviceStateCard state={state} />
<EqualizerCard state={state} />
</>
);
};
32 changes: 0 additions & 32 deletions manager-ui/src/screens/deviceState.tsx

This file was deleted.

0 comments on commit 6646a7d

Please sign in to comment.