diff options
| author | Max Nanis | 2026-02-18 20:42:03 -0500 |
|---|---|---|
| committer | Max Nanis | 2026-02-18 20:42:03 -0500 |
| commit | 3eaa56f0306ead818f64c3d99fc6d230d9b970a4 (patch) | |
| tree | 9fecc2f1456e6321572e0e65f57106916df173e2 /jb-ui/src/models/grlStatsSlice.ts | |
| download | amt-jb-3eaa56f0306ead818f64c3d99fc6d230d9b970a4.tar.gz amt-jb-3eaa56f0306ead818f64c3d99fc6d230d9b970a4.zip | |
HERE WE GO, HERE WE GO, HERE WE GO
Diffstat (limited to 'jb-ui/src/models/grlStatsSlice.ts')
| -rw-r--r-- | jb-ui/src/models/grlStatsSlice.ts | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/jb-ui/src/models/grlStatsSlice.ts b/jb-ui/src/models/grlStatsSlice.ts new file mode 100644 index 0000000..9385256 --- /dev/null +++ b/jb-ui/src/models/grlStatsSlice.ts @@ -0,0 +1,54 @@ +import { StatsSnapshot } from "@/api_fsb"; +import { RootState } from "@/store"; +import { createSelector, createSlice, PayloadAction } from '@reduxjs/toolkit'; + + +const initialState: StatsSnapshot[] = [] + +const grlStatsSlice = createSlice({ + name: 'grlStats', + initialState, + reducers: { + + addStatsData(state, action: PayloadAction<StatsSnapshot>) { + state.push(action.payload); + } + } +}) + +export const { + addStatsData +} = grlStatsSlice.actions; +export default grlStatsSlice.reducer + + +export const selectRecentStats = createSelector( + [ + (state: RootState) => state.stats, + ], + (stats): StatsSnapshot | null => { + const lastStat = stats[stats.length - 1]; + return lastStat ?? null; + } +); + +export const activeUsers = createSelector( + [selectRecentStats], + (recentStats): number | null => { + return recentStats?.active_users_last_24h ?? null; + } +); + +export const activeSurveys = createSelector( + [selectRecentStats], + (recentStats): number | null => { + return recentStats?.live_task_count?.total ?? null; + } +); + +export const maxPayout = createSelector( + [selectRecentStats], + (recentStats): number | null => { + return recentStats?.live_tasks_max_payout?.value ?? null; + } +); |
