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

Commit b852414

Browse files
refactor(client-core)(bot service): remove action receptor usage (#8321)
* refactor(client-core)(instance service): remove action and receptor usage * fix: typing refactor * refactor: api.instance.client to engine.instance.api * fix: remove unused import * refactor(client-core)(bot service): remove action receptor usage --------- Co-authored-by: HexaField <joshfield999@gmail.com>
1 parent 21ff49c commit b852414

File tree

2 files changed

+19
-90
lines changed

2 files changed

+19
-90
lines changed

packages/client-core/src/admin/services/BotsService.ts

Lines changed: 18 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@ import { Paginated } from '@feathersjs/feathers'
2727

2828
import { AdminBot, CreateBotAsAdmin } from '@etherealengine/common/src/interfaces/AdminBot'
2929
import multiLogger from '@etherealengine/common/src/logger'
30-
import { matches, Validator } from '@etherealengine/engine/src/common/functions/MatchesUtils'
31-
import { defineAction, defineState, dispatchAction, getMutableState } from '@etherealengine/hyperflux'
30+
import { Engine } from '@etherealengine/engine/src/ecs/classes/Engine'
31+
import { defineState, getMutableState } from '@etherealengine/hyperflux'
3232

33-
import { API } from '../../API'
34-
import { AuthState } from '../../user/services/AuthService'
33+
import { userIsAdmin } from '../../user/userHasAccess'
3534

3635
const logger = multiLogger.child({ component: 'client-core:BotsService' })
3736

38-
//State
3937
export const BOTS_PAGE_LIMIT = 100
4038

4139
export const AdminBotState = defineState({
@@ -52,56 +50,21 @@ export const AdminBotState = defineState({
5250
})
5351
})
5452

55-
const fetchedBotReceptor = (action: typeof AdminBotsActions.fetchedBot.matches._TYPE) => {
56-
const state = getMutableState(AdminBotState)
57-
return state.merge({
58-
bots: action.bots.data,
59-
retrieving: false,
60-
fetched: true,
61-
updateNeeded: false,
62-
lastFetched: Date.now()
63-
})
64-
}
65-
66-
const botCreatedReceptor = (action: typeof AdminBotsActions.botCreated.matches._TYPE) => {
67-
const state = getMutableState(AdminBotState)
68-
return state.merge({ updateNeeded: true })
69-
}
70-
71-
const botPatchedReceptor = (action: typeof AdminBotsActions.botPatched.matches._TYPE) => {
72-
const state = getMutableState(AdminBotState)
73-
return state.merge({ updateNeeded: true })
74-
}
75-
76-
const botRemovedReceptor = (action: typeof AdminBotsActions.botRemoved.matches._TYPE) => {
77-
const state = getMutableState(AdminBotState)
78-
return state.merge({ updateNeeded: true })
79-
}
80-
81-
export const AdminBotServiceReceptors = {
82-
fetchedBotReceptor,
83-
botCreatedReceptor,
84-
botPatchedReceptor,
85-
botRemovedReceptor
86-
}
87-
88-
//Service
8953
export const AdminBotService = {
9054
createBotAsAdmin: async (data: CreateBotAsAdmin) => {
9155
try {
92-
const bot = await API.instance.client.service('bot').create(data)
93-
dispatchAction(AdminBotsActions.botCreated({ bot }))
56+
await Engine.instance.api.service('bot').create(data)
57+
getMutableState(AdminBotState).merge({ updateNeeded: true })
9458
} catch (error) {
9559
logger.error(error)
9660
}
9761
},
9862
fetchBotAsAdmin: async (incDec?: 'increment' | 'decrement') => {
9963
try {
100-
const user = getMutableState(AuthState).user
10164
const skip = getMutableState(AdminBotState).skip.value
10265
const limit = getMutableState(AdminBotState).limit.value
103-
if (user.scopes?.value?.find((scope) => scope.type === 'admin:admin')) {
104-
const bots = (await API.instance.client.service('bot').find({
66+
if (userIsAdmin()) {
67+
const bots = (await Engine.instance.api.service('bot').find({
10568
query: {
10669
$sort: {
10770
name: 1
@@ -111,45 +74,32 @@ export const AdminBotService = {
11174
action: 'admin'
11275
}
11376
})) as Paginated<AdminBot>
114-
dispatchAction(AdminBotsActions.fetchedBot({ bots }))
77+
getMutableState(AdminBotState).merge({
78+
bots: bots.data,
79+
retrieving: false,
80+
fetched: true,
81+
updateNeeded: false,
82+
lastFetched: Date.now()
83+
})
11584
}
11685
} catch (error) {
11786
logger.error(error)
11887
}
11988
},
12089
removeBots: async (id: string) => {
12190
try {
122-
const bot = (await API.instance.client.service('bot').remove(id)) as AdminBot
123-
dispatchAction(AdminBotsActions.botRemoved({ bot }))
91+
await Engine.instance.api.service('bot').remove(id)
92+
getMutableState(AdminBotState).merge({ updateNeeded: true })
12493
} catch (error) {
12594
logger.error(error)
12695
}
12796
},
12897
updateBotAsAdmin: async (id: string, bot: CreateBotAsAdmin) => {
12998
try {
130-
const result = (await API.instance.client.service('bot').patch(id, bot)) as AdminBot
131-
dispatchAction(AdminBotsActions.botPatched({ bot: result }))
99+
await Engine.instance.api.service('bot').patch(id, bot)
100+
getMutableState(AdminBotState).merge({ updateNeeded: true })
132101
} catch (error) {
133102
logger.error(error)
134103
}
135104
}
136105
}
137-
//Action
138-
export class AdminBotsActions {
139-
static fetchedBot = defineAction({
140-
type: 'ee.client.AdminBots.BOT_ADMIN_DISPLAY' as const,
141-
bots: matches.object as Validator<unknown, Paginated<AdminBot>>
142-
})
143-
static botCreated = defineAction({
144-
type: 'ee.client.AdminBots.BOT_ADMIN_CREATE' as const,
145-
bot: matches.object as Validator<unknown, AdminBot>
146-
})
147-
static botRemoved = defineAction({
148-
type: 'ee.client.AdminBots.BOT_ADMIN_REMOVE' as const,
149-
bot: matches.object as Validator<unknown, AdminBot>
150-
})
151-
static botPatched = defineAction({
152-
type: 'ee.client.AdminBots.BOT_ADMIN_UPDATE' as const,
153-
bot: matches.object as Validator<unknown, AdminBot>
154-
})
155-
}

packages/client-core/src/systems/AdminSystem.tsx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@ Ethereal Engine. All Rights Reserved.
2424
*/
2525

2626
import { defineSystem } from '@etherealengine/engine/src/ecs/functions/SystemFunctions'
27-
import { defineAction, defineActionQueue } from '@etherealengine/hyperflux'
27+
import { defineActionQueue } from '@etherealengine/hyperflux'
2828

2929
import { AdminActiveRouteActions, AdminActiveRouteReceptors } from '../admin/services/ActiveRouteService'
30-
import { AdminBotsActions, AdminBotServiceReceptors } from '../admin/services/BotsService'
31-
import { AdminBuildStatusActions, AdminBuildStatusReceptors } from '../admin/services/BuildStatusService'
32-
import { AdminGroupActions, AdminGroupServiceReceptors } from '../admin/services/GroupService'
3330
import { AdminLocationActions, AdminLocationReceptors } from '../admin/services/LocationService'
3431
import { AdminPartyActions, AdminPartyReceptors } from '../admin/services/PartyService'
3532
import { AdminResourceActions, AdminResourceReceptors } from '../admin/services/ResourceService'
@@ -89,15 +86,6 @@ const partyRetrievedQueue = defineActionQueue(AdminPartyActions.partyRetrieved.m
8986
const partyAdminCreatedQueue = defineActionQueue(AdminPartyActions.partyAdminCreated.matches)
9087
const partyRemovedQueue = defineActionQueue(AdminPartyActions.partyRemoved.matches)
9188
const partyPatchedQueue = defineActionQueue(AdminPartyActions.partyPatched.matches)
92-
const fetchedBotQueue = defineActionQueue(AdminBotsActions.fetchedBot.matches)
93-
const botCreatedQueue = defineActionQueue(AdminBotsActions.botCreated.matches)
94-
const botPatchedQueue = defineActionQueue(AdminBotsActions.botPatched.matches)
95-
const botRemovedQueue = defineActionQueue(AdminBotsActions.botRemoved.matches)
96-
const fetchingGroupQueue = defineActionQueue(AdminGroupActions.fetchingGroup.matches)
97-
const setAdminGroupQueue = defineActionQueue(AdminGroupActions.setAdminGroup.matches)
98-
const updateGroupQueue = defineActionQueue(AdminGroupActions.updateGroup.matches)
99-
const removeGroupActionQueue = defineActionQueue(AdminGroupActions.removeGroupAction.matches)
100-
const addAdminGroupQueue = defineActionQueue(AdminGroupActions.addAdminGroup.matches)
10189
const activeRoutesRetrievedQueue = defineActionQueue(AdminActiveRouteActions.activeRoutesRetrieved.matches)
10290
const fetchedInstanceServerQueue = defineActionQueue(InstanceServerSettingActions.fetchedInstanceServer.matches)
10391
const chargebeeSettingRetrievedQueue = defineActionQueue(AdminChargebeeSettingActions.chargebeeSettingRetrieved.matches)
@@ -142,15 +130,6 @@ const execute = () => {
142130
for (const action of partyAdminCreatedQueue()) AdminPartyReceptors.partyAdminCreatedReceptor(action)
143131
for (const action of partyRemovedQueue()) AdminPartyReceptors.partyRemovedReceptor(action)
144132
for (const action of partyPatchedQueue()) AdminPartyReceptors.partyPatchedReceptor(action)
145-
for (const action of fetchedBotQueue()) AdminBotServiceReceptors.fetchedBotReceptor(action)
146-
for (const action of botCreatedQueue()) AdminBotServiceReceptors.botCreatedReceptor(action)
147-
for (const action of botPatchedQueue()) AdminBotServiceReceptors.botPatchedReceptor(action)
148-
for (const action of botRemovedQueue()) AdminBotServiceReceptors.botRemovedReceptor(action)
149-
for (const action of fetchingGroupQueue()) AdminGroupServiceReceptors.fetchingGroupReceptor(action)
150-
for (const action of setAdminGroupQueue()) AdminGroupServiceReceptors.setAdminGroupReceptor(action)
151-
for (const action of updateGroupQueue()) AdminGroupServiceReceptors.updateGroupReceptor(action)
152-
for (const action of removeGroupActionQueue()) AdminGroupServiceReceptors.removeGroupActionReceptor(action)
153-
for (const action of addAdminGroupQueue()) AdminGroupServiceReceptors.addAdminGroupReceptor(action)
154133
for (const action of activeRoutesRetrievedQueue()) AdminActiveRouteReceptors.activeRoutesRetrievedReceptor(action)
155134
for (const action of fetchedInstanceServerQueue()) AdminInstanceServerReceptors.fetchedInstanceServerReceptor(action)
156135
for (const action of chargebeeSettingRetrievedQueue())

0 commit comments

Comments
 (0)