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

Commit

Permalink
refactor(client-core)(location service): remove action receptor usage (
Browse files Browse the repository at this point in the history
…#8318)

Co-authored-by: HexaField <joshfield999@gmail.com>
  • Loading branch information
aditya-mitra and HexaField authored Jul 20, 2023
1 parent 37e7826 commit 07a5e4e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 116 deletions.
127 changes: 22 additions & 105 deletions packages/client-core/src/admin/services/LocationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ import { Paginated } from '@feathersjs/feathers'
import { Location } from '@etherealengine/common/src/interfaces/Location'
import { LocationType } from '@etherealengine/common/src/interfaces/LocationType'
import multiLogger from '@etherealengine/common/src/logger'
import { matches, Validator } from '@etherealengine/engine/src/common/functions/MatchesUtils'
import { defineAction, defineState, dispatchAction, getMutableState } from '@etherealengine/hyperflux'
import { Engine } from '@etherealengine/engine/src/ecs/classes/Engine'
import { defineState, getMutableState } from '@etherealengine/hyperflux'

import { API } from '../../API'
import { NotificationService } from '../../common/services/NotificationService'

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

//State
export const LOCATION_PAGE_LIMIT = 100

export const AdminLocationState = defineState({
Expand All @@ -55,72 +53,27 @@ export const AdminLocationState = defineState({
})
})

export const locationsRetrievedReceptor = (action: typeof AdminLocationActions.locationsRetrieved.matches._TYPE) => {
const state = getMutableState(AdminLocationState)
return state.merge({
locations: action.locations.data,
skip: action.locations.skip,
limit: action.locations.limit,
total: action.locations.total,
retrieving: false,
fetched: true,
updateNeeded: false,
lastFetched: Date.now()
})
}

export const locationCreatedReceptor = (action: typeof AdminLocationActions.locationCreated.matches._TYPE) => {
const state = getMutableState(AdminLocationState)
return state.merge({ updateNeeded: true, created: true })
}

export const locationPatchedReceptor = (action: typeof AdminLocationActions.locationPatched.matches._TYPE) => {
const state = getMutableState(AdminLocationState)
return state.merge({ updateNeeded: true })
}

export const locationRemovedReceptor = (action: typeof AdminLocationActions.locationRemoved.matches._TYPE) => {
const state = getMutableState(AdminLocationState)
return state.merge({ updateNeeded: true })
}

export const locationTypesRetrievedReceptor = (
action: typeof AdminLocationActions.locationTypesRetrieved.matches._TYPE
) => {
const state = getMutableState(AdminLocationState)
return state.merge({ locationTypes: action.locationTypes.data, updateNeeded: false })
}

export const AdminLocationReceptors = {
locationsRetrievedReceptor,
locationCreatedReceptor,
locationPatchedReceptor,
locationRemovedReceptor,
locationTypesRetrievedReceptor
}

//Service
export const AdminLocationService = {
fetchLocationTypes: async () => {
const locationTypes = (await API.instance.client.service('location-type').find()) as Paginated<LocationType>
dispatchAction(AdminLocationActions.locationTypesRetrieved({ locationTypes }))
await Engine.instance.api.service('location-type').find()
getMutableState(AdminLocationState).merge({ updateNeeded: true })
},
patchLocation: async (id: string, location: any) => {
try {
const result = await API.instance.client.service('location').patch(id, location)
dispatchAction(AdminLocationActions.locationPatched({ location: result }))
await Engine.instance.api.service('location').patch(id, location)
getMutableState(AdminLocationState).merge({ updateNeeded: true })
} catch (err) {
NotificationService.dispatchNotify(err.message, { variant: 'error' })
}
},
removeLocation: async (id: string) => {
const result = await API.instance.client.service('location').remove(id)
dispatchAction(AdminLocationActions.locationRemoved({ location: result }))
await Engine.instance.api.service('location').remove(id)
getMutableState(AdminLocationState).merge({ updateNeeded: true })
},
createLocation: async (location: any) => {
try {
const result = await API.instance.client.service('location').create(location)
dispatchAction(AdminLocationActions.locationCreated({ location: result }))
await Engine.instance.api.service('location').create(location)
getMutableState(AdminLocationState).merge({ updateNeeded: true, created: true })
} catch (err) {
NotificationService.dispatchNotify(err.message, { variant: 'error' })
}
Expand All @@ -142,7 +95,7 @@ export const AdminLocationService = {
}
}

const locations = (await API.instance.client.service('location').find({
const locations = (await Engine.instance.api.service('location').find({
query: {
$sort: {
...sortData
Expand All @@ -157,14 +110,23 @@ export const AdminLocationService = {
locations.data.forEach((locationData) => {
if (locationData.location_setting) locationData.locationSetting = locationData.location_setting
})
dispatchAction(AdminLocationActions.locationsRetrieved({ locations }))
getMutableState(AdminLocationState).merge({
locations: locations.data,
skip: locations.skip,
limit: locations.limit,
total: locations.total,
retrieving: false,
fetched: true,
updateNeeded: false,
lastFetched: Date.now()
})
} catch (error) {
logger.error(error)
}
},
searchAdminLocations: async (value, orderBy = 'asc') => {
try {
const locations = (await API.instance.client.service('location').find({
const locations = (await Engine.instance.api.service('location').find({
query: {
search: value,
$sort: {
Expand All @@ -183,48 +145,3 @@ export const AdminLocationService = {
}
}
}

//Action
export class AdminLocationActions {
static locationsRetrieved = defineAction({
type: 'ee.client.AdminLocation.ADMIN_LOCATIONS_RETRIEVED' as const,
locations: matches.object as Validator<unknown, Paginated<Location>>
})

// static locationRetrieved = defineAction({
// type: 'ee.client.AdminLocation.ADMIN_LOCATION_RETRIEVED' as const,
// location: matches.object as Validator<unknown, Location>
// })

static locationCreated = defineAction({
type: 'ee.client.AdminLocation.ADMIN_LOCATION_CREATED' as const,
location: matches.object as Validator<unknown, Location>
})

static locationPatched = defineAction({
type: 'ee.client.AdminLocation.ADMIN_LOCATION_PATCHED' as const,
location: matches.object as Validator<unknown, Location>
})

static locationRemoved = defineAction({
type: 'ee.client.AdminLocation.ADMIN_LOCATION_REMOVED' as const,
location: matches.object as Validator<unknown, Location>
})

// static locationBanCreated = defineAction({
// type: 'ee.client.AdminLocation.ADMIN_LOCATION_BAN_CREATED' as const
// })

// static fetchingCurrentLocation = defineAction({
// type: 'ee.client.AdminLocation.ADMIN_FETCH_CURRENT_LOCATION' as const
// })

// static locationNotFound = defineAction({
// type: 'ee.client.AdminLocation.ADMIN_LOCATION_NOT_FOUND' as const
// })

static locationTypesRetrieved = defineAction({
type: 'ee.client.AdminLocation.ADMIN_LOCATION_TYPES_RETRIEVED' as const,
locationTypes: matches.object as Validator<unknown, Paginated<LocationType>>
})
}
11 changes: 0 additions & 11 deletions packages/client-core/src/systems/AdminSystem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { defineSystem } from '@etherealengine/engine/src/ecs/functions/SystemFun
import { defineActionQueue } from '@etherealengine/hyperflux'

import { AdminActiveRouteActions, AdminActiveRouteReceptors } from '../admin/services/ActiveRouteService'
import { AdminLocationActions, AdminLocationReceptors } from '../admin/services/LocationService'
import { AdminResourceActions, AdminResourceReceptors } from '../admin/services/ResourceService'
import { AdminSceneActions, AdminSceneReceptors } from '../admin/services/SceneService'
import { AdminServerLogsActions, AdminServerLogsReceptors } from '../admin/services/ServerLogsService'
Expand Down Expand Up @@ -76,11 +75,6 @@ const resourceNeedsUpdateQueue = defineActionQueue(AdminResourceActions.resource
const resourcesResetFilterQueue = defineActionQueue(AdminResourceActions.resourcesResetFilter.matches)
const scenesFetchedQueue = defineActionQueue(AdminSceneActions.scenesFetched.matches)
const sceneFetchedQueue = defineActionQueue(AdminSceneActions.sceneFetched.matches)
const locationsRetrievedQueue = defineActionQueue(AdminLocationActions.locationsRetrieved.matches)
const locationCreatedQueue = defineActionQueue(AdminLocationActions.locationCreated.matches)
const locationPatchedQueue = defineActionQueue(AdminLocationActions.locationPatched.matches)
const locationRemovedQueue = defineActionQueue(AdminLocationActions.locationRemoved.matches)
const locationTypesRetrievedQueue = defineActionQueue(AdminLocationActions.locationTypesRetrieved.matches)
const activeRoutesRetrievedQueue = defineActionQueue(AdminActiveRouteActions.activeRoutesRetrieved.matches)
const fetchedInstanceServerQueue = defineActionQueue(InstanceServerSettingActions.fetchedInstanceServer.matches)
const chargebeeSettingRetrievedQueue = defineActionQueue(AdminChargebeeSettingActions.chargebeeSettingRetrieved.matches)
Expand Down Expand Up @@ -116,11 +110,6 @@ const execute = () => {
for (const action of resourcesResetFilterQueue()) AdminResourceReceptors.resourcesResetFilterReceptor(action)
for (const action of scenesFetchedQueue()) AdminSceneReceptors.scenesFetchedReceptor(action)
for (const action of sceneFetchedQueue()) AdminSceneReceptors.sceneFetchedReceptor(action)
for (const action of locationsRetrievedQueue()) AdminLocationReceptors.locationsRetrievedReceptor(action)
for (const action of locationCreatedQueue()) AdminLocationReceptors.locationCreatedReceptor(action)
for (const action of locationPatchedQueue()) AdminLocationReceptors.locationPatchedReceptor(action)
for (const action of locationRemovedQueue()) AdminLocationReceptors.locationRemovedReceptor(action)
for (const action of locationTypesRetrievedQueue()) AdminLocationReceptors.locationTypesRetrievedReceptor(action)
for (const action of activeRoutesRetrievedQueue()) AdminActiveRouteReceptors.activeRoutesRetrievedReceptor(action)
for (const action of fetchedInstanceServerQueue()) AdminInstanceServerReceptors.fetchedInstanceServerReceptor(action)
for (const action of chargebeeSettingRetrievedQueue())
Expand Down

0 comments on commit 07a5e4e

Please sign in to comment.