From d85083f7f2a4228abda1124419404e90aba2e1ac Mon Sep 17 00:00:00 2001 From: patryk-sierzega <126664583+patryk-sierzega@users.noreply.github.com> Date: Fri, 6 Oct 2023 13:04:24 +0200 Subject: [PATCH] Reverted previous changes and added new fix --- .../app/src/device/actions/base.action.ts | 6 ++-- .../app/src/device/reducers/device.reducer.ts | 29 +++++++++++++++---- .../check-for-force-update-need.action.ts | 5 ---- .../check-for-update.action.ts | 8 ----- .../handle-device-detached.action.ts | 5 +++- 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/packages/app/src/device/actions/base.action.ts b/packages/app/src/device/actions/base.action.ts index 4ffe0e1cea..bdfdb5bceb 100644 --- a/packages/app/src/device/actions/base.action.ts +++ b/packages/app/src/device/actions/base.action.ts @@ -12,9 +12,9 @@ import { import { DeviceEvent } from "App/device/constants" import { GetPhoneLockTimeResponseBody } from "App/device/types/mudita-os" -export const setDeviceData = createAction< - Partial ->(DeviceEvent.SetData) +export const setDeviceData = createAction | null>(DeviceEvent.SetData) export const setLockTime = createAction< GetPhoneLockTimeResponseBody | undefined diff --git a/packages/app/src/device/reducers/device.reducer.ts b/packages/app/src/device/reducers/device.reducer.ts index 822860fec2..f6a18d8296 100644 --- a/packages/app/src/device/reducers/device.reducer.ts +++ b/packages/app/src/device/reducers/device.reducer.ts @@ -54,6 +54,7 @@ export const deviceReducer = createReducer( initialState, (builder) => { builder + // SetInitState functionality .addCase(DeviceEvent.SetInitState, () => { return { @@ -76,6 +77,7 @@ export const deviceReducer = createReducer( externalUsageDevice: null, } }) + .addCase( fulfilledAction(DeviceEvent.Connected), (state, action: ConnectedFulfilledAction) => { @@ -91,6 +93,7 @@ export const deviceReducer = createReducer( } } ) + .addCase( rejectedAction(DeviceEvent.Connected), (state, action: ConnectedRejectedAction) => { @@ -106,6 +109,7 @@ export const deviceReducer = createReducer( } } ) + .addCase(pendingAction(DeviceEvent.Disconnected), (state) => { return { ...state, @@ -114,6 +118,7 @@ export const deviceReducer = createReducer( externalUsageDevice: null, } }) + .addCase(fulfilledAction(DeviceEvent.Disconnected), (state) => { return { ...state, @@ -121,6 +126,7 @@ export const deviceReducer = createReducer( error: null, } }) + .addCase( fulfilledAction(DeviceEvent.SetConnectionState), (state, action: SetConnectionStateAction) => { @@ -147,6 +153,7 @@ export const deviceReducer = createReducer( }, } }) + .addCase(unlockedDevice, (state) => { return { ...state, @@ -157,6 +164,7 @@ export const deviceReducer = createReducer( error: null, } }) + .addCase( DeviceEvent.SetLockTime, (state, action: SetPhoneLockTimeAction) => { @@ -173,12 +181,17 @@ export const deviceReducer = createReducer( // Passing data from the connecting device to state .addCase(DeviceEvent.SetData, (state, action: SetDeviceDataAction) => { + const newData = + action.payload === null + ? null + : { + ...(state.data ?? {}), + ...action.payload, + } + return { ...state, - data: { - ...(state.data ?? {}), - ...action.payload, - }, + data: newData, error: null, } }) @@ -228,6 +241,7 @@ export const deviceReducer = createReducer( } } ) + // Updates loading data state .addCase(pendingAction(DeviceEvent.Loading), (state) => { return { @@ -235,6 +249,7 @@ export const deviceReducer = createReducer( state: ConnectionState.Loading, } }) + .addCase(fulfilledAction(DeviceEvent.Loading), (state) => { return { ...state, @@ -246,6 +261,7 @@ export const deviceReducer = createReducer( error: null, } }) + .addCase( rejectedAction(DeviceEvent.Loading), (state, action: LoadDataRejectAction) => { @@ -274,6 +290,7 @@ export const deviceReducer = createReducer( } } ) + .addCase( rejectedAction(DeviceEvent.LoadStorageInfo), (state, action: LoadStorageInfoRejectedAction) => { @@ -284,17 +301,17 @@ export const deviceReducer = createReducer( } } ) - .addCase(setOnboardingStatus, (state, action) => { state.status.onboardingFinished = action.payload }) - .addCase(setCriticalBatteryLevel, (state, action) => { state.status.criticalBatteryLevel = action.payload }) + .addCase(setExternalUsageDevice, (state, action) => { state.externalUsageDevice = action.payload }) + .addCase(setRestarting, (state, action) => { state.status.restarting = action.payload }) diff --git a/packages/app/src/update/actions/check-for-force-update-need/check-for-force-update-need.action.ts b/packages/app/src/update/actions/check-for-force-update-need/check-for-force-update-need.action.ts index 8e6765db3d..a92fbc7280 100644 --- a/packages/app/src/update/actions/check-for-force-update-need/check-for-force-update-need.action.ts +++ b/packages/app/src/update/actions/check-for-force-update-need/check-for-force-update-need.action.ts @@ -10,7 +10,6 @@ import { checkForUpdate } from "App/update/actions/check-for-update/check-for-up import { CheckForUpdateMode, UpdateOsEvent } from "App/update/constants" import { versionFormatter } from "App/update/helpers" import { ReduxRootState, RootState } from "App/__deprecated__/renderer/store" -import { ConnectionState } from "App/device/constants" export const checkForForceUpdateNeed = createAsyncThunk( UpdateOsEvent.CheckForForceUpdate, @@ -21,10 +20,6 @@ export const checkForForceUpdateNeed = createAsyncThunk( const { device, settings } = getState() as RootState & ReduxRootState - if (device.state === ConnectionState.Loading) { - return false - } - const osVersion = versionFormatter(device.data?.osVersion ?? "") const lowestSupportedProductVersion = settings.lowestSupportedVersions?.lowestSupportedProductVersion diff --git a/packages/app/src/update/actions/check-for-update/check-for-update.action.ts b/packages/app/src/update/actions/check-for-update/check-for-update.action.ts index b1dece603b..a27ae57334 100644 --- a/packages/app/src/update/actions/check-for-update/check-for-update.action.ts +++ b/packages/app/src/update/actions/check-for-update/check-for-update.action.ts @@ -22,7 +22,6 @@ import { osUpdateAlreadyDownloadedCheck, } from "App/update/requests" import { ReduxRootState, RootState } from "App/__deprecated__/renderer/store" -import { ConnectionState } from "App/device/constants" interface Params { deviceType: DeviceType @@ -50,12 +49,6 @@ export const checkForUpdate = createAsyncThunk( async ({ deviceType }, { rejectWithValue, getState }) => { const state = getState() as RootState & ReduxRootState - if (state.device.state === ConnectionState.Loading) { - return { - allReleases: [], - availableReleasesForUpdate: [], - } - } const osVersion = versionFormatter(state.device.data?.osVersion || "") const product = @@ -112,7 +105,6 @@ export const checkForUpdate = createAsyncThunk( const mandatoryReleasesToInstall = await getReleasesByVersions({ product, versions: mandatoryVersionsToInstall, - deviceSerialNumber: state.device.data?.serialNumber, }) if (!mandatoryReleasesToInstall.ok || !mandatoryReleasesToInstall.data) { diff --git a/packages/app/src/update/actions/handle-device-detached/handle-device-detached.action.ts b/packages/app/src/update/actions/handle-device-detached/handle-device-detached.action.ts index 9e2fd16d8d..e2387dcc1b 100644 --- a/packages/app/src/update/actions/handle-device-detached/handle-device-detached.action.ts +++ b/packages/app/src/update/actions/handle-device-detached/handle-device-detached.action.ts @@ -8,14 +8,17 @@ import { setExternalUsageDeviceRequest } from "App/analytic-data-tracker/request import { DownloadState, UpdateOsEvent } from "App/update/constants" import { cancelOsDownload } from "App/update/requests" import { ReduxRootState } from "App/__deprecated__/renderer/store" +import { setDeviceData } from "App/device/actions/base.action" export const handleDeviceDetached = createAsyncThunk< void, void, { state: ReduxRootState } ->(UpdateOsEvent.HandleDeviceDetached, async (_, { getState }) => { +>(UpdateOsEvent.HandleDeviceDetached, async (_, { dispatch, getState }) => { const { update } = getState() + dispatch(setDeviceData(null)) + if (update.downloadState === DownloadState.Loading) { cancelOsDownload(true) }