cleans up the group modal and the center call

This commit is contained in:
Luke Berndt
2023-02-01 22:19:53 -05:00
parent 4b4d21df23
commit a91f981bf8
5 changed files with 81 additions and 35 deletions

View File

@@ -134,7 +134,7 @@ function CallPlayer(props) {
style={{ minHeight: '100vh' }} style={{ minHeight: '100vh' }}
> >
<div ref={loadNewerRef} /> <div ref={loadNewerRef} />
<ListCalls callsData={callsData} activeCallId={isPlaying ? currentCallId : false} talkgroups={talkgroupsData ? talkgroupsData.talkgroups : false} playCall={playCall} /> <ListCalls callsData={callsData} activeCallId={currentCallId} talkgroups={talkgroupsData ? talkgroupsData.talkgroups : false} playCall={playCall} />
<div ref={loadOlderRef} style={{ height: 50 }} /> <div ref={loadOlderRef} style={{ height: 50 }} />
</Sidebar.Pusher> </Sidebar.Pusher>
</Sidebar.Pushable> </Sidebar.Pushable>

View File

@@ -90,12 +90,18 @@ const CallItem = (props) => {
talkgroup = talkgroups.talkgroups[call.talkgroupNum].description; talkgroup = talkgroups.talkgroups[call.talkgroupNum].description;
} }
const cirlceStyle = {width:"4px",
margin:"6px",
height: "4px",
borderRadius:"50%",
background: "#09f"}
let playStatus = (<></>) let playStatus = (<></>)
if (activeCall) { if (activeCall) {
playStatus = (<Icon name="play" size='small' color="green"/>) playStatus = (<Icon name="play" size='small' color="green"/>)
} else if (!call.played) { } else if (!call.played) {
playStatus = (<Icon name="chevron right" size='small' disabled/>) playStatus = (<div style={cirlceStyle}/>)
} }
return ( return (

View File

@@ -1,66 +1,99 @@
import React, { Component, useState } from "react"; import React, { Component, useState, useEffect } from "react";
import { useGetGroupsQuery } from '../../features/api/apiSlice' import { useGetGroupsQuery, useGetSystemsQuery, } from '../../features/api/apiSlice'
import { setGroupFilter } from "../../features/callPlayer/callPlayerSlice"; import { setGroupFilter, setCenterCall } from "../../features/callPlayer/callPlayerSlice";
import { useSelector, useDispatch } from 'react-redux' import { useSelector, useDispatch } from 'react-redux'
import { import {
Modal, Modal,
Button, Button,
Icon, Icon,
Dropdown Dropdown,
Grid,
Form
} from "semantic-ui-react"; } from "semantic-ui-react";
import "./FilterModal.css"; import "./FilterModal.css";
function GroupModal (props) { function GroupModal(props) {
const shortName = useSelector((state) => state.callPlayer.shortName); const shortName = useSelector((state) => state.callPlayer.shortName);
const { data, isError, isLoading, isSuccess,error } = useGetGroupsQuery(props.shortName); const { data: groupData, isSuccess } = useGetGroupsQuery(props.shortName);
const { data: allSystems } = useGetSystemsQuery();
const [selectedGroup, setSelectedGroup] = useState(false); const [selectedGroup, setSelectedGroup] = useState(false);
const [groupOptions, setGroupOptions] = useState([]);
const [centerCall, setLocalCenterCall] = useState(true);
const dispatch = useDispatch() const dispatch = useDispatch()
const onClose = props.onClose; const onClose = props.onClose;
let system = false;
if (allSystems) {
system = allSystems.systems.find((system) => system.shortName === shortName)
}
function handleDone(onClose) { function handleDone(onClose) {
dispatch(setCenterCall(centerCall));
if (selectedGroup) { if (selectedGroup && (selectedGroup!="all")) {
dispatch(setGroupFilter(selectedGroup)) dispatch(setGroupFilter(selectedGroup))
//dispatch({type: types.SET_GROUP_FILTER, groupId: selectedGroup }) //dispatch({type: types.SET_GROUP_FILTER, groupId: selectedGroup })
onClose(true); onClose(true);
} else { } else {
onClose(false); onClose(false);
} }
} }
let groupOptions = [] useEffect(() => {
if (isSuccess) {
if (isSuccess) { let temp = [{
key: "all",
for (const num in data) { value: "all",
const group = data[num]; text: "All Calls"
const obj = { }];
key: group._id, for (const num in groupData) {
value: group._id, const group = groupData[num];
text: group.groupName const obj = {
key: group._id,
value: group._id,
text: group.groupName
}
temp.push(obj);
} }
groupOptions.push(obj); setGroupOptions(temp);
} }
} }, [groupData]);
return ( return (
<Modal open={props.open} onClose={onClose} size='tiny'> <Modal open={props.open} onClose={onClose} size='tiny'>
<Modal.Header>Select a Group</Modal.Header> <Modal.Header>{system && system.name}</Modal.Header>
<Modal.Content > <Modal.Content >
<Modal.Description> <Modal.Description>
<p>Choose the type of calls you want to listen to</p>
<Dropdown placeholder='Group...' fluid selection options={groupOptions} name='selectedGroup' onChange={(e, data) => setSelectedGroup(data.value)} /> <Grid >
<Grid.Row>
<Grid.Column width={8}>
{system && system.description}
</Grid.Column>
<Grid.Column width={8}>
<p>Choose the type of calls you want to listen to</p>
<Form>
<Form.Select placeholder='All Calls' fluid selection options={groupOptions} name='selectedGroup' onChange={(e, data) => setSelectedGroup(data.value)} />
<Form.Checkbox label='Center playing call ' checked={centerCall} onChange={(e, data) => setLocalCenterCall(data.value)} />
</Form>
</Grid.Column>
</Grid.Row>
</Grid>
</Modal.Description> </Modal.Description>
</Modal.Content> </Modal.Content>
<Modal.Actions> <Modal.Actions>
<Button onClick={()=> handleDone(onClose)} > <Button onClick={() => handleDone(onClose)} >
<Icon name='headphones' /> Listen <Icon name='headphones' /> Listen
</Button> </Button>
</Modal.Actions> </Modal.Actions>

View File

@@ -8,24 +8,27 @@ import {
} from "semantic-ui-react"; } from "semantic-ui-react";
import "../CallPlayer.css"; import "../CallPlayer.css";
import { useGetTalkgroupsQuery } from '../../features/api/apiSlice' import { useGetTalkgroupsQuery } from '../../features/api/apiSlice'
import { useSelector } from 'react-redux'
// ---------------------------------------------------- // ----------------------------------------------------
const ListCalls = (props) => { const ListCalls = (props) => {
const activeCallRef = useRef(); const activeCallRef = useRef();
const activeCallId = props.activeCallId;
const { shortName } = useParams(); const { shortName } = useParams();
const centerCall = useSelector((state) => state.callPlayer.centerCall);
const { data: talkgroupsData, isSuccess: isTalkgroupsSuccess } = useGetTalkgroupsQuery(shortName); const { data: talkgroupsData, isSuccess: isTalkgroupsSuccess } = useGetTalkgroupsQuery(shortName);
//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
/*
useEffect(() => { useEffect(() => {
if (activeCallRef.current) { if (activeCallRef.current && centerCall) {
activeCallRef.current.scrollIntoView({ activeCallRef.current.scrollIntoView({
block: "center", block: "center",
}); });
} }
});*/ },[activeCallId]);
const callsData = props.callsData; const callsData = props.callsData;
return ( return (
@@ -45,7 +48,7 @@ const ListCalls = (props) => {
{ {
props.callsData.ids.map((callId, index) => { props.callsData.ids.map((callId, index) => {
if (callId === props.activeCallId) { if (callId === activeCallId) {
return (<Ref innerRef={activeCallRef} key={index} ><CallItem activeCall={true} call={props.callsData.entities[callId]} talkgroups={talkgroupsData} key={index} onClick={props.playCall}/></Ref>) return (<Ref innerRef={activeCallRef} key={index} ><CallItem activeCall={true} call={props.callsData.entities[callId]} talkgroups={talkgroupsData} key={index} onClick={props.playCall}/></Ref>)
} else { } else {
return <CallItem activeCall={false} call={props.callsData.entities[callId]} talkgroups={talkgroupsData} key={index} onClick={props.playCall}/> return <CallItem activeCall={false} call={props.callsData.entities[callId]} talkgroups={talkgroupsData} key={index} onClick={props.playCall}/>

View File

@@ -14,7 +14,8 @@ const initialState = {
filterStarred: false, filterStarred: false,
currentCallId: false, currentCallId: false,
playlist: [], playlist: [],
live: false live: false,
centerCall: true
} }
const compareCalls = (a, b) => { const compareCalls = (a, b) => {
@@ -73,6 +74,9 @@ export const callPlayerSlice = createSlice({
setLive: (state,action) => { setLive: (state,action) => {
state.live = action.payload; state.live = action.payload;
}, },
setCenterCall: (state,action) => {
state.centerCall = action.payload;
},
setShortName: (state, action) => { setShortName: (state, action) => {
state.shortName = action.payload; state.shortName = action.payload;
}, },
@@ -102,7 +106,7 @@ export const callPlayerSlice = createSlice({
}) })
// Action creators are generated for each case reducer function // Action creators are generated for each case reducer function
export const { setCurrentCallId, setCallTime, setFilter, setLive, setPlaylist, removeFromPLaylist, addToPlaylist, setShortName, setDateFilter, setStarredFilter, setAllFilter, setGroupFilter, setTalkgroupFilter } = callPlayerSlice.actions export const { setCurrentCallId, setCallTime, setFilter, setLive, setCenterCall, setPlaylist, removeFromPLaylist, addToPlaylist, setShortName, setDateFilter, setStarredFilter, setAllFilter, setGroupFilter, setTalkgroupFilter } = callPlayerSlice.actions
export default callPlayerSlice.reducer export default callPlayerSlice.reducer