diff --git a/webclient/src/Storage.js b/webclient/src/Storage.js index 9f340a7..2d20ec8 100644 --- a/webclient/src/Storage.js +++ b/webclient/src/Storage.js @@ -3,7 +3,7 @@ import { Link, useParams, useHistory } from 'react-router-dom'; import './light.css'; import { MembersDropdown } from './Members.js'; import { isAdmin, BasicTable, requester, useIsMobile } from './utils.js'; -import { Button, Container, Form, Grid, Header, Icon, Message, Segment, Table } from 'semantic-ui-react'; +import { Button, Container, Form, Grid, Header, Icon, Input, Message, Segment, Table } from 'semantic-ui-react'; export function StorageEditor(props) { const { token, input, setInput, error } = props; @@ -235,9 +235,50 @@ export function StorageButton(props) { ); }; +let storageSearchCache = ''; + +export function StorageSearch(props) { + const { setSearch } = props; + const [input, setInput] = useState(storageSearchCache); + + const handleChange = (event) => { + const q = event.target.value.toUpperCase(); + setInput(q); + setSearch(q); + storageSearchCache = q; + }; + + return ( +
+ + + {input.length ? +
+ ); +}; + +let storageListCache = false; + export function StorageList(props) { const { token } = props; - const [storageList, setStorageList] = useState(false); + const [storageList, setStorageList] = useState(storageListCache); + const [search, setSearch] = useState(storageSearchCache); const [error, setError] = useState(false); const isMobile = useIsMobile(); @@ -245,6 +286,7 @@ export function StorageList(props) { requester('/storage/', 'GET', token) .then(res => { setStorageList(res.results); + storageListCache = res.results; setError(false); }) .catch(err => { @@ -253,6 +295,14 @@ export function StorageList(props) { }); }, []); + const filterStorage = (x) => { + if (search.length && !x.shelf_id.startsWith(search)) { + return false; + } else { + return true; + } + }; + return (

@@ -260,19 +310,22 @@ export function StorageList(props) { Locker
Large project storage

+ + + {!error ? storageList ? - + {!isMobile && Shelf ID Owner Memo - + } - {storageList.map(x => + {storageList.filter(filterStorage).map(x =>