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

refactor(client-core)(auth-setting service): remove action receptor usage #8348

Merged
merged 2 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -25,14 +25,13 @@ Ethereal Engine. All Rights Reserved.

import { Paginated } from '@feathersjs/feathers'

import { matches, Validator } from '@etherealengine/engine/src/common/functions/MatchesUtils'
import { Engine } from '@etherealengine/engine/src/ecs/classes/Engine'
import {
AuthenticationSettingPatch,
authenticationSettingPath,
AuthenticationSettingType
} from '@etherealengine/engine/src/schemas/setting/authentication-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 @@ -50,73 +49,30 @@ export const AuthSettingsState = defineState({
})
})

export const AuthSettingsServiceReceptor = (action) => {
const s = getMutableState(AuthSettingsState)
matches(action)
.when(AuthSettingsActions.authSettingRetrieved.matches, (action) => {
return s.merge({
authSettings: action.authSetting.data,
skip: action.authSetting.skip,
limit: action.authSetting.limit,
total: action.authSetting.total,
updateNeeded: false
})
})
.when(AuthSettingsActions.authSettingPatched.matches, (action) => {
return s.updateNeeded.set(true)
})
}

// const authSettingRetrievedReceptor = (action: typeof AuthSettingsActions.authSettingRetrieved.matches._TYPE) => {
// const state = getMutableState(AuthSettingsState)
// return state.merge({
// authSettings: action.authSetting.data,
// skip: action.authSetting.skip,
// limit: action.authSetting.limit,
// total: action.authSetting.total,
// updateNeeded: false
// })
// }

// const authSettingPatchedReceptor = (action: typeof AuthSettingsActions.authSettingPatched.matches._TYPE) => {
// const state = getMutableState(AuthSettingsState)
// return state.updateNeeded.set(true)
// }

// export const AuthSettingsReceptors = {
// authSettingRetrievedReceptor,
// authSettingPatchedReceptor
// }

export const AuthSettingsService = {
fetchAuthSetting: async () => {
try {
await waitForClientAuthenticated()
const authSetting = (await Engine.instance.api
.service(authenticationSettingPath)
.find()) as Paginated<AuthenticationSettingType>
dispatchAction(AuthSettingsActions.authSettingRetrieved({ authSetting }))
getMutableState(AuthSettingsState).merge({
authSettings: authSetting.data,
skip: authSetting.skip,
limit: authSetting.limit,
total: authSetting.total,
updateNeeded: false
})
} catch (err) {
console.error(err)
NotificationService.dispatchNotify(err.message, { variant: 'error' })
}
},
patchAuthSetting: async (data: AuthenticationSettingPatch, id: string) => {
try {
await Engine.instance.api.service(authenticationSettingPath).patch(id, data)
dispatchAction(AuthSettingsActions.authSettingPatched({}))
getMutableState(AuthSettingsState)
} catch (err) {
NotificationService.dispatchNotify(err.message, { variant: 'error' })
}
}
}

export class AuthSettingsActions {
static authSettingRetrieved = defineAction({
type: 'ee.client.AuthSettings.AUTH_SETTINGS_FETCHED' as const,
authSetting: matches.object as Validator<unknown, Paginated<AuthenticationSettingType>>
})
static authSettingPatched = defineAction({
type: 'ee.client.AuthSettings.AUTH_SETTINGS_PATCHED' as const
})
}
3 changes: 0 additions & 3 deletions packages/client/src/route/public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { useLocation } from 'react-router-dom'

import {
AuthSettingsService,
AuthSettingsServiceReceptor,
AuthSettingsState
} from '@etherealengine/client-core/src/admin/services/Setting/AuthSettingService'
import {
Expand Down Expand Up @@ -62,7 +61,6 @@ function RouterComp({ route }: { route: string }) {
useEffect(() => {
addActionReceptor(RouterServiceReceptor)
addActionReceptor(ClientSettingsServiceReceptor)
addActionReceptor(AuthSettingsServiceReceptor)
addActionReceptor(AuthServiceReceptor)
addActionReceptor(LocationServiceReceptor)
addActionReceptor(ProjectServiceReceptor)
Expand All @@ -78,7 +76,6 @@ function RouterComp({ route }: { route: string }) {
return () => {
removeActionReceptor(RouterServiceReceptor)
removeActionReceptor(ClientSettingsServiceReceptor)
removeActionReceptor(AuthSettingsServiceReceptor)
removeActionReceptor(AuthServiceReceptor)
removeActionReceptor(LocationServiceReceptor)
removeActionReceptor(ProjectServiceReceptor)
Expand Down
3 changes: 0 additions & 3 deletions packages/client/src/route/public_tw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { Route, Routes, useLocation } from 'react-router-dom'

import {
AuthSettingsService,
AuthSettingsServiceReceptor,
AuthSettingsState
} from '@etherealengine/client-core/src/admin/services/Setting/AuthSettingService'
import {
Expand Down Expand Up @@ -66,7 +65,6 @@ function PublicRouter() {

useEffect(() => {
addActionReceptor(ClientSettingsServiceReceptor)
addActionReceptor(AuthSettingsServiceReceptor)
addActionReceptor(AuthServiceReceptor)
addActionReceptor(LocationServiceReceptor)
addActionReceptor(ProjectServiceReceptor)
Expand All @@ -82,7 +80,6 @@ function PublicRouter() {

return () => {
removeActionReceptor(ClientSettingsServiceReceptor)
removeActionReceptor(AuthSettingsServiceReceptor)
removeActionReceptor(AuthServiceReceptor)
removeActionReceptor(LocationServiceReceptor)
removeActionReceptor(ProjectServiceReceptor)
Expand Down
7 changes: 1 addition & 6 deletions packages/ui/src/pages/Capture/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ import React, { useEffect, useRef, useState } from 'react'
// import { useTranslation } from 'react-i18next'

// import { useLocation, useNavigate } from 'react-router-dom'
import {
AuthSettingsService,
AuthSettingsServiceReceptor
} from '@etherealengine/client-core/src/admin/services/Setting/AuthSettingService'
import { AuthSettingsService } 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 {
Expand Down Expand Up @@ -162,7 +159,6 @@ const decorators = [

useEffect(() => {
addActionReceptor(ClientSettingsServiceReceptor)
addActionReceptor(AuthSettingsServiceReceptor)
addActionReceptor(AuthServiceReceptor)
addActionReceptor(LocationServiceReceptor)
addActionReceptor(ProjectServiceReceptor)
Expand All @@ -187,7 +183,6 @@ const decorators = [
return () => {
// removeActionReceptor(RouterServiceReceptor)
removeActionReceptor(ClientSettingsServiceReceptor)
removeActionReceptor(AuthSettingsServiceReceptor)
removeActionReceptor(AuthServiceReceptor)
removeActionReceptor(LocationServiceReceptor)
removeActionReceptor(ProjectServiceReceptor)
Expand Down
Loading