From 033c3dcf5d88be3da873ef00eb6d9f43b5cdad3a Mon Sep 17 00:00:00 2001 From: Luke Berndt Date: Sat, 21 Jan 2023 10:29:23 -0500 Subject: [PATCH] Sending network traffic! --- .../src/Call/components/PlaylistBuilder.js | 142 ++++++++++++++++-- frontend/src/features/api/apiSlice.js | 9 +- 2 files changed, 135 insertions(+), 16 deletions(-) diff --git a/frontend/src/Call/components/PlaylistBuilder.js b/frontend/src/Call/components/PlaylistBuilder.js index bdccc9d..4c0b411 100644 --- a/frontend/src/Call/components/PlaylistBuilder.js +++ b/frontend/src/Call/components/PlaylistBuilder.js @@ -1,4 +1,5 @@ import { useSelector, useDispatch } from 'react-redux' +import { useParams } from 'react-router-dom'; import React, { useState } from "react"; import { Header, @@ -9,13 +10,45 @@ import { Statistic, Icon, Menu, - Tab + Tab, + Table, + Modal, + Button, + Image, + Form } from "semantic-ui-react"; +import { useAddNewEventMutation, useGetTalkgroupsQuery } from '../../features/api/apiSlice' function PlaylistBuilder(props) { - + const { shortName } = useParams(); + const { data: talkgroupsData, isSuccess: isTalkgroupsSuccess } = useGetTalkgroupsQuery(shortName); + const [addNewEvent, { isLoading }] = useAddNewEventMutation() const { loading: callsLoading, data: callsData } = useSelector((state) => state.calls); const [playlist, setPlaylist] = useState([]); + const [open, setOpen] = React.useState(false); + const [title, setTitle] = useState("") + const [description, setDescription] = useState("") + const handleTitleChange = (e, { name, value }) => setTitle(value); + const handleDescriptionChange = (e, { name, value }) => setDescription(value); + + + const compareCalls = (a, b) => { + const aTimestamp = new Date(a.time).getTime() + const bTimestamp = new Date(b.time).getTime() + if (aTimestamp > bTimestamp) { + return -1 + } else { + return 1 + } + } + const addCall = (call) => { + const found = playlist.find(c => c._id == call._id); + if (!found) { + playlist.push(call); + setPlaylist([...playlist.sort(compareCalls)]) + } + + } const onDragOver = (event) => { // It also receives a DragEvent. @@ -32,30 +65,109 @@ function PlaylistBuilder(props) { event.preventDefault(); } + const onDrop = (event) => { // Here, we will: // - update the rendered list // - and reset the DnD state var callId = event.dataTransfer.getData("call-id"); console.log("Dropping: " + callId); - console.log("Found: " + callsData.entities[callId].freq); - setPlaylist([...playlist, callId]); + addCall(callsData.entities[callId]) } let listItems = ""; - listItems = playlist.map((callId, index) => { - const call = callsData.entities[callId]; - return(
  • {call.time}
  • ) - }) - + listItems = playlist.map((call, index) => { + let tgAlpha = ""; + if (talkgroupsData) { + const talkgroup = talkgroupsData.talkgroups[call.talkgroupNum] + tgAlpha = talkgroup.alpha + } + const time = new Date(call.time); + const callTime = time.toLocaleTimeString(); + const callDate = time.toLocaleDateString(); + return ( + {call.len} + {tgAlpha} + {callTime} + + ) + }) + + const submitPlaylist = () => { + setOpen(true) + } + + const handleSubmit = () => { + console.log(title) + setOpen(false) + const callIds = playlist.map( (call) => call._id) + const event = { + title, + description, + callIds + } + addNewEvent(event) + setTitle("") + setDescription("") + setPlaylist([]) + } return ( - - - + <> + setOpen(false)} + onOpen={() => setOpen(true)} + open={open} + > + Submit an Event + + + +
    Event
    +
    + + + + + +
    +
    + + +