@@ -26,13 +26,11 @@ Ethereal Engine. All Rights Reserved.
2626import { Paginated } from '@feathersjs/feathers'
2727
2828import { AdminScopeType } from '@etherealengine/common/src/interfaces/AdminScopeType'
29- import { matches , Validator } from '@etherealengine/engine/src/common/functions/MatchesUtils '
30- import { defineAction , defineState , dispatchAction , getMutableState } from '@etherealengine/hyperflux'
29+ import { Engine } from '@etherealengine/engine/src/ecs/classes/Engine '
30+ import { defineState , getMutableState } from '@etherealengine/hyperflux'
3131
32- import { API } from '../../API'
3332import { NotificationService } from '../../common/services/NotificationService'
3433
35- //State
3634export const SCOPE_PAGE_LIMIT = 100
3735
3836export const AdminScopeTypeState = defineState ( {
@@ -50,48 +48,30 @@ export const AdminScopeTypeState = defineState({
5048 } )
5149} )
5250
53- const getScopeTypesReceptor = ( action : typeof AdminScopeTypeActions . getScopeTypes . matches . _TYPE ) => {
54- const state = getMutableState ( AdminScopeTypeState )
55- return state . merge ( {
56- scopeTypes : action . adminScopeTypeResult . data ,
57- skip : action . adminScopeTypeResult . skip ,
58- limit : action . adminScopeTypeResult . limit ,
59- total : action . adminScopeTypeResult . total ,
60- retrieving : false ,
61- fetched : true ,
62- updateNeeded : false ,
63- lastFetched : Date . now ( )
64- } )
65- }
66-
67- export const AdminScopeTypeReceptor = {
68- getScopeTypesReceptor
69- }
70-
71- //Service
7251export const AdminScopeTypeService = {
73- getScopeTypeService : async ( incDec ?: 'increment' | 'decrement' ) => {
52+ getScopeTypeService : async ( page = 0 ) => {
7453 const scopeState = getMutableState ( AdminScopeTypeState )
75- const skip = scopeState . skip . value
76- const limit = scopeState . limit . value
54+ const $limit = scopeState . limit . value
55+ const $skip = page * $ limit
7756 try {
78- const result = ( await API . instance . client . service ( 'scope-type' ) . find ( {
57+ const result = ( await Engine . instance . api . service ( 'scope-type' ) . find ( {
7958 query : {
80- $skip : incDec === 'increment' ? skip + limit : incDec === 'decrement' ? skip - limit : skip ,
81- $limit : limit
59+ $skip,
60+ $limit
8261 }
8362 } ) ) as Paginated < AdminScopeType >
84- dispatchAction ( AdminScopeTypeActions . getScopeTypes ( { adminScopeTypeResult : result } ) )
63+ getMutableState ( AdminScopeTypeState ) . merge ( {
64+ scopeTypes : result . data ,
65+ skip : result . skip ,
66+ limit : result . limit ,
67+ total : result . total ,
68+ retrieving : false ,
69+ fetched : true ,
70+ updateNeeded : false ,
71+ lastFetched : Date . now ( )
72+ } )
8573 } catch ( err ) {
8674 NotificationService . dispatchNotify ( err . message , { variant : 'error' } )
8775 }
8876 }
8977}
90-
91- //Action
92- export class AdminScopeTypeActions {
93- static getScopeTypes = defineAction ( {
94- type : 'ee.client.AdminScopeType.SCOPE_TYPES_RETRIEVED' as const ,
95- adminScopeTypeResult : matches . object as Validator < unknown , Paginated < AdminScopeType > >
96- } )
97- }
0 commit comments