From e7eae446899f60bb6a0c637a73a349eb24228cbb Mon Sep 17 00:00:00 2001 From: Ldoppea Date: Tue, 19 Dec 2023 19:05:25 +0100 Subject: [PATCH] fix: Remove OsReceive side effect from old FlagshipUI implementation Now that OsReceive uses the new FlagshipUI API, then this hack is not needed anymore Related PR: #1043 --- __tests__/jestSetupFile.js | 12 ------------ src/app/view/OsReceive/state/OsReceiveState.ts | 16 ---------------- src/libs/intents/setFlagshipUI.ts | 12 ------------ 3 files changed, 40 deletions(-) diff --git a/__tests__/jestSetupFile.js b/__tests__/jestSetupFile.js index 1e3d50481..2b984bbbb 100644 --- a/__tests__/jestSetupFile.js +++ b/__tests__/jestSetupFile.js @@ -109,18 +109,6 @@ jest.mock( () => mockRNBackgroundGeolocation ) -// This function isn't meant to be tested -// It is breaking the tests just by being imported -// Have to remove that mock when we refactor the actual function -jest.mock('../src/app/view/OsReceive/state/OsReceiveState', () => ({ - getDangerousOsReceiveState: jest.fn().mockReturnValue({ - filesToUpload: [], - routeToUpload: {}, - errored: false, - candidateApps: undefined - }) -})) - jest.mock('react-native/Libraries/Components/Switch/Switch', () => { const mockComponent = require('react-native/jest/mockComponent') return { diff --git a/src/app/view/OsReceive/state/OsReceiveState.ts b/src/app/view/OsReceive/state/OsReceiveState.ts index 119e86653..f783790c8 100644 --- a/src/app/view/OsReceive/state/OsReceiveState.ts +++ b/src/app/view/OsReceive/state/OsReceiveState.ts @@ -29,7 +29,6 @@ export const osReceiveReducer = ( action: OsReceiveAction ): OsReceiveState => { let nextState = state - dangerousOsReceiveState = nextState switch (action.type) { case OsReceiveActionType.SetFilesToUpload: @@ -94,21 +93,6 @@ export const initialState: OsReceiveState = { candidateApps: undefined } -/** - * This variable is used to expose the state to the outside world. - * - * It is meant to be a temporary solution to fix an issue where resetUIstate() - * has to know the state of this feature before executing its logic, - * but at the time of writing resetUIState has no connection to the React tree. - * - * It should not be used anywhere else unless absolutely necessary. - * ResetUIState() should be refactored to use a proper React context. - * It can't be done at the time of this commit for time constraints. - */ -let dangerousOsReceiveState = initialState -export const getDangerousOsReceiveState = (): OsReceiveState => - dangerousOsReceiveState - export const useOsReceiveState = (): OsReceiveState => { const context = useContext(OsReceiveStateContext) if (context === undefined) { diff --git a/src/libs/intents/setFlagshipUI.ts b/src/libs/intents/setFlagshipUI.ts index 23730c80a..0d5462333 100644 --- a/src/libs/intents/setFlagshipUI.ts +++ b/src/libs/intents/setFlagshipUI.ts @@ -12,7 +12,6 @@ import { } from '/app/theme/themeManager' import { navigationRef } from '/libs/RootNavigation' import { routes } from '/constants/routes' -import { getDangerousOsReceiveState } from '/app/view/OsReceive/state/OsReceiveState' const log = Minilog('🎨 FLAGSHIP_UI') @@ -245,17 +244,6 @@ export const resetUIState = ( ? ThemeInput.Dark : getHomeThemeAsThemeInput() - // If the theme is light, and there are files to upload (OsReceiveScreen visible), then set the theme to dark - // This is done because the file upload dialog is light background, so we want to use dark icons - // This is a temporary fix until we have a proper React context - // see src/app/view/OsReceive/state/OsReceiveState.ts#getDangerousOsReceiveState - if (theme === ThemeInput.Light) { - const hasFilesToUpload = - getDangerousOsReceiveState().filesToUpload.length > 0 - - if (hasFilesToUpload) theme = ThemeInput.Dark - } - themeLog.info('resetUIState', { uri, theme }) void setFlagshipUI({ bottomTheme: theme, topTheme: theme }, 'resetUIState')