From d34b3f94fde7044ec7b92df6602c6116612201ab Mon Sep 17 00:00:00 2001 From: aditya-mitra <55396651+aditya-mitra@users.noreply.github.com> Date: Sat, 22 Jul 2023 11:59:11 +0530 Subject: [PATCH] refactor(client-core)(client-settings service): remove action receptor usage --- .../services/Setting/ClientSettingService.ts | 58 +++---------------- packages/client/src/route/public.tsx | 7 +-- packages/client/src/route/public_tw.tsx | 7 +-- .../ui/src/pages/Capture/index.stories.tsx | 4 +- 4 files changed, 12 insertions(+), 64 deletions(-) diff --git a/packages/client-core/src/admin/services/Setting/ClientSettingService.ts b/packages/client-core/src/admin/services/Setting/ClientSettingService.ts index 6b0e2abb93..066092f22b 100644 --- a/packages/client-core/src/admin/services/Setting/ClientSettingService.ts +++ b/packages/client-core/src/admin/services/Setting/ClientSettingService.ts @@ -27,14 +27,13 @@ import { Paginated } from '@feathersjs/feathers' import config from '@etherealengine/common/src/config' import multiLogger from '@etherealengine/common/src/logger' -import { matches, Validator } from '@etherealengine/engine/src/common/functions/MatchesUtils' import { Engine } from '@etherealengine/engine/src/ecs/classes/Engine' import { ClientSettingPatch, clientSettingPath, ClientSettingType } from '@etherealengine/engine/src/schemas/setting/client-setting.schema' -import { defineAction, defineState, dispatchAction, getMutableState } from '@etherealengine/hyperflux' +import { defineState, getMutableState } from '@etherealengine/hyperflux' import { NotificationService } from '../../../common/services/NotificationService' import waitForClientAuthenticated from '../../../util/wait-for-client-authenticated' @@ -49,48 +48,19 @@ export const AdminClientSettingsState = defineState({ }) }) -export const ClientSettingsServiceReceptor = (action) => { - const s = getMutableState(AdminClientSettingsState) - matches(action) - .when(ClientSettingActions.fetchedClient.matches, (action) => { - const [clientSetting] = action.clientSettings.data - if (clientSetting.key8thWall) { - config.client.key8thWall = clientSetting.key8thWall - } - - return s.merge({ client: action.clientSettings.data, updateNeeded: false }) - }) - .when(ClientSettingActions.clientSettingPatched.matches, (action) => { - return s.updateNeeded.set(true) - }) -} - -// const fetchedClientReceptor = (action: typeof ClientSettingActions.fetchedClient.matches._TYPE) => { -// const state = getMutableState(AdminClientSettingsState) -// return state.merge({ client: action.clientSettings.data, updateNeeded: false }) -// } - -// const clientSettingPatchedReceptor = (action: typeof ClientSettingActions.clientSettingPatched.matches._TYPE) => { -// const state = getMutableState(AdminClientSettingsState) -// return state.updateNeeded.set(true) -// } - -// export const ClientSettingReceptors = { -// fetchedClientReceptor, -// clientSettingPatchedReceptor -// } - export const ClientSettingService = { - fetchClientSettings: async (inDec?: 'increment' | 'decrement') => { + fetchClientSettings: async () => { try { - logger.info('waitingForClientAuthenticated') await waitForClientAuthenticated() - logger.info('CLIENT AUTHENTICATED!') const clientSettings = (await Engine.instance.api .service(clientSettingPath) .find()) as Paginated - logger.info('Dispatching fetchedClient') - dispatchAction(ClientSettingActions.fetchedClient({ clientSettings })) + + if (clientSettings[0].key8thWall) { + config.client.key8thWall = clientSettings[0].key8thWall + } + + getMutableState(AdminClientSettingsState).merge({ client: clientSettings.data, updateNeeded: false }) } catch (err) { logger.error(err) NotificationService.dispatchNotify(err.message, { variant: 'error' }) @@ -99,20 +69,10 @@ export const ClientSettingService = { patchClientSetting: async (data: ClientSettingPatch, id: string) => { try { await Engine.instance.api.service(clientSettingPath).patch(id, data) - dispatchAction(ClientSettingActions.clientSettingPatched({})) + getMutableState(AdminClientSettingsState).merge({ updateNeeded: true }) } catch (err) { logger.error(err) NotificationService.dispatchNotify(err.message, { variant: 'error' }) } } } - -export class ClientSettingActions { - static fetchedClient = defineAction({ - type: 'ee.client.AdminClientSetting.CLIENT_SETTING_DISPLAY' as const, - clientSettings: matches.object as Validator> - }) - static clientSettingPatched = defineAction({ - type: 'ee.client.AdminClientSetting.CLIENT_SETTING_PATCHED' as const - }) -} diff --git a/packages/client/src/route/public.tsx b/packages/client/src/route/public.tsx index dc27db75bc..d8645bec5d 100644 --- a/packages/client/src/route/public.tsx +++ b/packages/client/src/route/public.tsx @@ -32,10 +32,7 @@ import { AuthSettingsServiceReceptor, AuthSettingsState } from '@etherealengine/client-core/src/admin/services/Setting/AuthSettingService' -import { - AdminClientSettingsState, - ClientSettingsServiceReceptor -} from '@etherealengine/client-core/src/admin/services/Setting/ClientSettingService' +import { AdminClientSettingsState } from '@etherealengine/client-core/src/admin/services/Setting/ClientSettingService' import ErrorBoundary from '@etherealengine/client-core/src/common/components/ErrorBoundary' import { ProjectServiceReceptor } from '@etherealengine/client-core/src/common/services/ProjectService' import { RouterServiceReceptor, useCustomRoutes } from '@etherealengine/client-core/src/common/services/RouterService' @@ -61,7 +58,6 @@ function RouterComp({ route }: { route: string }) { useEffect(() => { addActionReceptor(RouterServiceReceptor) - addActionReceptor(ClientSettingsServiceReceptor) addActionReceptor(AuthSettingsServiceReceptor) addActionReceptor(AuthServiceReceptor) addActionReceptor(LocationServiceReceptor) @@ -77,7 +73,6 @@ function RouterComp({ route }: { route: string }) { } return () => { removeActionReceptor(RouterServiceReceptor) - removeActionReceptor(ClientSettingsServiceReceptor) removeActionReceptor(AuthSettingsServiceReceptor) removeActionReceptor(AuthServiceReceptor) removeActionReceptor(LocationServiceReceptor) diff --git a/packages/client/src/route/public_tw.tsx b/packages/client/src/route/public_tw.tsx index b6672588df..19100a7c99 100644 --- a/packages/client/src/route/public_tw.tsx +++ b/packages/client/src/route/public_tw.tsx @@ -32,10 +32,7 @@ import { AuthSettingsServiceReceptor, AuthSettingsState } from '@etherealengine/client-core/src/admin/services/Setting/AuthSettingService' -import { - AdminClientSettingsState, - ClientSettingsServiceReceptor -} from '@etherealengine/client-core/src/admin/services/Setting/ClientSettingService' +import { AdminClientSettingsState } from '@etherealengine/client-core/src/admin/services/Setting/ClientSettingService' import ErrorBoundary from '@etherealengine/client-core/src/common/components/ErrorBoundary' import { ProjectServiceReceptor } from '@etherealengine/client-core/src/common/services/ProjectService' import { useCustomRoutes } from '@etherealengine/client-core/src/common/services/RouterService' @@ -65,7 +62,6 @@ function PublicRouter() { const [routesReady, setRoutesReady] = useState(false) useEffect(() => { - addActionReceptor(ClientSettingsServiceReceptor) addActionReceptor(AuthSettingsServiceReceptor) addActionReceptor(AuthServiceReceptor) addActionReceptor(LocationServiceReceptor) @@ -81,7 +77,6 @@ function PublicRouter() { } return () => { - removeActionReceptor(ClientSettingsServiceReceptor) removeActionReceptor(AuthSettingsServiceReceptor) removeActionReceptor(AuthServiceReceptor) removeActionReceptor(LocationServiceReceptor) diff --git a/packages/ui/src/pages/Capture/index.stories.tsx b/packages/ui/src/pages/Capture/index.stories.tsx index 32b99fd419..0cadfe5526 100644 --- a/packages/ui/src/pages/Capture/index.stories.tsx +++ b/packages/ui/src/pages/Capture/index.stories.tsx @@ -34,7 +34,7 @@ import { AuthSettingsService, AuthSettingsServiceReceptor } from '@etherealengine/client-core/src/admin/services/Setting/AuthSettingService' -import { ClientSettingsServiceReceptor } from '@etherealengine/client-core/src/admin/services/Setting/ClientSettingService' + import { AdminCoilSettingService } from '@etherealengine/client-core/src/admin/services/Setting/CoilSettingService' import { NotificationAction, @@ -161,7 +161,6 @@ const decorators = [ }, [authState.isLoggedIn]) useEffect(() => { - addActionReceptor(ClientSettingsServiceReceptor) addActionReceptor(AuthSettingsServiceReceptor) addActionReceptor(AuthServiceReceptor) addActionReceptor(LocationServiceReceptor) @@ -186,7 +185,6 @@ const decorators = [ return () => { // removeActionReceptor(RouterServiceReceptor) - removeActionReceptor(ClientSettingsServiceReceptor) removeActionReceptor(AuthSettingsServiceReceptor) removeActionReceptor(AuthServiceReceptor) removeActionReceptor(LocationServiceReceptor)