mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-13 09:17:30 -05:00
almost have loadolder working
This commit is contained in:
@@ -9,8 +9,8 @@ import CalendarModal from "./CalendarModalContainer";
|
|||||||
import CallInfo from "./CallInfo";
|
import CallInfo from "./CallInfo";
|
||||||
import ListCalls from "./ListCalls";
|
import ListCalls from "./ListCalls";
|
||||||
import { useSelector, useDispatch } from 'react-redux'
|
import { useSelector, useDispatch } from 'react-redux'
|
||||||
import { setLive } from "../features/callPlayer/callPlayerSlice";
|
import { setLive, setShortName } from "../features/callPlayer/callPlayerSlice";
|
||||||
import { getCalls} from "../features/calls/callsSlice";
|
import { getCalls, getOlderCalls} from "../features/calls/callsSlice";
|
||||||
import { useGetGroupsQuery, useGetTalkgroupsQuery } from '../features/api/apiSlice'
|
import { useGetGroupsQuery, useGetTalkgroupsQuery } from '../features/api/apiSlice'
|
||||||
import { selectAllCalls, useGetCallsQuery, callsAdapter } from "../features/calls/callsSlice";
|
import { selectAllCalls, useGetCallsQuery, callsAdapter } from "../features/calls/callsSlice";
|
||||||
import {
|
import {
|
||||||
@@ -21,13 +21,13 @@ import {
|
|||||||
Menu,
|
Menu,
|
||||||
Icon,
|
Icon,
|
||||||
Sidebar,
|
Sidebar,
|
||||||
Visibility
|
Visibility,
|
||||||
|
Button
|
||||||
} from "semantic-ui-react";
|
} from "semantic-ui-react";
|
||||||
import "./CallPlayer.css";
|
import "./CallPlayer.css";
|
||||||
//import setupSocket from '../socket/SetupSocket.js'
|
//import setupSocket from '../socket/SetupSocket.js'
|
||||||
import queryString from '../query-string';
|
import queryString from '../query-string';
|
||||||
|
|
||||||
import { setShortName } from "./call-actions";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -89,9 +89,6 @@ function CallPlayer (props) {
|
|||||||
|
|
||||||
const loadNewerCalls = () => {
|
const loadNewerCalls = () => {
|
||||||
|
|
||||||
}
|
|
||||||
const loadOlderCalls = () => {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const playCall = (data) => {
|
const playCall = (data) => {
|
||||||
@@ -109,13 +106,13 @@ function CallPlayer (props) {
|
|||||||
console.log("Loading Newer Calls");
|
console.log("Loading Newer Calls");
|
||||||
callActions.fetchNewerCalls(newestCallTime.getTime());
|
callActions.fetchNewerCalls(newestCallTime.getTime());
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
loadOlderCalls() {
|
const loadOlderCalls = (getOlderCalls) => {
|
||||||
|
|
||||||
console.log("Loading Older Calls");
|
console.log("Loading Older Calls");
|
||||||
callActions.fetchOlderCalls(oldestCallTime.getTime());
|
dispatch(getOlderCalls());
|
||||||
|
|
||||||
}*/
|
}
|
||||||
|
|
||||||
|
|
||||||
const getFilter = () => {
|
const getFilter = () => {
|
||||||
@@ -385,13 +382,17 @@ const getFilter = () => {
|
|||||||
if (filter.live) {
|
if (filter.live) {
|
||||||
this.startSocket(shortName, filterType, filterCode, filter.filterStarred);
|
this.startSocket(shortName, filterType, filterCode, filter.filterStarred);
|
||||||
}*/
|
}*/
|
||||||
|
console.log("Setting short name to: " + shortName)
|
||||||
dispatch(setShortName(shortName));
|
dispatch(setShortName(shortName));
|
||||||
dispatch(getCalls({shortName}));
|
|
||||||
return () => {
|
return () => {
|
||||||
//this.endSocket();
|
//this.endSocket();
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
dispatch(getCalls({shortName}));
|
||||||
|
}, [shortName,filterGroupId,filterTalkgroups,filterType,filterStarred])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -599,6 +600,10 @@ const getFilter = () => {
|
|||||||
>
|
>
|
||||||
<Visibility onTopVisible={loadNewerCalls} onBottomVisible={loadOlderCalls} once={false}>
|
<Visibility onTopVisible={loadNewerCalls} onBottomVisible={loadOlderCalls} once={false}>
|
||||||
<ListCalls callsData={callsData} currentCallRef={false} activeCallId={callId} talkgroups={talkgroupsData} playCall={playCall} />
|
<ListCalls callsData={callsData} currentCallRef={false} activeCallId={callId} talkgroups={talkgroupsData} playCall={playCall} />
|
||||||
|
<Button onClick={()=> dispatch(getOlderCalls())}>Load More!</Button>
|
||||||
|
<div>
|
||||||
|
<Button>padding</Button>
|
||||||
|
</div>
|
||||||
</Visibility>
|
</Visibility>
|
||||||
</Sidebar.Pusher>
|
</Sidebar.Pusher>
|
||||||
</Sidebar.Pushable>
|
</Sidebar.Pushable>
|
||||||
|
|||||||
@@ -74,10 +74,11 @@ const initialState = {
|
|||||||
}).join('&')
|
}).join('&')
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildCallUrl(shortName,filterType=0,filterGroupId=false, filterTalkgroups=false,filterDate=false, date=false, direction=false,filterStarred=false) {
|
function buildCallUrl(getState, direction=false, date=false) {
|
||||||
var params = {};
|
var params = {};
|
||||||
var url = "";
|
var url = "";
|
||||||
|
|
||||||
|
const {shortName,filterType,filterGroupId, filterTalkgroups, filterStarred, filterDate} = getState().callPlayer;
|
||||||
|
|
||||||
if ((typeof direction === 'string') && (typeof date === 'number')) {
|
if ((typeof direction === 'string') && (typeof date === 'number')) {
|
||||||
url = url + '/' + direction;
|
url = url + '/' + direction;
|
||||||
@@ -126,14 +127,38 @@ const initialState = {
|
|||||||
|
|
||||||
export const getCalls = createAsyncThunk(
|
export const getCalls = createAsyncThunk(
|
||||||
'calls/getCalls',
|
'calls/getCalls',
|
||||||
async({shortName,filterType=0,filterGroupId=false, filterTalkgroups=false, filterStarred=false }) => {
|
async({},{getState, requestId}) => {
|
||||||
const url = buildCallUrl(shortName, filterType, filterGroupId,filterTalkgroups, filterStarred);
|
const state = getState()
|
||||||
|
const {loading,oldestCallTime, newestCallTime} = getState().call;
|
||||||
|
const url = buildCallUrl(getState);
|
||||||
const res = await fetch(url).then(
|
const res = await fetch(url).then(
|
||||||
(data) => data.json()
|
(data) => data.json()
|
||||||
)
|
)
|
||||||
return res;
|
return res;
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const getOlderCalls = createAsyncThunk(
|
||||||
|
'calls/getOlderCalls',
|
||||||
|
async({},{getState, requestId} ) => {
|
||||||
|
const {loading,oldestCallTime, newestCallTime} = getState().call;
|
||||||
|
const url = buildCallUrl(getState,"older",oldestCallTime.getTime());
|
||||||
|
const res = await fetch(url).then(
|
||||||
|
(data) => data.json()
|
||||||
|
)
|
||||||
|
return res;
|
||||||
|
})
|
||||||
|
|
||||||
|
export const getNewerCalls = createAsyncThunk(
|
||||||
|
'calls/getNewerCalls',
|
||||||
|
async({},{getState, requestId} ) => {
|
||||||
|
const {loading,oldestCallTime, newestCallTime} = getState().call;
|
||||||
|
const url = buildCallUrl(getState,"newer",newestCallTime.getTime());
|
||||||
|
const res = await fetch(url).then(
|
||||||
|
(data) => data.json()
|
||||||
|
)
|
||||||
|
return res;
|
||||||
|
})
|
||||||
|
|
||||||
export const callsSlice = createSlice({
|
export const callsSlice = createSlice({
|
||||||
name: 'calls',
|
name: 'calls',
|
||||||
initialState,
|
initialState,
|
||||||
@@ -142,15 +167,57 @@ export const callsSlice = createSlice({
|
|||||||
[getCalls.pending]: (state) => {
|
[getCalls.pending]: (state) => {
|
||||||
state.loading = true;
|
state.loading = true;
|
||||||
},
|
},
|
||||||
|
[getCalls.rejected]: (state) => {
|
||||||
|
state.loading = false;
|
||||||
|
},
|
||||||
[getCalls.fulfilled]: (state, {payload}) => {
|
[getCalls.fulfilled]: (state, {payload}) => {
|
||||||
state.loading = false;
|
state.loading = false;
|
||||||
state.data = callsAdapter.setAll(state.data, payload.calls)
|
state.data = callsAdapter.setAll(state.data, payload.calls)
|
||||||
state.newestCallTime = new Date(payload.calls[0].time)
|
if (state.data && (state.data.ids.length > 0)) {
|
||||||
state.oldestCallTime = new Date(payloads.calls[payloads.calls.length-1].time)
|
const first = state.data.ids[0]
|
||||||
|
const firstTime = state.data.entities[first].time;
|
||||||
|
const last = state.data.ids[state.data.ids[0].length-1];
|
||||||
|
const lastTime = state.data.entities[last].time;
|
||||||
|
state.newestCallTime = new Date(firstTime)
|
||||||
|
state.oldestCallTime = new Date(lastTime)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[getCalls.rejected]: (state) => {
|
[getOlderCalls.pending]: (state) => {
|
||||||
|
state.loading = true;
|
||||||
|
},
|
||||||
|
[getOlderCalls.rejected]: (state) => {
|
||||||
state.loading = false;
|
state.loading = false;
|
||||||
}
|
},
|
||||||
|
[getOlderCalls.fulfilled]: (state, {payload}) => {
|
||||||
|
state.loading = false;
|
||||||
|
state.data = callsAdapter.addMany(state.data, payload.calls)
|
||||||
|
if (state.data && (state.data.ids.length > 0)) {
|
||||||
|
const first = state.data.ids[0]
|
||||||
|
const firstTime = state.data.entities[first].time;
|
||||||
|
const last = state.data.ids[state.data.ids[0].length-1];
|
||||||
|
const lastTime = state.data.entities[last].time;
|
||||||
|
state.newestCallTime = new Date(firstTime)
|
||||||
|
state.oldestCallTime = new Date(lastTime)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[getNewerCalls.pending]: (state) => {
|
||||||
|
state.loading = true;
|
||||||
|
},
|
||||||
|
[getNewerCalls.rejected]: (state) => {
|
||||||
|
state.loading = false;
|
||||||
|
},
|
||||||
|
[getNewerCalls.fulfilled]: (state, {payload}) => {
|
||||||
|
state.loading = false;
|
||||||
|
state.data = callsAdapter.addMany(state.data, payload.calls)
|
||||||
|
if (state.data && (state.data.ids.length > 0)) {
|
||||||
|
const first = state.data.ids[0]
|
||||||
|
const firstTime = state.data.entities[first].time;
|
||||||
|
const last = state.data.ids[state.data.ids[0].length-1];
|
||||||
|
const lastTime = state.data.entities[last].time;
|
||||||
|
state.newestCallTime = new Date(firstTime)
|
||||||
|
state.oldestCallTime = new Date(lastTime)
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user