diff --git a/src/components/AppView/AppView.js b/src/components/AppView/AppView.js index d0e11b4..8536140 100644 --- a/src/components/AppView/AppView.js +++ b/src/components/AppView/AppView.js @@ -18,7 +18,7 @@ export default function AppView({ setDarkMode }){ const [items, setItems] = useState([]); const [selectedQueues, setSelectedQueues] = useState([]); const [queueSelectorOpen, setQueueSelectorOpen] = useState(false); - const [isLoading, setIsLoading] = useState(true); + const [isLoading, setIsLoading] = useState(false); // Create contextual variables. const activeItem = useItem(); @@ -41,6 +41,7 @@ export default function AppView({ setDarkMode }){ return undefined; } + setIsLoading(true); let queuesToLoad = ""; if (selectedQueues.length === 1){ @@ -62,6 +63,7 @@ export default function AppView({ setDarkMode }){ const queueJson = await apiResponse.json(); setQueues(queueJson); + setIsLoading(false) })(); }, [selectedQueues, access_token, queueSelectorOpen]); diff --git a/src/components/ItemTable/ItemTable.js b/src/components/ItemTable/ItemTable.js index 0cc18b9..13e96a0 100644 --- a/src/components/ItemTable/ItemTable.js +++ b/src/components/ItemTable/ItemTable.js @@ -1,20 +1,25 @@ import React, { useState } from "react"; import PropTypes from "prop-types"; import { useTable, useFilters, useFlexLayout, useSortBy } from "react-table"; -import { Table, TableBody, TableCell, TableHead, TableRow, TableContainer, Paper, Grid, ButtonGroup, IconButton, makeStyles, useTheme } from "@material-ui/core"; +import { Table, TableBody, TableCell, TableHead, TableRow, TableContainer, Box, Grid, ButtonGroup, IconButton, makeStyles, useTheme } from "@material-ui/core"; import { useHistory } from "react-router-dom"; import RelativeTime from "react-relative-time"; import ItemTableFilter from "../ItemTableFilter/" import { ArrowDownward, ArrowUpward } from "@material-ui/icons"; import ItemTableCell from "../ItemTableCell"; import LastUpdatedCell from "../LastUpdatedCell/"; -import { Skeleton } from "@material-ui/lab"; +import jester from "./loading-annimation.gif"; export default function ItemTable({ data, rowCanBeSelected, loading }) { const [selectedRow, setSelectedRow] = useState({ queue: null, number: null }); const theme = useTheme(); const useStyles = makeStyles({ + loadingAnnimation: { + display: "flex", + justifyContent: "center", + width: "100%" + }, hoverBackgroundColor: { "&:hover": { // The !important is placed here to enforce CSS specificity. @@ -85,64 +90,69 @@ export default function ItemTable({ data, rowCanBeSelected, loading }) { const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow, } = tableInstance; return ( - - - - {headerGroups.map(headerGroup => ( - - {headerGroup.headers.map(column => ( - - - - - {column.render("Filter")} - - - - { - const isSortedAsc = column.isSorted && !column.isSortedDesc; - isSortedAsc ? column.clearSortBy() : column.toggleSortBy(false) - })} - > - - - { - const isSortedDesc = column.isSorted && column.isSortedDesc; - isSortedDesc ? column.clearSortBy() : column.toggleSortBy(true) - })} - > - - - + loading + ? ( + + Items are loading. + + ) + : ( + +
+ + {headerGroups.map(headerGroup => ( + + {headerGroup.headers.map(column => ( + + + + + {column.render("Filter")} + + + + { + const isSortedAsc = column.isSorted && !column.isSortedDesc; + isSortedAsc ? column.clearSortBy() : column.toggleSortBy(false) + })} + > + + + { + const isSortedDesc = column.isSorted && column.isSortedDesc; + isSortedDesc ? column.clearSortBy() : column.toggleSortBy(true) + })} + > + + + + - - - - ))} - - ))} - - - {rows.map((row) => { - prepareRow(row); - let isSelected = selectedRow.queue === row.original.queue && selectedRow.number === row.original.number - return ( - loading ? : - + + + ))} + + ))} + + + {rows.map((row) => { + prepareRow(row); + let isSelected = selectedRow.queue === row.original.queue && selectedRow.number === row.original.number + return ( { @@ -183,25 +193,27 @@ export default function ItemTable({ data, rowCanBeSelected, loading }) { } }) ))}; - - ); - })} - -
-
+ + ); + })} + + + + ) ); }; ItemTable.propTypes = { /** Array of items from all active queues to display in table. */ "items": PropTypes.array, - /** State variable indicating if rows can be selected. When false, all rows are deselected. */ - "rowCanBeSelected": PropTypes.bool + /** If true, rows can be selected. */ + "rowCanBeSelected": PropTypes.bool, + /** If true, ItemTable displays loading screen. */ + "loading": PropTypes.bool }; ItemTable.defaultProps = { - /** The items to display in the table. */ "items": [], - /** A state variable determining whether a row can be selected or not. */ - "rowCanBeSelected": true + "rowCanBeSelected": true, + "loading": false }; diff --git a/src/components/ItemTable/loading-annimation.gif b/src/components/ItemTable/loading-annimation.gif new file mode 100644 index 0000000..c657308 Binary files /dev/null and b/src/components/ItemTable/loading-annimation.gif differ