Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

refactor(client-core)(client-settings service): remove action receptor usage #8346

Merged
merged 1 commit into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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<ClientSettingType>
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' })
Expand All @@ -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<unknown, Paginated<ClientSettingType>>
})
static clientSettingPatched = defineAction({
type: 'ee.client.AdminClientSetting.CLIENT_SETTING_PATCHED' as const
})
}
7 changes: 1 addition & 6 deletions packages/client/src/route/public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -61,7 +58,6 @@ function RouterComp({ route }: { route: string }) {

useEffect(() => {
addActionReceptor(RouterServiceReceptor)
addActionReceptor(ClientSettingsServiceReceptor)
addActionReceptor(AuthSettingsServiceReceptor)
addActionReceptor(AuthServiceReceptor)
addActionReceptor(LocationServiceReceptor)
Expand All @@ -77,7 +73,6 @@ function RouterComp({ route }: { route: string }) {
}
return () => {
removeActionReceptor(RouterServiceReceptor)
removeActionReceptor(ClientSettingsServiceReceptor)
removeActionReceptor(AuthSettingsServiceReceptor)
removeActionReceptor(AuthServiceReceptor)
removeActionReceptor(LocationServiceReceptor)
Expand Down
7 changes: 1 addition & 6 deletions packages/client/src/route/public_tw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -65,7 +62,6 @@ function PublicRouter() {
const [routesReady, setRoutesReady] = useState(false)

useEffect(() => {
addActionReceptor(ClientSettingsServiceReceptor)
addActionReceptor(AuthSettingsServiceReceptor)
addActionReceptor(AuthServiceReceptor)
addActionReceptor(LocationServiceReceptor)
Expand All @@ -81,7 +77,6 @@ function PublicRouter() {
}

return () => {
removeActionReceptor(ClientSettingsServiceReceptor)
removeActionReceptor(AuthSettingsServiceReceptor)
removeActionReceptor(AuthServiceReceptor)
removeActionReceptor(LocationServiceReceptor)
Expand Down
4 changes: 1 addition & 3 deletions packages/ui/src/pages/Capture/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -161,7 +161,6 @@ const decorators = [
}, [authState.isLoggedIn])

useEffect(() => {
addActionReceptor(ClientSettingsServiceReceptor)
addActionReceptor(AuthSettingsServiceReceptor)
addActionReceptor(AuthServiceReceptor)
addActionReceptor(LocationServiceReceptor)
Expand All @@ -186,7 +185,6 @@ const decorators = [

return () => {
// removeActionReceptor(RouterServiceReceptor)
removeActionReceptor(ClientSettingsServiceReceptor)
removeActionReceptor(AuthSettingsServiceReceptor)
removeActionReceptor(AuthServiceReceptor)
removeActionReceptor(LocationServiceReceptor)
Expand Down
Loading