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

Converted BuildStatusService.ts away from receptors. #8343

Merged
merged 1 commit into from
Jul 22, 2023
Merged
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
56 changes: 11 additions & 45 deletions packages/client-core/src/admin/services/BuildStatusService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ All portions of the code written by the Ethereal Engine team are Copyright © 20
Ethereal Engine. All Rights Reserved.
*/

import { matches, Validator } from '@etherealengine/engine/src/common/functions/MatchesUtils'
import { Engine } from '@etherealengine/engine/src/ecs/classes/Engine'
import { buildStatusPath, BuildStatusType } from '@etherealengine/engine/src/schemas/cluster/build-status.schema'
import { defineAction, defineState, dispatchAction, getMutableState } from '@etherealengine/hyperflux'

import { API } from '../../API'
import { NotificationService } from '../../common/services/NotificationService'
import { defineState, getMutableState } from '@etherealengine/hyperflux'

//State
export const AdminBuildStatusState = defineState({
Expand All @@ -43,30 +40,10 @@ export const AdminBuildStatusState = defineState({
})
})

const fetchBuildStatusReceptor = (action: typeof AdminBuildStatusActions.fetchBuildStatusRetrieved.matches._TYPE) => {
try {
const state = getMutableState(AdminBuildStatusState)
return state.merge({
buildStatuses: action.data,
skip: action.skip,
limit: action.limit,
total: action.total,
fetched: true,
updateNeeded: false
})
} catch (err) {
NotificationService.dispatchNotify(err.message, { variant: 'error' })
}
}

export const AdminBuildStatusReceptors = {
fetchBuildStatusReceptor
}

//Service
export const BuildStatusService = {
fetchBuildStatus: async (skip = 0) => {
let buildStatusResult = await API.instance.client.service(buildStatusPath).find({
let buildStatusResult = await Engine.instance.api.service(buildStatusPath).find({
query: {
$limit: 10,
$skip: skip,
Expand All @@ -76,24 +53,13 @@ export const BuildStatusService = {
}
})

dispatchAction(
AdminBuildStatusActions.fetchBuildStatusRetrieved({
data: buildStatusResult.data,
total: buildStatusResult.total,
skip: buildStatusResult.total,
limit: buildStatusResult.limit
})
)
getMutableState(AdminBuildStatusState).merge({
buildStatuses: buildStatusResult.data,
total: buildStatusResult.total,
skip: buildStatusResult.total,
limit: buildStatusResult.limit,
fetched: true,
updateNeeded: false
})
}
}

//Action
export class AdminBuildStatusActions {
static fetchBuildStatusRetrieved = defineAction({
type: 'ee.client.AdminBuildStatus.FETCH_BUILD_STATUS_RETRIEVED' as const,
data: matches.array as Validator<unknown, BuildStatusType[]>,
total: matches.number,
limit: matches.number,
skip: matches.number
})
}