diff --git a/src/App.js b/src/App.js index 351f068..068c371 100644 --- a/src/App.js +++ b/src/App.js @@ -1,23 +1,18 @@ import React, { useState, useEffect } from "react"; +import { ThemeProvider } from "@material-ui/core/styles"; +import { Box, makeStyles } from "@material-ui/core"; import { Route } from "react-router-dom"; import clsx from "clsx"; -import { ThemeProvider } from "@material-ui/core/styles"; import webqueueTheme from "./theme"; -import { Box, makeStyles } from "@material-ui/core"; import ItemTableAppBar from "./components/ItemTableAppBar/"; import ItemTable from "./components/ItemTable/"; import ItemViewAppBar from "./components/ItemViewAppBar/"; import ItemView from "./components/ItemView/"; -const testItem = { "queue": "ce", "number": 100, "lastUpdated": "07-23-20 10:11 PM", "headers": [{ "type": "Merged-Time", "content": "Tue, 23 Jun 2020 13:31:53 -0400" }, { "type": "Merged-By", "content": "campb303" }, { "type": "QTime", "content": "1" }, { "type": "QTime-Updated-Time", "content": "Tue, 23 Jun 2020 13:28:50 EDT" }, { "type": "QTime-Updated-By", "content": "campb303" }, { "type": "Time", "content": "1" }, { "type": "Time-Updated-Time", "content": "Tue, 23 Jun 2020 13:28:50 EDT" }, { "type": "Time-Updated-By", "content": "campb303" }, { "type": "Replied-Time", "content": "Tue, 23 Jun 2020 13:28:48 -0400" }, { "type": "Replied-By", "content": "campb303" }, { "type": "Edited-Time", "content": "Tue, 23 Jun 2020 13:27:56 -0400" }, { "type": "Edited-By", "content": "campb303" }, { "type": "QAssigned-To", "content": "campb303" }, { "type": "QAssigned-To-Updated-Time", "content": "Tue, 23 Jun 2020 13:27:00 EDT" }, { "type": "QAssigned-To-Updated-By", "content": "campb303" }, { "type": "Assigned-To", "content": "campb303" }, { "type": "Assigned-To-Updated-Time", "content": "Tue, 23 Jun 2020 13:27:00 EDT" }, { "type": "Assigned-To-Updated-By", "content": "campb303" }, { "type": "QStatus", "content": "Dont Delete" }, { "type": "QStatus-Updated-Time", "content": "Tue, 23 Jun 2020 13:26:55 EDT" }, { "type": "QStatus-Updated-By", "content": "campb303" }, { "type": "Status", "content": "Dont Delete" }, { "type": "Status-Updated-Time", "content": "Tue, 23 Jun 2020 13:26:55 EDT" }, { "type": "Status-Updated-By", "content": "campb303" }, { "type": "Date", "content": "Tue, 23 Jun 2020 13:25:51 -0400" }, { "type": "From", "content": "Justin Campbell " }, { "type": "Message-ID", "content": "<911CE050-3240-4980-91DD-9C3EBB8DBCF8@purdue.edu>" }, { "type": "Subject", "content": "Beepboop" }, { "type": "To", "content": "cesite@ecn.purdue.edu" }, { "type": "Content-Type", "content": "text/plain; charset=\"utf-8\"" }, { "type": "X-ECN-Queue-Original-Path", "content": "/home/pier/e/queue/Attachments/inbox/2020-06-23/208-original.txt" }], "content": ["Testtest\n", "\n", "*** Status updated by: campb303 at: 6/23/2020 13:26:55 ***\n", "Dont Delete\n", "*** Edited by: campb303 at: 06/23/20 13:27:56 ***\n", "\n", "This be an edit my boy\n", "\n", "\n", "\n", "*** Replied by: campb303 at: 06/23/20 13:28:18 ***\n", "\n", "This be a reply my son\n", "\n", "Justin\n", "ECN\n", "\n", "=== Additional information supplied by user ===\n", "\n", "Subject: Re: Beepboop\n", "From: Justin Campbell \n", "Date: Tue, 23 Jun 2020 13:30:45 -0400\n", "X-ECN-Queue-Original-Path: /home/pier/e/queue/Attachments/inbox/2020-06-23/212-original.txt\n", "X-ECN-Queue-Original-URL: https://engineering.purdue.edu/webqueue/Attachments/inbox/2020-06-23/212-original.txt\n", "\n", "Huzzah!\n", "\n", "===============================================\n"], "isLocked": "ce 100 is locked by knewell using qvi", "userEmail": "campb303@purdue.edu", "userName": "Justin Campbell", "userAlias": "campb303", "assignedTo": "campb303", "subject": "Beepboop", "status": "Dont Delete", "priority": "", "department": "", "building": "", "dateReceived": "Tue, 23 Jun 2020 13:25:51 -0400" } - function App() { const [darkMode, setDarkMode] = useState(false); - const [activeItem, setActiveItem] = useState(testItem); + const [activeItem, setActiveItem] = useState({}); const [sidebarOpen, setSidebarOpen] = useState(false); - - const theme = webqueueTheme(darkMode); - const [itemQueue, setItemQueue] = useState([]) useEffect(() => { @@ -26,11 +21,11 @@ function App() { }) }, []) + const theme = webqueueTheme(darkMode); const transitionWidth = theme.transitions.create(["width"], { duration: theme.transitions.duration.enteringScreen, easing: theme.transitions.easing.easeInOut }); - const useStyles = makeStyles({ "leftCol": { overflow: "auto", @@ -57,7 +52,6 @@ function App() { } }, }); - const classes = useStyles(); return ( @@ -71,41 +65,40 @@ function App() { - {itemQueue.length === 0 ? null : - { - - /** - * Returns true if an item matches the URL parameters. - * @param item {Object} The item to compare. - * @param match {Object} The match parameters. - * @returns {boolean} - */ - function itemMatchesURL(item, match){ - let queueMatches = item.queue === match.params.queue; - let numberMatches = item.number === match.params.number; - return queueMatches && numberMatches; - } - - let item = itemQueue.find( item => itemMatchesURL(item, match) ); - - if (item === undefined) { - setSidebarOpen(true); - return "Item doesn't exist :("; - } - - setActiveItem(item); - setSidebarOpen(true); - - return ( - <> - - - - ); - }} - />} + {itemQueue.length === 0 ? null : + { + + /** + * Returns true if an item matches the URL parameters. + * @param item {Object} The item to compare. + * @param match {Object} The match parameters. + * @returns {boolean} + */ + function itemMatchesURL(item, match) { + let queueMatches = item.queue === match.params.queue; + let numberMatches = item.number === match.params.number; + return queueMatches && numberMatches; + } + + let item = itemQueue.find(item => itemMatchesURL(item, match)); + + if (item === undefined) { + setSidebarOpen(true); + return "Item doesn't exist :("; + } + + setActiveItem(item); + + return ( + <> + + + + ); + }} + />}