2020-04-26 00:37:58 -07:00
|
|
|
import React from "react";
|
2020-12-25 09:08:33 -08:00
|
|
|
import { Box, Flex } from "@chakra-ui/react";
|
2020-04-26 00:37:58 -07:00
|
|
|
|
|
|
|
import ItemsPanel from "./ItemsPanel";
|
2021-01-18 15:56:24 -08:00
|
|
|
import SearchToolbar, { emptySearchQuery } from "./SearchToolbar";
|
2020-04-26 00:37:58 -07:00
|
|
|
import SearchPanel from "./SearchPanel";
|
2020-09-01 19:11:33 -07:00
|
|
|
|
2020-04-26 00:37:58 -07:00
|
|
|
/**
|
|
|
|
* ItemsAndSearchPanels manages the shared layout and state for:
|
|
|
|
* - ItemsPanel, which shows the items in the outfit now, and
|
|
|
|
* - SearchPanel, which helps you find new items to add.
|
|
|
|
*
|
|
|
|
* These panels don't share a _lot_ of concerns; they're mainly intertwined by
|
|
|
|
* the fact that they share the SearchToolbar at the top!
|
|
|
|
*
|
|
|
|
* We try to keep the search concerns in the search components, by avoiding
|
|
|
|
* letting any actual _logic_ live at the root here; and instead just
|
|
|
|
* performing some wiring to help them interact with each other via simple
|
|
|
|
* state and refs.
|
|
|
|
*/
|
|
|
|
function ItemsAndSearchPanels({ loading, outfitState, dispatchToOutfit }) {
|
2021-01-18 15:56:24 -08:00
|
|
|
const [searchQuery, setSearchQuery] = React.useState(emptySearchQuery);
|
2020-04-26 00:37:58 -07:00
|
|
|
const scrollContainerRef = React.useRef();
|
|
|
|
const searchQueryRef = React.useRef();
|
|
|
|
const firstSearchResultRef = React.useRef();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Flex direction="column" height="100%">
|
|
|
|
<Box px="5" py="3" boxShadow="sm">
|
|
|
|
<SearchToolbar
|
|
|
|
query={searchQuery}
|
|
|
|
searchQueryRef={searchQueryRef}
|
|
|
|
firstSearchResultRef={firstSearchResultRef}
|
2021-01-18 15:56:24 -08:00
|
|
|
onChange={setSearchQuery}
|
2020-04-26 00:37:58 -07:00
|
|
|
/>
|
|
|
|
</Box>
|
2020-11-08 15:04:17 -08:00
|
|
|
{searchQuery.value ||
|
|
|
|
searchQuery.filterToItemKind ||
|
|
|
|
searchQuery.filterToZoneLabel ? (
|
2020-04-26 00:37:58 -07:00
|
|
|
<Box
|
|
|
|
key="search-panel"
|
|
|
|
gridArea="items"
|
|
|
|
position="relative"
|
|
|
|
overflow="auto"
|
|
|
|
ref={scrollContainerRef}
|
|
|
|
>
|
2020-09-01 19:40:53 -07:00
|
|
|
<Box px="4" py="2">
|
2020-04-26 00:37:58 -07:00
|
|
|
<SearchPanel
|
2020-09-01 19:53:38 -07:00
|
|
|
query={searchQuery}
|
2020-04-26 00:37:58 -07:00
|
|
|
outfitState={outfitState}
|
|
|
|
dispatchToOutfit={dispatchToOutfit}
|
|
|
|
scrollContainerRef={scrollContainerRef}
|
|
|
|
searchQueryRef={searchQueryRef}
|
|
|
|
firstSearchResultRef={firstSearchResultRef}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
) : (
|
|
|
|
<Box
|
|
|
|
gridArea="items"
|
|
|
|
position="relative"
|
|
|
|
overflow="auto"
|
|
|
|
key="items-panel"
|
|
|
|
>
|
2020-09-01 19:40:53 -07:00
|
|
|
<Box px="4" py="2">
|
2020-04-26 00:37:58 -07:00
|
|
|
<ItemsPanel
|
|
|
|
loading={loading}
|
|
|
|
outfitState={outfitState}
|
|
|
|
dispatchToOutfit={dispatchToOutfit}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
</Flex>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ItemsAndSearchPanels;
|