2023-08-10 15:56:36 -07:00
|
|
|
import React from "react";
|
|
|
|
import * as Sentry from "@sentry/react";
|
|
|
|
import { Box, Flex } from "@chakra-ui/react";
|
|
|
|
import SearchToolbar from "./SearchToolbar";
|
|
|
|
import { MajorErrorMessage, TestErrorSender, useLocalStorage } from "../util";
|
|
|
|
import PaginationToolbar from "../components/PaginationToolbar";
|
|
|
|
import { useSearchResults } from "./useSearchResults";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SearchFooter appears on large screens only, to let you search for new items
|
|
|
|
* while still keeping the rest of the item screen open!
|
|
|
|
*/
|
|
|
|
function SearchFooter({ searchQuery, onChangeSearchQuery, outfitState }) {
|
2024-09-09 16:10:45 -07:00
|
|
|
const [canUseSearchFooter, setCanUseSearchFooter] = useLocalStorage(
|
|
|
|
"DTIFeatureFlagCanUseSearchFooter",
|
|
|
|
false,
|
|
|
|
);
|
2023-08-10 15:56:36 -07:00
|
|
|
|
2024-09-09 16:10:45 -07:00
|
|
|
const { items, numTotalPages } = useSearchResults(
|
|
|
|
searchQuery,
|
|
|
|
outfitState,
|
|
|
|
1,
|
|
|
|
);
|
2023-08-10 15:56:36 -07:00
|
|
|
|
2024-09-09 16:10:45 -07:00
|
|
|
React.useEffect(() => {
|
|
|
|
if (window.location.search.includes("feature-flag-can-use-search-footer")) {
|
|
|
|
setCanUseSearchFooter(true);
|
|
|
|
}
|
|
|
|
}, [setCanUseSearchFooter]);
|
2023-08-10 15:56:36 -07:00
|
|
|
|
2024-09-09 16:10:45 -07:00
|
|
|
// TODO: Show the new footer to other users, too!
|
|
|
|
if (!canUseSearchFooter) {
|
|
|
|
return null;
|
|
|
|
}
|
2023-08-10 15:56:36 -07:00
|
|
|
|
2024-09-09 16:10:45 -07:00
|
|
|
return (
|
|
|
|
<Sentry.ErrorBoundary fallback={MajorErrorMessage}>
|
|
|
|
<TestErrorSender />
|
|
|
|
<Box>
|
|
|
|
<Box paddingX="4" paddingY="4">
|
|
|
|
<Flex as="label" align="center">
|
|
|
|
<Box fontWeight="600" flex="0 0 auto">
|
|
|
|
Add new items:
|
|
|
|
</Box>
|
|
|
|
<Box width="8" />
|
|
|
|
<SearchToolbar
|
|
|
|
query={searchQuery}
|
|
|
|
onChange={onChangeSearchQuery}
|
|
|
|
flex="0 1 100%"
|
|
|
|
suggestionsPlacement="top"
|
|
|
|
/>
|
|
|
|
<Box width="8" />
|
|
|
|
{numTotalPages != null && (
|
|
|
|
<Box flex="0 0 auto">
|
|
|
|
<PaginationToolbar
|
|
|
|
numTotalPages={numTotalPages}
|
|
|
|
currentPageNumber={1}
|
|
|
|
goToPageNumber={() => alert("TODO")}
|
|
|
|
buildPageUrl={() => null}
|
|
|
|
size="sm"
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
</Flex>
|
|
|
|
</Box>
|
|
|
|
<Box maxHeight="32" overflow="auto">
|
|
|
|
<Box as="ul" listStyleType="disc" paddingLeft="8">
|
|
|
|
{items.map((item) => (
|
|
|
|
<Box key={item.id} as="li">
|
|
|
|
{item.name}
|
|
|
|
</Box>
|
|
|
|
))}
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
</Sentry.ErrorBoundary>
|
|
|
|
);
|
2023-08-10 15:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export default SearchFooter;
|