mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-16 18:57:47 -05:00
Loads and gets calls
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import React from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { Link } from 'react-router-dom';
|
import { Link, useLocation} from 'react-router-dom';
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
import MediaPlayer from "./MediaPlayer";
|
import MediaPlayer from "./MediaPlayer";
|
||||||
import FilterModal from "./FilterModal";
|
import FilterModal from "./FilterModal";
|
||||||
import GroupModal from "./GroupModal";
|
import GroupModal from "./GroupModal";
|
||||||
@@ -7,6 +8,10 @@ import SupportModal from "./SupportModal";
|
|||||||
import CalendarModal from "./CalendarModalContainer";
|
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 { setLive } from "../features/callPlayer/callPlayerSlice";
|
||||||
|
import { useGetGroupsQuery, useGetTalkgroupsQuery } from '../features/api/apiSlice'
|
||||||
|
import { selectAllCalls, useGetCallsQuery } from "../features/calls/callsSlice";
|
||||||
import {
|
import {
|
||||||
Container,
|
Container,
|
||||||
Label,
|
Label,
|
||||||
@@ -20,114 +25,117 @@ import {
|
|||||||
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 {Groups, Calls} from "./call-data"
|
|
||||||
|
import { setShortName } from "./call-actions";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------
|
// ----------------------------------------------------
|
||||||
class CallPlayer extends React.Component {
|
function CallPlayer (props) {
|
||||||
|
|
||||||
constructor(props) {
|
const { shortName } = useParams();
|
||||||
super(props);
|
const { data:groupsData, isSuccess:isGroupsSuccess } = useGetGroupsQuery(shortName);
|
||||||
this.loadNewerCalls = this.loadNewerCalls.bind(this);
|
const { data:callsData, isSuccess:isCallsSuccess } = useGetCallsQuery({shortName});
|
||||||
this.loadOlderCalls = this.loadOlderCalls.bind(this);
|
const { data:talkgroupsData, isSuccess:isTalkgroupsSuccess } = useGetTalkgroupsQuery(shortName);
|
||||||
this.playCall = this.playCall.bind(this);
|
//const allCalls = selectAllCalls(shortName)
|
||||||
this.updateUri = this.updateUri.bind(this);
|
const [requestMessage, setRequestMessage] = useState("");
|
||||||
this.switchAutoPlay = this.switchAutoPlay.bind(this);
|
const [callUrl, setCallUrl] = useState("");
|
||||||
this.callEnded = this.callEnded.bind(this);
|
const [autoPlay, setAutoPlay] = useState(true);
|
||||||
this.addCall = this.addCall.bind(this);
|
const [callId, setCallId] = useState(false);
|
||||||
this.handlePusherClick = this.handlePusherClick.bind(this);
|
const [playTime, setPlayTime] = useState(0);
|
||||||
this.handleSidebarToggle = this.handleSidebarToggle.bind(this);
|
const [callScroll, setCallScroll] = useState(false);
|
||||||
this.handleFilterClose = this.handleFilterClose.bind(this);
|
const [callSelect, setCallSelect] = useState(false);
|
||||||
this.handleGroupClose = this.handleGroupClose.bind(this);
|
const [urlOptions, setUrlOptions] = useState(false);
|
||||||
this.handleCalendarToggle = this.handleCalendarToggle.bind(this);
|
const [isPlaying, setIsPlaying] = useState(false);
|
||||||
this.handleCalendarClose = this.handleCalendarClose.bind(this);
|
const [sidebarOpened, setSidebarOpened] = useState(false);
|
||||||
this.handleLiveToggle = this.handleLiveToggle.bind(this);
|
const [filterVisible, setFilterVisible] = useState(false);
|
||||||
this.handlePlayPause = this.handlePlayPause.bind(this);
|
const [groupVisible, setGroupVisible] = useState(false);
|
||||||
this.getFilter = this.getFilter.bind(this);
|
const [calendarVisible, setCalendarVisible] = useState(false);
|
||||||
this.socket = window.socket;
|
|
||||||
this.setupSocket = this.setupSocket.bind(this);
|
const dispatch = useDispatch();
|
||||||
this.endSocket = this.endSocket.bind(this);
|
|
||||||
this.changeUrl = this.changeUrl.bind(this);
|
|
||||||
this.audioRef = React.createRef();
|
const filterType = useSelector((state) => state.callPlayer.filterType);
|
||||||
this.currentCallRef = React.createRef();
|
const filterGroupId = useSelector((state) => state.callPlayer.filterGroupId);
|
||||||
this.state = {
|
const filterTalkgroups = useSelector((state) => state.callPlayer.filterTalkgroups);
|
||||||
requestMessage: "",
|
const filterStarred = useSelector((state) => state.callPlayer.filterStarred);
|
||||||
callUrl: "",
|
const filterDate = useSelector((state) => state.callPlayer.filterDate);
|
||||||
autoPlay: true,
|
const live = useSelector((state) => state.callPlayer.live);
|
||||||
callId: false,
|
|
||||||
playTime: 0,
|
const uri = queryString.parse(useLocation().search);
|
||||||
callScroll: false,
|
|
||||||
callSelect: false,
|
const switchAutoPlay = () => setAutoPlay(!autoPlay);
|
||||||
urlOptions: false,
|
const handlePlayPause = (playing) => setIsPlaying(playing);
|
||||||
isPlaying: false,
|
|
||||||
sidebarOpened: false,
|
const handlePusherClick = () => {
|
||||||
filterVisible: false,
|
if (sidebarOpened) setSidebarOpened(false);
|
||||||
groupVisible: false,
|
|
||||||
calendarVisible: false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switchAutoPlay = () => this.setState({
|
const handleSidebarToggle = () => setSidebarOpened(!sidebarOpened);
|
||||||
autoPlay: !this.state.autoPlay
|
const handleFilterToggle = () => setFilterVisible(!filterVisible);
|
||||||
})
|
const handleCalendarToggle = () => setCalendarVisible(!calendarVisible);
|
||||||
handlePlayPause = (playing) => this.setState({
|
const handleLiveToggle = () => {
|
||||||
isPlaying: playing
|
dispatch(setLive(!live));
|
||||||
})
|
}
|
||||||
handlePusherClick = () => {
|
|
||||||
const { sidebarOpened } = this.state
|
const audioRef = false;
|
||||||
|
|
||||||
|
const loadNewerCalls = () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
const loadOlderCalls = () => {
|
||||||
|
|
||||||
if (sidebarOpened) this.setState({ sidebarOpened: false })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSidebarToggle = () => this.setState({ sidebarOpened: !this.state.sidebarOpened })
|
const playCall = (data) => {
|
||||||
|
|
||||||
handleFilterToggle = () => this.setState({
|
}
|
||||||
filterVisible: !this.state.filterVisible
|
|
||||||
})
|
const callEnded = () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
/*const changeUrl = url => callActions.changeUrl(url)
|
||||||
|
|
||||||
handleContextRef = contextRef => this.setState({ contextRef })
|
handleContextRef = contextRef => this.setState({ contextRef })
|
||||||
changeUrl = url => this.props.callActions.changeUrl(url)
|
|
||||||
|
|
||||||
loadNewerCalls() {
|
loadNewerCalls() {
|
||||||
|
|
||||||
console.log("Loading Newer Calls");
|
console.log("Loading Newer Calls");
|
||||||
this.props.callActions.fetchNewerCalls(this.props.newestCallTime.getTime());
|
callActions.fetchNewerCalls(newestCallTime.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
loadOlderCalls() {
|
loadOlderCalls() {
|
||||||
|
|
||||||
console.log("Loading Older Calls");
|
console.log("Loading Older Calls");
|
||||||
this.props.callActions.fetchOlderCalls(this.props.oldestCallTime.getTime());
|
callActions.fetchOlderCalls(oldestCallTime.getTime());
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
|
||||||
handleCalendarToggle = () => this.setState({
|
|
||||||
calendarVisible: !this.state.calendarVisible
|
|
||||||
})
|
|
||||||
|
|
||||||
getFilter() {
|
const getFilter = () => {
|
||||||
|
|
||||||
var filter = { type: 'all', code: "", filterStarred: false };
|
var filter = { type: 'all', code: "", filterStarred: false };
|
||||||
switch (this.props.filterType) {
|
|
||||||
|
switch (filterType) {
|
||||||
case 1:
|
case 1:
|
||||||
filter.type = "group";
|
filter.type = "group";
|
||||||
filter.code = this.props.filterGroupId;
|
filter.code = filterGroupId
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
filter.type = "talkgroup";
|
filter.type = "talkgroup";
|
||||||
filter.code = this.props.filterTalkgroups;
|
filter.code = filterTalkgroups
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
case 0:
|
case 0:
|
||||||
filter.type = "all";
|
filter.type = "all";
|
||||||
filter.code = ""
|
filter.code = ""
|
||||||
}
|
}
|
||||||
filter.filterStarred = this.props.filterStarred;
|
filter.filterStarred = filterStarred
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
endSocket() {
|
/*
|
||||||
|
const endSocket = () => {
|
||||||
this.socket.removeAllListeners("new message");
|
this.socket.removeAllListeners("new message");
|
||||||
this.socket.removeAllListeners("reconnect");
|
this.socket.removeAllListeners("reconnect");
|
||||||
}
|
}
|
||||||
@@ -135,9 +143,9 @@ class CallPlayer extends React.Component {
|
|||||||
this.socket.on('new message', this.addCall);
|
this.socket.on('new message', this.addCall);
|
||||||
this.socket.on('reconnect', (attempts) => {
|
this.socket.on('reconnect', (attempts) => {
|
||||||
console.log("Socket Reconnected after attempts: " + attempts); // true
|
console.log("Socket Reconnected after attempts: " + attempts); // true
|
||||||
if (this.props.live) {
|
if (live) {
|
||||||
var filter = this.getFilter();
|
var filter = this.getFilter();
|
||||||
this.startSocket(this.props.shortName, filter.type, filter.code, filter.filterStarred);
|
this.startSocket(shortName, filter.type, filter.code, filter.filterStarred);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -154,16 +162,17 @@ class CallPlayer extends React.Component {
|
|||||||
this.socket.emit("stop");
|
this.socket.emit("stop");
|
||||||
}
|
}
|
||||||
handleLiveToggle() {
|
handleLiveToggle() {
|
||||||
if (!this.props.live) {
|
if (!live) {
|
||||||
this.props.callActions.setDateFilter(false);
|
callActions.setDateFilter(false);
|
||||||
this.props.callActions.setLive(false);
|
callActions.setLive(false);
|
||||||
this.setState({ callUrl: "", callId: false });
|
this.setState({ callUrl: "", callId: false });
|
||||||
this.props.callActions.fetchCalls();
|
callActions.fetchCalls();
|
||||||
var filter = this.getFilter();
|
var filter = this.getFilter();
|
||||||
this.startSocket(this.props.shortName, filter.type, filter.code, filter.filterStarred);
|
this.startSocket(shortName, filter.type, filter.code, filter.filterStarred);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
/*
|
||||||
updateUri(props, state) {
|
updateUri(props, state) {
|
||||||
var search = "?"
|
var search = "?"
|
||||||
switch (props.filterType) {
|
switch (props.filterType) {
|
||||||
@@ -198,51 +207,48 @@ class CallPlayer extends React.Component {
|
|||||||
}
|
}
|
||||||
search = search + `starred=true`;
|
search = search + `starred=true`;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
this.props.history.push({
|
history.push({
|
||||||
pathname: this.props.history.location.pathname,
|
pathname: history.location.pathname,
|
||||||
search: search
|
search: search
|
||||||
});*/
|
|
||||||
}
|
|
||||||
|
|
||||||
handleCalendarClose(didUpdate) {
|
|
||||||
this.setState({
|
|
||||||
calendarVisible: !this.state.calendarVisible
|
|
||||||
});
|
});
|
||||||
if (didUpdate) {
|
}
|
||||||
this.props.callActions.setLive(false);
|
*/
|
||||||
this.props.callActions.fetchCalls();
|
|
||||||
|
|
||||||
this.setState({ callUrl: "", callId: false });
|
const handleCalendarClose = (didUpdate) => {
|
||||||
this.stopSocket();
|
setCalendarVisible(!calendarVisible);
|
||||||
|
|
||||||
|
if (didUpdate) {
|
||||||
|
dispatchEvent(setLive(false));
|
||||||
|
setCallId(false);
|
||||||
|
setCallUrl("");
|
||||||
|
//callActions.fetchCalls();
|
||||||
|
//this.stopSocket();
|
||||||
//this.socket.close();
|
//this.socket.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleGroupClose(didUpdate) {
|
const handleGroupClose = (didUpdate) => {
|
||||||
this.setState({
|
setGroupVisible(!groupVisible);
|
||||||
groupVisible: !this.state.groupVisible
|
//callActions.fetchCalls();
|
||||||
});
|
|
||||||
this.props.callActions.fetchCalls();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleFilterClose(didUpdate) {
|
const handleFilterClose = (didUpdate) => {
|
||||||
this.setState({
|
setFilterVisible(!filterVisible);
|
||||||
filterVisible: !this.state.filterVisible
|
|
||||||
});
|
|
||||||
if (didUpdate) {
|
if (didUpdate) {
|
||||||
this.setState({ callUrl: "", callId: false });
|
setCallUrl("");
|
||||||
this.props.callActions.fetchCalls();
|
setCallId(false);
|
||||||
|
//callActions.fetchCalls();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
callEnded(data) {
|
callEnded(data) {
|
||||||
const audio = this.audioRef.current;
|
const audio = this.audioRef.current;
|
||||||
const currentIndex = this.props.callsAllIds.findIndex(callId => callId === this.state.callId);
|
const currentIndex = callsAllIds.findIndex(callId => callId === callId);
|
||||||
if (this.state.autoPlay && (currentIndex > 0)) {
|
if (autoPlay && (currentIndex > 0)) {
|
||||||
const nextCallId = this.props.callsAllIds[currentIndex - 1];
|
const nextCallId = callsAllIds[currentIndex - 1];
|
||||||
const nextCall = this.props.callsById[nextCallId];
|
const nextCall = callsById[nextCallId];
|
||||||
var callUrl = nextCall.url;
|
var callUrl = nextCall.url;
|
||||||
|
|
||||||
this.setState({ callUrl: callUrl, callId: nextCallId, isPlaying: true }, () => { audio.playSource(callUrl) }); //scrollToComponent(this.currentCallRef.current);
|
this.setState({ callUrl: callUrl, callId: nextCallId, isPlaying: true }, () => { audio.playSource(callUrl) }); //scrollToComponent(this.currentCallRef.current);
|
||||||
@@ -252,7 +258,7 @@ class CallPlayer extends React.Component {
|
|||||||
block: "center",
|
block: "center",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.props.callActions.fetchCallInfo(nextCallId);
|
callActions.fetchCallInfo(nextCallId);
|
||||||
} else {
|
} else {
|
||||||
this.setState({ isPlaying: false });
|
this.setState({ isPlaying: false });
|
||||||
}
|
}
|
||||||
@@ -266,7 +272,7 @@ class CallPlayer extends React.Component {
|
|||||||
callId: data.call._id,
|
callId: data.call._id,
|
||||||
isPlaying: true
|
isPlaying: true
|
||||||
}, () => { audio.playSource(callUrl); }); //scrollToComponent(this.currentCallRef.current);
|
}, () => { audio.playSource(callUrl); }); //scrollToComponent(this.currentCallRef.current);
|
||||||
this.props.callActions.fetchCallInfo(data.call._id);
|
callActions.fetchCallInfo(data.call._id);
|
||||||
}
|
}
|
||||||
|
|
||||||
addCall(data) {
|
addCall(data) {
|
||||||
@@ -274,9 +280,9 @@ class CallPlayer extends React.Component {
|
|||||||
switch (message.type) {
|
switch (message.type) {
|
||||||
case 'calls':
|
case 'calls':
|
||||||
const refs = this.refs.current;
|
const refs = this.refs.current;
|
||||||
this.props.callActions.addCall(message);
|
callActions.addCall(message);
|
||||||
const newCall = this.props.callsById[this.props.callsAllIds[0]];
|
const newCall = callsById[callsAllIds[0]];
|
||||||
if (!this.state.isPlaying && this.state.autoPlay) {
|
if (!isPlaying && autoPlay) {
|
||||||
this.playCall({ call: newCall });
|
this.playCall({ call: newCall });
|
||||||
if (this.currentCallRef.current) {
|
if (this.currentCallRef.current) {
|
||||||
this.currentCallRef.current.scrollIntoView({
|
this.currentCallRef.current.scrollIntoView({
|
||||||
@@ -289,14 +295,9 @@ class CallPlayer extends React.Component {
|
|||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
componentWillUnmount() {
|
|
||||||
this.endSocket();
|
const setStateFromUri = () => {
|
||||||
}
|
|
||||||
componentDidMount() {
|
|
||||||
//const parsed = queryString.parse(location.search);
|
|
||||||
//console.log(parsed);
|
|
||||||
this.props.callActions.setShortName(this.props.shortName);
|
|
||||||
var filter = {
|
var filter = {
|
||||||
filterDate: false,
|
filterDate: false,
|
||||||
filterType: 0, // this is "all"
|
filterType: 0, // this is "all"
|
||||||
@@ -305,7 +306,6 @@ class CallPlayer extends React.Component {
|
|||||||
filterStarred: false,
|
filterStarred: false,
|
||||||
live: true
|
live: true
|
||||||
};
|
};
|
||||||
const uri = queryString.parse(this.props.location.search);
|
|
||||||
|
|
||||||
// is there a star filter?
|
// is there a star filter?
|
||||||
if (uri.hasOwnProperty('starred')) {
|
if (uri.hasOwnProperty('starred')) {
|
||||||
@@ -335,10 +335,8 @@ class CallPlayer extends React.Component {
|
|||||||
callScroll: true,
|
callScroll: true,
|
||||||
callSelect: true
|
callSelect: true
|
||||||
});
|
});
|
||||||
this.props.callActions.fetchCallInfo(_id);
|
//callActions.fetchCallInfo(_id);
|
||||||
this.props.callActions.setCallTime(date);
|
//callActions.setCallTime(date);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -367,23 +365,31 @@ class CallPlayer extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.props.callActions.setFilter(filter);
|
//callActions.setFilter(filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
// When a time/date is provided in the URL, it will be added to the filter
|
// When a time/date is provided in the URL, it will be added to the filter
|
||||||
// When fetchCalls is called it will selected calls that are older
|
// When fetchCalls is called it will selected calls that are older
|
||||||
this.props.callActions.fetchCalls();
|
//callActions.fetchCalls();
|
||||||
this.props.talkgroupActions.fetchTalkgroups(this.props.shortName);
|
//talkgroupActions.fetchTalkgroups(shortName);
|
||||||
this.props.groupActions.fetchGroups(this.props.shortName);
|
//groupActions.fetchGroups(shortName);
|
||||||
|
//systemActions.fetchSystems();
|
||||||
|
/*this.setupSocket();
|
||||||
this.props.systemActions.fetchSystems();
|
|
||||||
this.setupSocket();
|
|
||||||
|
|
||||||
if (filter.live) {
|
if (filter.live) {
|
||||||
this.startSocket(this.props.shortName, filterType, filterCode, filter.filterStarred);
|
this.startSocket(shortName, filterType, filterCode, filter.filterStarred);
|
||||||
}
|
}*/
|
||||||
}
|
dispatch(setShortName(shortName));
|
||||||
compareArray(a1, a2) {
|
return () => {
|
||||||
|
//this.endSocket();
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const compareArray = (a1, a2) => {
|
||||||
var i = a1.length;
|
var i = a1.length;
|
||||||
while (i--) {
|
while (i--) {
|
||||||
if (a1[i] !== a2[i])
|
if (a1[i] !== a2[i])
|
||||||
@@ -392,62 +398,60 @@ class CallPlayer extends React.Component {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect( () => {
|
||||||
|
if (!urlOptions && groupsData && (groupsData.length > 0)) {
|
||||||
|
setGroupVisible(true);
|
||||||
|
}
|
||||||
|
},[groupsData] )
|
||||||
|
|
||||||
|
useEffect( () => {
|
||||||
|
/*var typeString = 'all';
|
||||||
|
var filterCode = '';
|
||||||
|
switch (nextProps.filterType) {
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
typeString = 'group';
|
||||||
|
filterCode = nextProps.filterGroupId;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
typeString = 'talkgroup';
|
||||||
|
filterCode = nextProps.filterTalkgroups;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
case 0:
|
||||||
|
typeString = "all";
|
||||||
|
filterCode = '';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateUri(nextProps, nextState);
|
||||||
|
if (live) {
|
||||||
|
this.startSocket(shortName, typeString, filterCode, nextProps.filterStarred);
|
||||||
|
}*/
|
||||||
|
}, [filterType,filterTalkgroups,filterGroupId,filterStarred,filterDate])
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
componentWillUpdate(nextProps, nextState) {
|
componentWillUpdate(nextProps, nextState) {
|
||||||
if (!this.props.groups && nextProps.groups) {
|
|
||||||
if (!this.state.urlOptions && (nextProps.groups.length > 0)) {
|
|
||||||
this.setState({
|
|
||||||
groupVisible: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const filterChanged = (nextProps.filterType !== this.props.filterType) || !this.compareArray(nextProps.filterTalkgroups, this.props.filterTalkgroups) || (nextProps.filterGroupId !== this.props.filterGroupId) || (nextProps.filterDate !== this.props.filterDate) || (nextProps.filterStarred !== this.props.filterStarred);
|
|
||||||
if (filterChanged) {
|
|
||||||
var typeString = 'all';
|
|
||||||
var filterCode = '';
|
|
||||||
switch (nextProps.filterType) {
|
|
||||||
|
|
||||||
case 1:
|
const callsChanged = nextProps.callsAllIds[0] !== callsAllIds[0];
|
||||||
typeString = 'group';
|
|
||||||
filterCode = nextProps.filterGroupId;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
typeString = 'talkgroup';
|
|
||||||
filterCode = nextProps.filterTalkgroups;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
case 0:
|
|
||||||
typeString = "all";
|
|
||||||
filterCode = '';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.updateUri(nextProps, nextState);
|
|
||||||
if (this.props.live) {
|
|
||||||
this.startSocket(this.props.shortName, typeString, filterCode, nextProps.filterStarred);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const callsChanged = nextProps.callsAllIds[0] !== this.props.callsAllIds[0];
|
|
||||||
if (callsChanged) {
|
if (callsChanged) {
|
||||||
const { contextRef } = this.state;
|
const { contextRef } = this.state;
|
||||||
this.scrollPos = contextRef.scrollTop;
|
this.scrollPos = contextRef.scrollTop;
|
||||||
this.prevHeight = contextRef.clientHeight;
|
this.prevHeight = contextRef.clientHeight;
|
||||||
this.autoScroll = true;
|
this.autoScroll = true;
|
||||||
}
|
}
|
||||||
/* // if you do this, you also need to update time in the URI to be the call time...
|
|
||||||
if (this.state.callId != nextState.callId) {
|
|
||||||
this.updateUri(nextProps, nextState);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (this.state.callId && !this.state.callUrl) {
|
|
||||||
const call = this.props.callsById[this.state.callId];
|
if (callId && !callUrl) {
|
||||||
|
const call = callsById[callId];
|
||||||
if (call) {
|
if (call) {
|
||||||
this.setState({ callUrl: call.url });
|
this.setState({ callUrl: call.url });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
/*
|
||||||
componentDidUpdate(prevProps, prevState) {
|
componentDidUpdate(prevProps, prevState) {
|
||||||
const { contextRef } = this.state
|
const { contextRef } = this.state
|
||||||
//console.log( contextRef.clientHeight - this.prevHeight );
|
//console.log( contextRef.clientHeight - this.prevHeight );
|
||||||
@@ -457,8 +461,8 @@ class CallPlayer extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// scroll to a call once the calls have loaded
|
// scroll to a call once the calls have loaded
|
||||||
if (this.state.callScroll && (this.props.callsAllIds.length > prevProps.callsAllIds.length)) {
|
if (callScroll && (callsAllIds.length > prevProps.callsAllIds.length)) {
|
||||||
const call = this.props.callsById[this.state.callId];
|
const call = callsById[callId];
|
||||||
if (call) {
|
if (call) {
|
||||||
this.setState({ callScroll: false });
|
this.setState({ callScroll: false });
|
||||||
if (this.currentCallRef.current) {
|
if (this.currentCallRef.current) {
|
||||||
@@ -472,8 +476,8 @@ class CallPlayer extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.state.callSelect) {
|
if (callSelect) {
|
||||||
const call = this.props.callsById[this.state.callId];
|
const call = callsById[callId];
|
||||||
if (call) {
|
if (call) {
|
||||||
const audio = this.audioRef.current;
|
const audio = this.audioRef.current;
|
||||||
var callUrl = call.url;
|
var callUrl = call.url;
|
||||||
@@ -484,37 +488,40 @@ class CallPlayer extends React.Component {
|
|||||||
}, () => { audio.playSource(callUrl); }); //scrollToComponent(this.currentCallRef.current);
|
}, () => { audio.playSource(callUrl); }); //scrollToComponent(this.currentCallRef.current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
//https://stackoverflow.com/questions/36559661/how-can-i-dispatch-from-child-components-in-react-redux
|
//https://stackoverflow.com/questions/36559661/how-can-i-dispatch-from-child-components-in-react-redux
|
||||||
//https://stackoverflow.com/questions/42597602/react-onclick-pass-event-with-parameter
|
//https://stackoverflow.com/questions/42597602/react-onclick-pass-event-with-parameter
|
||||||
render() {
|
|
||||||
const { contextRef } = this.state
|
//const { contextRef } = this.state
|
||||||
const { sidebarOpened } = this.state
|
|
||||||
var archiveLabel = "";
|
var archiveLabel = "";
|
||||||
if (this.props.filterDate) {
|
if (filterDate) {
|
||||||
const filterDate = new Date(this.props.filterDate);
|
const filterDate = new Date(filterDate);
|
||||||
archiveLabel = filterDate.toLocaleDateString() + " " + filterDate.toLocaleTimeString()
|
archiveLabel = filterDate.toLocaleDateString() + " " + filterDate.toLocaleTimeString()
|
||||||
}
|
}
|
||||||
|
|
||||||
var callInfoHeader = "Call Info";
|
var callInfoHeader = "Call Info";
|
||||||
|
|
||||||
const currentCall = this.props.callsById[this.state.callId];
|
const currentCall = false;//callsById[callId];
|
||||||
|
|
||||||
|
|
||||||
|
var callsAllIds = [];
|
||||||
|
var callsById = false;
|
||||||
var callLink = ""
|
var callLink = ""
|
||||||
var callDownload = ""
|
var callDownload = ""
|
||||||
if (currentCall) {
|
if (currentCall) {
|
||||||
if ((this.props.talkgroups) && this.props.talkgroups[currentCall.talkgroupNum]) {
|
if ((talkgroupsData) && talkgroupsData[currentCall.talkgroupNum]) {
|
||||||
callInfoHeader = this.props.talkgroups[currentCall.talkgroupNum].description;
|
callInfoHeader = talkgroupsData[currentCall.talkgroupNum].description;
|
||||||
}
|
}
|
||||||
const callDate = new Date(currentCall.time);
|
const callDate = new Date(currentCall.time);
|
||||||
callLink = "/system/" + this.props.shortName + "?call-id=" + currentCall._id + "&time=" + (callDate.getTime() + 1);
|
callLink = "/system/" + shortName + "?call-id=" + currentCall._id + "&time=" + (callDate.getTime() + 1);
|
||||||
callDownload = currentCall.url;
|
callDownload = currentCall.url;
|
||||||
}
|
}
|
||||||
var archive = process.env.REACT_APP_ARCHIVE_DAYS
|
var archive = process.env.REACT_APP_ARCHIVE_DAYS
|
||||||
|
|
||||||
var filterLabel = "All"
|
var filterLabel = "All"
|
||||||
switch (this.props.filterType) {
|
switch (filterType) {
|
||||||
case 1:
|
case 1:
|
||||||
filterLabel = "Group"
|
filterLabel = "Group"
|
||||||
break;
|
break;
|
||||||
@@ -526,41 +533,39 @@ class CallPlayer extends React.Component {
|
|||||||
case 0:
|
case 0:
|
||||||
filterLabel = "All"
|
filterLabel = "All"
|
||||||
}
|
}
|
||||||
/* if (this.props.calls) {
|
/* if (calls) {
|
||||||
var callRows = calls.map((call) =>
|
var callRows = calls.map((call) =>
|
||||||
<CallItem call={call} key={call.shortName}/>
|
<CallItem call={call} key={call.shortName}/>
|
||||||
))
|
))
|
||||||
}*/
|
}*/
|
||||||
return (
|
return (
|
||||||
<div ref={this.handleContextRef}>
|
<div >
|
||||||
<FilterModal shortName={this.props.shortName} open={this.state.filterVisible} onClose={this.handleFilterClose} />
|
<FilterModal shortName={shortName} open={filterVisible} onClose={handleFilterClose} />
|
||||||
<CalendarModal open={this.state.calendarVisible} onClose={this.handleCalendarClose} archive={archive} key={this.props.shortName} />
|
<CalendarModal open={calendarVisible} onClose={handleCalendarClose} archive={archive} key={shortName} />
|
||||||
<GroupModal shortName={this.props.shortName} open={this.state.groupVisible} onClose={this.handleGroupClose} />
|
<GroupModal shortName={shortName} open={groupVisible} onClose={handleGroupClose} />
|
||||||
|
|
||||||
<Sidebar as={Menu} animation='overlay' inverted vertical visible={sidebarOpened}
|
<Sidebar as={Menu} animation='overlay' inverted vertical visible={sidebarOpened}
|
||||||
onClick={this.handlePusherClick} duration={50} width='thin'>
|
onClick={handlePusherClick} duration={50} width='thin'>
|
||||||
<Menu.Item onClick={this.handlePusherClick} >
|
<Menu.Item onClick={handlePusherClick} >
|
||||||
<span> </span><Icon name="close" inverted={true} link={true} size='small' /></Menu.Item>
|
<span> </span><Icon name="close" inverted={true} link={true} size='small' /></Menu.Item>
|
||||||
<Link to="/"><Menu.Item link>Home</Menu.Item></Link>
|
<Link to="/"><Menu.Item link>Home</Menu.Item></Link>
|
||||||
<Link to="/systems"><Menu.Item link>Systems</Menu.Item></Link>
|
<Link to="/systems"><Menu.Item link>Systems</Menu.Item></Link>
|
||||||
<Link to="/about"><Menu.Item link>About</Menu.Item></Link>
|
<Link to="/about"><Menu.Item link>About</Menu.Item></Link>
|
||||||
<Menu.Item link><Groups shortName={this.props.shortName}/></Menu.Item>
|
|
||||||
<Menu.Item link><Calls shortName={this.props.shortName}/></Menu.Item>
|
|
||||||
</Sidebar>
|
</Sidebar>
|
||||||
<Menu fixed="top">
|
<Menu fixed="top">
|
||||||
<Menu.Item onClick={this.handleSidebarToggle}>
|
<Menu.Item onClick={handleSidebarToggle}>
|
||||||
<Icon name='sidebar' />
|
<Icon name='sidebar' />
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
<Menu.Item name='filter-btn' onClick={this.handleFilterToggle}>
|
<Menu.Item name='filter-btn' onClick={handleFilterToggle}>
|
||||||
<Icon name="filter" />
|
<Icon name="filter" />
|
||||||
<span className="desktop-only">Filter</span>
|
<span className="desktop-only">Filter</span>
|
||||||
<Label horizontal={true} color="grey" className="desktop-only">{filterLabel}</Label>
|
<Label horizontal={true} color="grey" className="desktop-only">{filterLabel}</Label>
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
<Container className="desktop-only" textAlign='center' style={{ fontSize: '1.5rem', paddingLeft: '1em', paddingTop: '.5em' }}>
|
<Container className="desktop-only" textAlign='center' style={{ fontSize: '1.5rem', paddingLeft: '1em', paddingTop: '.5em' }}>
|
||||||
{this.props.system && this.props.system.name}
|
{/*system && system.name*/}
|
||||||
</Container>
|
</Container>
|
||||||
<Menu.Menu position="right">
|
<Menu.Menu position="right">
|
||||||
<Menu.Item name='archive-btn' onClick={this.handleCalendarToggle} active={!this.props.live}>
|
<Menu.Item name='archive-btn' onClick={handleCalendarToggle} active={!live}>
|
||||||
<Icon name="calendar" />
|
<Icon name="calendar" />
|
||||||
<span className="desktop-only">
|
<span className="desktop-only">
|
||||||
{
|
{
|
||||||
@@ -570,7 +575,7 @@ class CallPlayer extends React.Component {
|
|||||||
}
|
}
|
||||||
</span>
|
</span>
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
<Menu.Item name='live-btn' onClick={this.handleLiveToggle} active={this.props.live}>
|
<Menu.Item name='live-btn' onClick={handleLiveToggle} active={live}>
|
||||||
<Icon name="unmute" />
|
<Icon name="unmute" />
|
||||||
<span className="desktop-only">Live</span>
|
<span className="desktop-only">Live</span>
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
@@ -583,24 +588,24 @@ class CallPlayer extends React.Component {
|
|||||||
<Container className="main">
|
<Container className="main">
|
||||||
<Sidebar.Pushable>
|
<Sidebar.Pushable>
|
||||||
<Sidebar.Pusher
|
<Sidebar.Pusher
|
||||||
onClick={this.handlePusherClick}
|
onClick={handlePusherClick}
|
||||||
style={{ minHeight: '100vh' }}
|
style={{ minHeight: '100vh' }}
|
||||||
>
|
>
|
||||||
<Visibility onTopVisible={this.loadNewerCalls} onBottomVisible={this.loadOlderCalls} once={false}>
|
<Visibility onTopVisible={loadNewerCalls} onBottomVisible={loadOlderCalls} once={false}>
|
||||||
<ListCalls callsAllIds={this.props.callsAllIds} currentCallRef={this.currentCallRef} callsById={this.props.callsById} activeCallId={this.state.callId} talkgroups={this.props.talkgroups} playCall={this.playCall} />
|
{/* <ListCalls callsAllIds={callsAllIds} currentCallRef={false} callsById={callsById} activeCallId={callId} talkgroups={talkgroupsData} playCall={playCall} /> */}
|
||||||
</Visibility>
|
</Visibility>
|
||||||
</Sidebar.Pusher>
|
</Sidebar.Pusher>
|
||||||
</Sidebar.Pushable>
|
</Sidebar.Pushable>
|
||||||
<Rail position='right' className="desktop-only" dimmed={sidebarOpened ? "true" : "false"} >
|
<Rail position='right' className="desktop-only" dimmed={sidebarOpened ? "true" : "false"} >
|
||||||
<Sticky context={contextRef} offset={60}>
|
<Sticky offset={60}>
|
||||||
<CallInfo call={currentCall} header={callInfoHeader} link={callLink}/>
|
<CallInfo call={currentCall} header={callInfoHeader} link={callLink}/>
|
||||||
</Sticky>
|
</Sticky>
|
||||||
</Rail>
|
</Rail>
|
||||||
</Container>
|
</Container>
|
||||||
|
|
||||||
<Menu fixed="bottom" compact inverted >
|
<Menu fixed="bottom" compact inverted >
|
||||||
<Menu.Item active={this.state.autoPlay} onClick={() => this.switchAutoPlay()}><Icon name="level up" /><span className="desktop-only">Autoplay</span></Menu.Item>
|
<Menu.Item active={autoPlay} onClick={() => this.switchAutoPlay()}><Icon name="level up" /><span className="desktop-only">Autoplay</span></Menu.Item>
|
||||||
<MediaPlayer ref={this.audioRef} call={currentCall} onEnded={this.callEnded} onPlayPause={this.handlePlayPause} />
|
{ /*<MediaPlayer ref={audioRef} call={currentCall} onEnded={callEnded} onPlayPause={handlePlayPause} /> */ }
|
||||||
<Menu.Menu position="right" className="desktop-only">
|
<Menu.Menu position="right" className="desktop-only">
|
||||||
<Menu.Item><SupportModal/></Menu.Item>
|
<Menu.Item><SupportModal/></Menu.Item>
|
||||||
<Menu.Item><a href={callDownload}><Icon name="download" />Download</a></Menu.Item>
|
<Menu.Item><a href={callDownload}><Icon name="download" />Download</a></Menu.Item>
|
||||||
@@ -616,6 +621,6 @@ class CallPlayer extends React.Component {
|
|||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export default CallPlayer;
|
export default CallPlayer;
|
||||||
|
|||||||
@@ -25,14 +25,7 @@ export const apiSlice = createApi({
|
|||||||
// The URL for the request is '/fakeApi/posts'
|
// The URL for the request is '/fakeApi/posts'
|
||||||
query: (shortName) => ({ url: `/${shortName}/talkgroups` })
|
query: (shortName) => ({ url: `/${shortName}/talkgroups` })
|
||||||
}),
|
}),
|
||||||
getCalls: builder.query({
|
|
||||||
// The URL for the request is '/fakeApi/posts'
|
|
||||||
query: ({shortName,filterType=0,filterCode=0}) => ({
|
|
||||||
url: `/${shortName}/calls`,
|
|
||||||
method: "GET",
|
|
||||||
params: { filterType, filterCode },
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
48
frontend/src/features/calls/callsSlice.js
Normal file
48
frontend/src/features/calls/callsSlice.js
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import {
|
||||||
|
createSlice,
|
||||||
|
createEntityAdapter,
|
||||||
|
createSelector
|
||||||
|
} from '@reduxjs/toolkit'
|
||||||
|
|
||||||
|
import { apiSlice } from '../api/apiSlice'
|
||||||
|
|
||||||
|
const callsAdapter = createEntityAdapter({
|
||||||
|
selectId: (call) => call._id,
|
||||||
|
sortComparer: (a, b) => a.time.localeCompare(b.time),
|
||||||
|
})
|
||||||
|
|
||||||
|
const initialState = callsAdapter.getInitialState()
|
||||||
|
|
||||||
|
export const extendedApiSlice = apiSlice.injectEndpoints({
|
||||||
|
endpoints: builder => ({
|
||||||
|
getCalls: builder.query({
|
||||||
|
query: ({shortName,filterType=0,filterCode=0}) => ({
|
||||||
|
url: `/${shortName}/calls`,
|
||||||
|
method: "GET",
|
||||||
|
params: { filterType, filterCode },
|
||||||
|
}),
|
||||||
|
transformResponse: responseData => {
|
||||||
|
responseData = responseData.calls;
|
||||||
|
return callsAdapter.setAll(initialState, responseData)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
export const { useGetCallsQuery } = extendedApiSlice
|
||||||
|
|
||||||
|
|
||||||
|
// 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 selectCallsResult = extendedApiSlice.endpoints.getCalls.select()
|
||||||
|
|
||||||
|
|
||||||
|
export const selectCallsData = createSelector(
|
||||||
|
selectCallsResult,
|
||||||
|
callsResult => callsResult.data
|
||||||
|
)
|
||||||
|
|
||||||
|
export const { selectAll: selectAllCalls, selectById: selectCallById } =
|
||||||
|
callsAdapter.getSelectors(state => selectCallsData(state) ?? initialState)
|
||||||
@@ -17,7 +17,7 @@ import MainContainer from "./Main/MainContainer"
|
|||||||
import ListSystemsContainer from "./System/ListSystemsContainer"
|
import ListSystemsContainer from "./System/ListSystemsContainer"
|
||||||
|
|
||||||
// Call
|
// Call
|
||||||
import CallPlayerContainer from "./Call/CallPlayerContainer"
|
import CallPlayer from "./Call/CallPlayer"
|
||||||
|
|
||||||
import AboutComponent from "./About/AboutComponent"
|
import AboutComponent from "./About/AboutComponent"
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ root.render(
|
|||||||
<Routes>
|
<Routes>
|
||||||
<Route exact path="/" element={<MainContainer/>} />
|
<Route exact path="/" element={<MainContainer/>} />
|
||||||
<Route exact path="/systems" element={<ListSystemsContainer/>} />
|
<Route exact path="/systems" element={<ListSystemsContainer/>} />
|
||||||
<Route exact path="/system/:shortName" element={<CallPlayerContainer/>} />
|
<Route exact path="/system/:shortName" element={<CallPlayer/>} />
|
||||||
<Route exact path="/about" element={<AboutComponent/>} />
|
<Route exact path="/about" element={<AboutComponent/>} />
|
||||||
|
|
||||||
</Routes>
|
</Routes>
|
||||||
|
|||||||
Reference in New Issue
Block a user