Call Info and Cal Modals converted

This commit is contained in:
Luke Berndt
2023-01-05 21:17:13 -05:00
parent 271ecee5d5
commit 9205224f23
2 changed files with 63 additions and 71 deletions

View File

@@ -1,70 +1,64 @@
import React, { Component } from "react"; import React, { Component, useState } from "react";
import { import {
Modal, Modal,
Button, Button,
Icon Icon
} from "semantic-ui-react"; } from "semantic-ui-react";
import "./CalendarModal.css"; import "./CalendarModal.css";
import { setDateFilter } from "../features/callPlayer/callPlayerSlice";
import DatePicker from 'react-datepicker'; import DatePicker from 'react-datepicker';
import { subDays } from 'date-fns' import { useDispatch } from 'react-redux'
import { setDate, subDays } from 'date-fns'
import 'react-datepicker/dist/react-datepicker.css'; import 'react-datepicker/dist/react-datepicker.css';
class CalendarModal extends Component { function CalendarModal(props) {
constructor(props) {
super(props)
this.handleDateChange = this.handleDateChange.bind(this);
this.handleDone = this.handleDone.bind(this);
this.handleClose = this.handleClose.bind(this);
this.state = { const [open, setOpen] = useState(false);
open: false, const [startDate, setStartDate] = useState(new Date());
startDate: new Date() const dispatch = useDispatch()
} const onClose = props.onClose;
}
handleDateChange = (date) => { const handleDateChange = (date) => {
this.setState({ setStartDate(date);
startDate: date
});
} }
handleClose = () => this.props.onClose(false); const handleClose = () => this.props.onClose(false);
handleDone(event) { const handleDone = (onClose) => {
this.props.callActions.setDateFilter(this.state.startDate.getTime()); dispatch(setDateFilter(startDate.getTime()));
this.props.onClose(true); onClose(true);
}
render() {
return (
<Modal open={this.props.open} onClose={this.handleClose} centered={false} size="tiny">
<Modal.Header>Select a Date & Time</Modal.Header>
<Modal.Content >
<Modal.Description>
<DatePicker
selected={this.state.startDate}
onChange={this.handleDateChange}
maxDate={new Date()}
minDate={subDays(new Date(), process.env.REACT_APP_ARCHIVE_DAYS)}
showTimeSelect
timeFormat="HH:mm"
timeIntervals={15}
dateFormat="LLL"
inline
/>
</Modal.Description>
</Modal.Content>
<Modal.Actions>
<Button onClick={this.handleDone} >
<Icon name='checkmark' /> Done
</Button>
</Modal.Actions>
</Modal>
)
} }
return (
<Modal open={props.open} onClose={handleClose} centered={false} size="tiny">
<Modal.Header>Select a Date & Time</Modal.Header>
<Modal.Content >
<Modal.Description>
<DatePicker
selected={startDate}
onChange={handleDateChange}
maxDate={new Date()}
minDate={subDays(new Date(), process.env.REACT_APP_ARCHIVE_DAYS)}
showTimeSelect
timeFormat="HH:mm"
timeIntervals={15}
dateFormat="LLL"
inline
/>
</Modal.Description>
</Modal.Content>
<Modal.Actions>
<Button onClick={()=>handleDone(onClose)} >
<Icon name='checkmark' /> Done
</Button>
</Modal.Actions>
</Modal>
)
} }
export default CalendarModal; export default CalendarModal;

View File

@@ -11,20 +11,19 @@ import {
} from "semantic-ui-react"; } from "semantic-ui-react";
// ---------------------------------------------------- // ----------------------------------------------------
class CallInfo extends React.Component { function CallInfo(props) {
render() { let srcList = "";
var srcList = ""; let callLength = "-";
var callLength = "-"; let callFreq = "-";
var callFreq = "-"; let callDate = "-";
var callDate = "-"; let callTime = "-";
var callTime = "-"; let talkgroupNum = "-";
var talkgroupNum = "-"; let callDownload = "";
var callDownload = ""; let callTweet = "";
var callTweet = ""; if (props.call) {
if (this.props.call) { const currentCall = props.call;
const currentCall = this.props.call;
var time = new Date(currentCall.time); var time = new Date(currentCall.time);
callTime = time.toLocaleTimeString(); callTime = time.toLocaleTimeString();
callDate = time.toLocaleDateString(); callDate = time.toLocaleDateString();
@@ -33,12 +32,11 @@ class CallInfo extends React.Component {
callFreq = Math.round(freq * 1000) / 1000; callFreq = Math.round(freq * 1000) / 1000;
} }
srcList = currentCall.srcList.map((source, index) => <List.Item key={index}>{source.src} srcList = currentCall.srcList.map((source, index) => <List.Item key={index}>{source.src}[{source.pos}]</List.Item>);
[{source.pos}]</List.Item>);
callLength = currentCall.len; callLength = currentCall.len;
talkgroupNum = currentCall.talkgroupNum; talkgroupNum = currentCall.talkgroupNum;
callDownload = currentCall.url; callDownload = currentCall.url;
callTweet = "https://twitter.com/intent/tweet?url="+encodeURIComponent(document.location.origin+this.props.link)+"&via="+encodeURIComponent("OpenMHz"); callTweet = "https://twitter.com/intent/tweet?url="+encodeURIComponent(document.location.origin+props.link)+"&via="+encodeURIComponent("OpenMHz");
} }
@@ -46,7 +44,7 @@ class CallInfo extends React.Component {
return ( return (
<div> <div>
<Segment padded attached> <Segment padded attached>
<Header as='h1'>{this.props.header}</Header> <Header as='h1'>{props.header}</Header>
<List bulleted horizontal link> <List bulleted horizontal link>
{srcList} {srcList}
</List> </List>
@@ -84,11 +82,11 @@ class CallInfo extends React.Component {
<Menu attached='bottom'> <Menu attached='bottom'>
<a href={callTweet}><Menu.Item name="tweet" ><Icon name='twitter' />Tweet</Menu.Item></a> <a href={callTweet}><Menu.Item name="tweet" ><Icon name='twitter' />Tweet</Menu.Item></a>
<a href={callDownload}><Menu.Item name="download"><Icon name="download" />Download</Menu.Item></a> <a href={callDownload}><Menu.Item name="download"><Icon name="download" />Download</Menu.Item></a>
<a href={this.props.link}><Menu.Item name="link"><Icon name="at" />Link</Menu.Item></a> <a href={props.link}><Menu.Item name="link"><Icon name="at" />Link</Menu.Item></a>
</Menu> </Menu>
</div> </div>
); );
}
} }
export default CallInfo; export default CallInfo;