mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-14 17:58:02 -05:00
showing calls
This commit is contained in:
@@ -11,7 +11,7 @@ import ListCalls from "./ListCalls";
|
|||||||
import { useSelector, useDispatch } from 'react-redux'
|
import { useSelector, useDispatch } from 'react-redux'
|
||||||
import { setLive } from "../features/callPlayer/callPlayerSlice";
|
import { setLive } from "../features/callPlayer/callPlayerSlice";
|
||||||
import { useGetGroupsQuery, useGetTalkgroupsQuery } from '../features/api/apiSlice'
|
import { useGetGroupsQuery, useGetTalkgroupsQuery } from '../features/api/apiSlice'
|
||||||
import { selectAllCalls, useGetCallsQuery } from "../features/calls/callsSlice";
|
import { selectAllCalls, useGetCallsQuery, callsAdapter } from "../features/calls/callsSlice";
|
||||||
import {
|
import {
|
||||||
Container,
|
Container,
|
||||||
Label,
|
Label,
|
||||||
@@ -38,8 +38,9 @@ function CallPlayer (props) {
|
|||||||
const { shortName } = useParams();
|
const { shortName } = useParams();
|
||||||
const { data:groupsData, isSuccess:isGroupsSuccess } = useGetGroupsQuery(shortName);
|
const { data:groupsData, isSuccess:isGroupsSuccess } = useGetGroupsQuery(shortName);
|
||||||
const { data:callsData, isSuccess:isCallsSuccess } = useGetCallsQuery({shortName});
|
const { data:callsData, isSuccess:isCallsSuccess } = useGetCallsQuery({shortName});
|
||||||
|
//console.log(callsData);
|
||||||
const { data:talkgroupsData, isSuccess:isTalkgroupsSuccess } = useGetTalkgroupsQuery(shortName);
|
const { data:talkgroupsData, isSuccess:isTalkgroupsSuccess } = useGetTalkgroupsQuery(shortName);
|
||||||
//const allCalls = selectAllCalls(shortName)
|
const allCalls = callsData?callsData.ids.map( id => callsData.entities[id] ):[]
|
||||||
const [requestMessage, setRequestMessage] = useState("");
|
const [requestMessage, setRequestMessage] = useState("");
|
||||||
const [callUrl, setCallUrl] = useState("");
|
const [callUrl, setCallUrl] = useState("");
|
||||||
const [autoPlay, setAutoPlay] = useState(true);
|
const [autoPlay, setAutoPlay] = useState(true);
|
||||||
@@ -73,6 +74,7 @@ function CallPlayer (props) {
|
|||||||
if (sidebarOpened) setSidebarOpened(false);
|
if (sidebarOpened) setSidebarOpened(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const handleSidebarToggle = () => setSidebarOpened(!sidebarOpened);
|
const handleSidebarToggle = () => setSidebarOpened(!sidebarOpened);
|
||||||
const handleFilterToggle = () => setFilterVisible(!filterVisible);
|
const handleFilterToggle = () => setFilterVisible(!filterVisible);
|
||||||
const handleCalendarToggle = () => setCalendarVisible(!calendarVisible);
|
const handleCalendarToggle = () => setCalendarVisible(!calendarVisible);
|
||||||
@@ -592,7 +594,7 @@ const getFilter = () => {
|
|||||||
style={{ minHeight: '100vh' }}
|
style={{ minHeight: '100vh' }}
|
||||||
>
|
>
|
||||||
<Visibility onTopVisible={loadNewerCalls} onBottomVisible={loadOlderCalls} once={false}>
|
<Visibility onTopVisible={loadNewerCalls} onBottomVisible={loadOlderCalls} once={false}>
|
||||||
{/* <ListCalls callsAllIds={callsAllIds} currentCallRef={false} callsById={callsById} activeCallId={callId} talkgroups={talkgroupsData} playCall={playCall} /> */}
|
<ListCalls callsAllIds={callsData.ids} currentCallRef={false} callsById={callsData.entities} activeCallId={callId} talkgroups={talkgroupsData} playCall={playCall} />
|
||||||
</Visibility>
|
</Visibility>
|
||||||
</Sidebar.Pusher>
|
</Sidebar.Pusher>
|
||||||
</Sidebar.Pushable>
|
</Sidebar.Pushable>
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ import {
|
|||||||
|
|
||||||
import { apiSlice } from '../api/apiSlice'
|
import { apiSlice } from '../api/apiSlice'
|
||||||
|
|
||||||
const callsAdapter = createEntityAdapter({
|
// in order for the initial fetch to happen this call needs to be made in index.js
|
||||||
|
// store.dispatch(extendedApiSlice.endpoints.getCalls.initiate())
|
||||||
|
|
||||||
|
export const callsAdapter = createEntityAdapter({
|
||||||
selectId: (call) => call._id,
|
selectId: (call) => call._id,
|
||||||
sortComparer: (a, b) => a.time.localeCompare(b.time),
|
sortComparer: (a, b) => a.time.localeCompare(b.time),
|
||||||
})
|
})
|
||||||
@@ -16,11 +19,15 @@ import {
|
|||||||
export const extendedApiSlice = apiSlice.injectEndpoints({
|
export const extendedApiSlice = apiSlice.injectEndpoints({
|
||||||
endpoints: builder => ({
|
endpoints: builder => ({
|
||||||
getCalls: builder.query({
|
getCalls: builder.query({
|
||||||
query: ({shortName,filterType=0,filterCode=0}) => ({
|
query: ({shortName,filterType=0,filterCode=0}) => ({
|
||||||
url: `/${shortName}/calls`,
|
url: `/${shortName}/calls`,
|
||||||
method: "GET",
|
method: "GET",
|
||||||
params: { filterType, filterCode },
|
params: { filterType, filterCode },
|
||||||
}),
|
}),
|
||||||
|
/*query: () => ({
|
||||||
|
url: `/test/calls`,
|
||||||
|
method: "GET"
|
||||||
|
}),*/
|
||||||
transformResponse: responseData => {
|
transformResponse: responseData => {
|
||||||
responseData = responseData.calls;
|
responseData = responseData.calls;
|
||||||
return callsAdapter.setAll(initialState, responseData)
|
return callsAdapter.setAll(initialState, responseData)
|
||||||
@@ -29,20 +36,28 @@ import {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// from tutorials: https://redux.js.org/tutorials/essentials/part-8-rtk-query-advanced#transforming-responses
|
||||||
export const { useGetCallsQuery } = extendedApiSlice
|
export const { useGetCallsQuery } = extendedApiSlice
|
||||||
|
|
||||||
|
|
||||||
// Calling `someEndpoint.select(someArg)` generates a new selector that will return
|
// Calling `someEndpoint.select(someArg)` generates a new selector that will return
|
||||||
// the query result object for a query with those parameters.
|
// the query result object for a query with those parameters.
|
||||||
// To generate a selector for a specific query argument, call `select(theQueryArg)`.
|
// 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()
|
// In this case, the users query has no params, so we don't pass anything to select()
|
||||||
export const selectCallsResult = extendedApiSlice.endpoints.getCalls.select()
|
export const selectCallsResult = extendedApiSlice.endpoints.getCalls.select({"shortName":"test"})
|
||||||
|
|
||||||
|
const selectCallsData = createSelector(
|
||||||
export const selectCallsData = createSelector(
|
|
||||||
selectCallsResult,
|
selectCallsResult,
|
||||||
callsResult => callsResult.data
|
(callsResult) => {
|
||||||
|
return callsResult.data
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
export const { selectAll: selectAllCalls, selectById: selectCallById } =
|
export const { selectAll: selectAllCalls, selectById: selectCallById } = callsAdapter.getSelectors(state => {
|
||||||
callsAdapter.getSelectors(state => selectCallsData(state) ?? initialState)
|
return selectCallsData(state) ?? initialState
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
export const {selectAll: selectAllCalls} = callsAdapter.getSelectors((state) => {
|
||||||
|
return state.api}
|
||||||
|
);*/
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import AboutComponent from "./About/AboutComponent"
|
|||||||
|
|
||||||
|
|
||||||
const store = configureStore(/* provide initial state if any */)
|
const store = configureStore(/* provide initial state if any */)
|
||||||
|
|
||||||
const container = document.getElementById('root');
|
const container = document.getElementById('root');
|
||||||
const root = createRoot(container);
|
const root = createRoot(container);
|
||||||
root.render(
|
root.render(
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import callReducer from "../Call/call-reducer"
|
|||||||
import {apiSlice} from "../features/api/apiSlice"
|
import {apiSlice} from "../features/api/apiSlice"
|
||||||
import callPlayerSlice from "../features/callPlayer/callPlayerSlice"
|
import callPlayerSlice from "../features/callPlayer/callPlayerSlice"
|
||||||
|
|
||||||
|
|
||||||
export default (history) => combineReducers({
|
export default (history) => combineReducers({
|
||||||
router: connectRouter(history),
|
router: connectRouter(history),
|
||||||
system: systemReducer,
|
system: systemReducer,
|
||||||
@@ -16,7 +17,6 @@ export default (history) => combineReducers({
|
|||||||
group: groupReducer,
|
group: groupReducer,
|
||||||
callPlayer: callPlayerSlice,
|
callPlayer: callPlayerSlice,
|
||||||
call: callReducer,
|
call: callReducer,
|
||||||
|
|
||||||
[apiSlice.reducerPath]: apiSlice.reducer,
|
[apiSlice.reducerPath]: apiSlice.reducer,
|
||||||
|
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user