Systems sorted by State!

This commit is contained in:
Luke Berndt
2023-01-28 10:19:35 -05:00
parent b7e2419109
commit fe91b93a84
5 changed files with 109 additions and 69 deletions

View File

@@ -0,0 +1,26 @@
import {
createSlice,
createEntityAdapter,
createSelector
} from '@reduxjs/toolkit'
import { apiSlice} from '../api/apiSlice'
// Calling `someEndpoint.select(someArg)` generates a new selector that will return
// the query result object for a query with those parameters.
// To generate a selector for a specific query argument, call `select(theQueryArg)`.
// In this case, the users query has no params, so we don't pass anything to select()
export const selectSystemsResult = apiSlice.endpoints.getSystems.select()
const emptySystems = []
export const selectAllSystems = createSelector(
selectSystemsResult,
systemsResult => systemsResult.data?systemsResult.data.systems:emptySystems
)
export const selectActiveSystems = createSelector(
selectAllSystems,
(state) => null,
(systems) => systems.filter(system => system.active === true)
)