-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a37563
commit a487322
Showing
16 changed files
with
203 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,34 @@ | ||
"use client"; | ||
|
||
import { store } from "@/state/store/store"; | ||
import React, { ReactNode } from "react"; | ||
import { makeStore } from "@/state/store/store"; | ||
import React, { type ReactNode, useRef, useEffect } from "react"; | ||
import { Provider } from "react-redux"; | ||
import { setupListeners } from "@reduxjs/toolkit/query"; | ||
|
||
import type { AppStore } from "@/state/store"; | ||
|
||
type ReduxProviderType = { | ||
children: ReactNode; | ||
readonly children: ReactNode; | ||
}; | ||
|
||
const ReduxProvider = ({ children }: ReduxProviderType) => { | ||
return <Provider store={store}>{children}</Provider>; | ||
const storeRef = useRef<AppStore | null>(null); | ||
|
||
if (!storeRef.current) { | ||
// Create the store instance the first time this renders | ||
storeRef.current = makeStore(); | ||
} | ||
|
||
useEffect(() => { | ||
if (storeRef.current != null) { | ||
// configure listeners using the provided defaults | ||
// optional, but required for `refetchOnFocus`/`refetchOnReconnect` behaviors | ||
const unsubscribe = setupListeners(storeRef.current.dispatch); | ||
return unsubscribe; | ||
} | ||
}, []); | ||
|
||
return <Provider store={storeRef.current}>{children}</Provider>; | ||
}; | ||
|
||
export default ReduxProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// TODO: Implement the client side of the trunk player Socket.IO client library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { AuthFetchHeaders } from "./auth"; | ||
import type { PaginatedResponse } from "@/types/api/APIResponses"; | ||
import type { System } from "@/types/api/System"; | ||
|
||
export const getSystems = async (authHeaders: AuthFetchHeaders) => { | ||
const systemsRes = await fetch( | ||
`${process.env.SERVICE_API_BASE_URL}/radio/system/list`, | ||
{ | ||
method: "GET", | ||
headers: authHeaders, | ||
} | ||
); | ||
|
||
if (!systemsRes.ok) { | ||
return null; | ||
} | ||
|
||
return (await systemsRes.json()) as PaginatedResponse<System[]>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { createEntityAdapter, createSlice } from "@reduxjs/toolkit"; | ||
|
||
import type { System } from "@/types/api/System"; | ||
import type { AppState } from "@/state/store"; | ||
|
||
const systemsAdapter = createEntityAdapter({ | ||
selectId: (system: System) => system.UUID, | ||
sortComparer: (a, b) => a.name.localeCompare(b.name), | ||
}); | ||
|
||
const initialState = systemsAdapter.getInitialState(); | ||
|
||
const systemsSlice = createSlice({ | ||
name: "systems", | ||
initialState, | ||
reducers: { | ||
addSystem: systemsAdapter.addOne, | ||
addSystems: systemsAdapter.addMany, | ||
updateSystem: systemsAdapter.updateOne, | ||
removeSystem: systemsAdapter.removeOne, | ||
}, | ||
}); | ||
|
||
export const { addSystem, addSystems, updateSystem, removeSystem } = | ||
systemsSlice.actions; | ||
|
||
export default systemsSlice.reducer; | ||
|
||
export const { | ||
selectById: selectSystemById, | ||
selectIds: selectSystemIds, | ||
selectEntities: selectSystemEntities, | ||
selectAll: selectAllSystems, | ||
selectTotal: selectTotalSystems, | ||
} = systemsAdapter.getSelectors<AppState>((state) => state.systems); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { createSlice, PayloadAction } from "@reduxjs/toolkit"; | ||
import { SocketConnectionState } from "@/types/state/SocketConnectionState"; | ||
|
||
import type { AppState } from "../store"; | ||
|
||
const initialState: SocketConnectionState = { | ||
isConnected: false, | ||
}; | ||
|
||
export const socketConnectionSlice = createSlice({ | ||
name: "socketConnection", | ||
initialState, | ||
reducers: { | ||
setIsConnected: (state, action: PayloadAction<boolean>) => { | ||
state.isConnected = action.payload; | ||
}, | ||
}, | ||
extraReducers: (_builder) => {}, | ||
}); | ||
|
||
export const { setIsConnected } = socketConnectionSlice.actions; | ||
|
||
export const selectIsSocketConnected = (state: AppState) => | ||
state.socketConnection.isConnected; | ||
|
||
export default socketConnectionSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
import { configureStore } from "@reduxjs/toolkit"; | ||
|
||
import layoutReducer from "@/state/slices/layoutSlice"; | ||
import { socketConnectionSlice } from "../slices/socketConnectionSlice"; | ||
import systemsReducer from "../slices/entitySlices/systemsSlice"; | ||
|
||
export function makeStore() { | ||
export const makeStore = () => { | ||
return configureStore({ | ||
reducer: { | ||
layout: layoutReducer, | ||
socketConnection: socketConnectionSlice.reducer, | ||
systems: systemsReducer, | ||
}, | ||
devTools: process.env.NODE_ENV !== "production", | ||
}); | ||
} | ||
}; | ||
|
||
export const store = makeStore(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface PaginatedResponse<T extends Array<any> = any[]> { | ||
count: number; | ||
next: string | null; | ||
previous: string | null; | ||
results: T; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export interface System { | ||
UUID: string; | ||
name: string; | ||
systemACL: string; | ||
rr_system_id?: string; | ||
enable_talkgroup_acls: boolean; | ||
prune_transmissions: boolean; | ||
prune_transmissions_after_days: number; | ||
notes: string; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface SocketConnectionState { | ||
isConnected: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { type AuthFetchHeaders, getAuthFetchHeaders } from "@/lib/server/auth"; | ||
|
||
import type { ReadonlyRequestCookies } from "next/dist/server/web/spec-extension/adapters/request-cookies"; | ||
|
||
import type { NextRequest } from "next/server"; | ||
|
||
export const getAuthFetchHeadersOrThrow = async ( | ||
req: NextRequest | ReadonlyRequestCookies | ||
): Promise<AuthFetchHeaders> => { | ||
const fetchHeaders = await getAuthFetchHeaders(req); | ||
|
||
if (!fetchHeaders) { | ||
throw new Error("Unauthorized"); | ||
} | ||
|
||
return fetchHeaders; | ||
}; |