Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:mudita/mudita-center into CP-3218
Browse files Browse the repository at this point in the history
  • Loading branch information
MateuszMudita committed Dec 20, 2024
2 parents f6224b2 + 106f4b5 commit 47688fe
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1045,5 +1045,5 @@
"module.recoveryMode.modal.terminalInfo.step3": "3. Enter your computer password when prompted",
"module.recoveryMode.modal.terminalInfo.step4": "4. Repeat your computer password when prompted",
"module.recoveryMode.modal.completed.subtitle": "Recovery process complete",
"module.recoveryMode.modal.completed.description": "Harmony is in transport mode. Press the light button when \"ON\" and \"OFF\" appear on harmony's screen."
"module.recoveryMode.modal.completed.description": "Hold down the light button on Harmony to turn it on when prompted."
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { z } from "zod"

export const entitiesMetadataValidator = z.object({
totalEntities: z.number().nonnegative(),
uniqueKey: z.string().optional(),
})

export type EntitiesMetadata = z.infer<typeof entitiesMetadataValidator>
1 change: 1 addition & 0 deletions libs/generic-view/store/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export * from "./lib/entities/get-entities-metadata.action"
export * from "./lib/entities/delete-entities-data.action"
export * from "./lib/entities/create-entity-data.action"
export * from "./lib/entities/update-entity-data.action"
export * from "./lib/entities/refresh-entities-if-metadata-changed.action"

export * from "./lib/data-migration/reducer"
export * from "./lib/data-migration/actions"
Expand Down
1 change: 1 addition & 0 deletions libs/generic-view/store/src/lib/action-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,5 @@ export enum ActionName {
DeleteEntityData = "entities/delete-entity-data",
CreateEntityData = "entities/create-entity-data",
UpdateEntityData = "entities/update-entity-data",
RefreshEntitiesIfMetadataChanged = "entities/refresh-entities-if-metadata-changed",
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { selectActiveApiDeviceId } from "../selectors/select-active-api-device-i
import { setRestoreProcessFileStatus, setRestoreProcessStatus } from "./actions"
import { BackupProcessFileStatus, RestoreProcessStatus } from "./backup.types"
import { delay } from "shared/utils"
import { refreshEntitiesIfMetadataChanged } from "../entities/refresh-entities-if-metadata-changed.action"

export const restoreBackup = createAsyncThunk<
undefined,
Expand Down Expand Up @@ -221,6 +222,14 @@ export const restoreBackup = createAsyncThunk<
return rejectWithValue(undefined)
}
dispatch(setRestoreProcessStatus({ status: RestoreProcessStatus.Done }))

await dispatch(
refreshEntitiesIfMetadataChanged({
deviceId: deviceId,
entitiesType: "contacts",
})
)

return undefined
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { removeDirectory } from "system-utils/feature"
import { DataMigrationStatus } from "./reducer"
import { clearMigrationData } from "./clear-migration-data"
import { pureToUnifiedMessage } from "./data-migration-mappers/pure-to-unified-message"
import { refreshEntitiesIfMetadataChanged } from "../entities/refresh-entities-if-metadata-changed.action"
import { selectActiveApiDeviceId } from "../selectors"

export const transferMigrationData = createAsyncThunk<
void,
Expand Down Expand Up @@ -56,6 +58,12 @@ export const transferMigrationData = createAsyncThunk<
return rejectWithValue(undefined)
}

const deviceId = selectActiveApiDeviceId(getState())

if (!deviceId) {
return handleError("Device not found")
}

const sourceDeviceId = dataMigration.sourceDevice
if (!sourceDeviceId) {
return handleError("Source device not selected")
Expand Down Expand Up @@ -173,6 +181,15 @@ export const transferMigrationData = createAsyncThunk<

await delay()

if (domainsData.some((obj) => obj.domain === "contacts-v1")) {
await dispatch(
refreshEntitiesIfMetadataChanged({
deviceId: deviceId,
entitiesType: "contacts",
})
)
}

dispatch(setDataMigrationStatus(DataMigrationStatus.Completed))

return
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright (c) Mudita sp. z o.o. All rights reserved.
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

import { createAsyncThunk } from "@reduxjs/toolkit"
import { ReduxRootState } from "Core/__deprecated__/renderer/store"
import { ActionName } from "../action-names"
import { getEntitiesMetadataAction } from "./get-entities-metadata.action"
import { selectEntitiesMetadata } from "../selectors"
import { getEntitiesDataAction } from "./get-entities-data.action"
import { EntitiesMetadata } from "Libs/device/models/src"

export const refreshEntitiesIfMetadataChanged = createAsyncThunk<
void,
{ deviceId: string; entitiesType: string },
{ state: ReduxRootState }
>(
ActionName.RefreshEntitiesIfMetadataChanged,
async (
{ deviceId, entitiesType },
{ dispatch, getState, rejectWithValue }
) => {
if (!deviceId) {
return rejectWithValue(undefined)
}

const currentMetadata = selectEntitiesMetadata(getState(), {
deviceId,
entitiesType,
})

const metadata = await dispatch(
getEntitiesMetadataAction({ deviceId, entitiesType })
)

if (
currentMetadata?.uniqueKey !==
(metadata.payload as EntitiesMetadata)?.uniqueKey
) {
dispatch(getEntitiesDataAction({ deviceId, entitiesType }))
}

return
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { sendFile } from "../file-transfer/send-file.action"
import { selectActiveApiDeviceId } from "../selectors"
import { setImportProcessFileStatus, setImportProcessStatus } from "./actions"
import { delay } from "shared/utils"
import { refreshEntitiesIfMetadataChanged } from "../entities/refresh-entities-if-metadata-changed.action"

export const startImportToDevice = createAsyncThunk<
undefined,
Expand Down Expand Up @@ -254,6 +255,13 @@ export const startImportToDevice = createAsyncThunk<
return rejectWithValue(undefined)
}

await dispatch(
refreshEntitiesIfMetadataChanged({
deviceId: deviceId,
entitiesType: "contacts",
})
)

return undefined
}
)

0 comments on commit 47688fe

Please sign in to comment.