Share search query state between panel and footer
This commit is contained in:
parent
c564400223
commit
a83e3a9e0b
3 changed files with 19 additions and 13 deletions
|
@ -3,10 +3,7 @@ import { Box, Flex, useBreakpointValue } from "@chakra-ui/react";
|
||||||
import * as Sentry from "@sentry/react";
|
import * as Sentry from "@sentry/react";
|
||||||
|
|
||||||
import ItemsPanel from "./ItemsPanel";
|
import ItemsPanel from "./ItemsPanel";
|
||||||
import SearchToolbar, {
|
import SearchToolbar, { searchQueryIsEmpty } from "./SearchToolbar";
|
||||||
emptySearchQuery,
|
|
||||||
searchQueryIsEmpty,
|
|
||||||
} from "./SearchToolbar";
|
|
||||||
import SearchPanel from "./SearchPanel";
|
import SearchPanel from "./SearchPanel";
|
||||||
import { MajorErrorMessage, TestErrorSender, useLocalStorage } from "../util";
|
import { MajorErrorMessage, TestErrorSender, useLocalStorage } from "../util";
|
||||||
|
|
||||||
|
@ -25,11 +22,12 @@ import { MajorErrorMessage, TestErrorSender, useLocalStorage } from "../util";
|
||||||
*/
|
*/
|
||||||
function ItemsAndSearchPanels({
|
function ItemsAndSearchPanels({
|
||||||
loading,
|
loading,
|
||||||
|
searchQuery,
|
||||||
|
onChangeSearchQuery,
|
||||||
outfitState,
|
outfitState,
|
||||||
outfitSaving,
|
outfitSaving,
|
||||||
dispatchToOutfit,
|
dispatchToOutfit,
|
||||||
}) {
|
}) {
|
||||||
const [searchQuery, setSearchQuery] = React.useState(emptySearchQuery);
|
|
||||||
const scrollContainerRef = React.useRef();
|
const scrollContainerRef = React.useRef();
|
||||||
const searchQueryRef = React.useRef();
|
const searchQueryRef = React.useRef();
|
||||||
const firstSearchResultRef = React.useRef();
|
const firstSearchResultRef = React.useRef();
|
||||||
|
@ -52,7 +50,7 @@ function ItemsAndSearchPanels({
|
||||||
query={searchQuery}
|
query={searchQuery}
|
||||||
searchQueryRef={searchQueryRef}
|
searchQueryRef={searchQueryRef}
|
||||||
firstSearchResultRef={firstSearchResultRef}
|
firstSearchResultRef={firstSearchResultRef}
|
||||||
onChange={setSearchQuery}
|
onChange={onChangeSearchQuery}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import * as Sentry from "@sentry/react";
|
import * as Sentry from "@sentry/react";
|
||||||
import { Box, Flex } from "@chakra-ui/react";
|
import { Box, Flex } from "@chakra-ui/react";
|
||||||
import SearchToolbar, { emptySearchQuery } from "./SearchToolbar";
|
import SearchToolbar from "./SearchToolbar";
|
||||||
import { MajorErrorMessage, TestErrorSender, useLocalStorage } from "../util";
|
import { MajorErrorMessage, TestErrorSender, useLocalStorage } from "../util";
|
||||||
import PaginationToolbar from "../components/PaginationToolbar";
|
import PaginationToolbar from "../components/PaginationToolbar";
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import PaginationToolbar from "../components/PaginationToolbar";
|
||||||
* SearchFooter appears on large screens only, to let you search for new items
|
* SearchFooter appears on large screens only, to let you search for new items
|
||||||
* while still keeping the rest of the item screen open!
|
* while still keeping the rest of the item screen open!
|
||||||
*/
|
*/
|
||||||
function SearchFooter() {
|
function SearchFooter({ searchQuery, onChangeSearchQuery }) {
|
||||||
const [canUseSearchFooter, setCanUseSearchFooter] = useLocalStorage(
|
const [canUseSearchFooter, setCanUseSearchFooter] = useLocalStorage(
|
||||||
"DTIFeatureFlagCanUseSearchFooter",
|
"DTIFeatureFlagCanUseSearchFooter",
|
||||||
false
|
false
|
||||||
|
@ -21,8 +21,6 @@ function SearchFooter() {
|
||||||
}
|
}
|
||||||
}, [setCanUseSearchFooter]);
|
}, [setCanUseSearchFooter]);
|
||||||
|
|
||||||
const [query, setQuery] = React.useState(emptySearchQuery);
|
|
||||||
|
|
||||||
// TODO: Show the new footer to other users, too!
|
// TODO: Show the new footer to other users, too!
|
||||||
if (!canUseSearchFooter) {
|
if (!canUseSearchFooter) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -38,8 +36,8 @@ function SearchFooter() {
|
||||||
</Box>
|
</Box>
|
||||||
<Box width="8" />
|
<Box width="8" />
|
||||||
<SearchToolbar
|
<SearchToolbar
|
||||||
query={query}
|
query={searchQuery}
|
||||||
onChange={setQuery}
|
onChange={onChangeSearchQuery}
|
||||||
flex="0 1 100%"
|
flex="0 1 100%"
|
||||||
suggestionsPlacement="top"
|
suggestionsPlacement="top"
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -11,6 +11,7 @@ import WardrobePageLayout from "./WardrobePageLayout";
|
||||||
import WardrobePreviewAndControls from "./WardrobePreviewAndControls";
|
import WardrobePreviewAndControls from "./WardrobePreviewAndControls";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
|
import { emptySearchQuery } from "./SearchToolbar";
|
||||||
|
|
||||||
const WardrobeDevHacks = loadable(() => import("./WardrobeDevHacks"));
|
const WardrobeDevHacks = loadable(() => import("./WardrobeDevHacks"));
|
||||||
|
|
||||||
|
@ -29,6 +30,8 @@ function WardrobePage() {
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
const { loading, error, outfitState, dispatchToOutfit } = useOutfitState();
|
const { loading, error, outfitState, dispatchToOutfit } = useOutfitState();
|
||||||
|
|
||||||
|
const [searchQuery, setSearchQuery] = React.useState(emptySearchQuery);
|
||||||
|
|
||||||
// We manage outfit saving up here, rather than at the point of the UI where
|
// We manage outfit saving up here, rather than at the point of the UI where
|
||||||
// "Saving" indicators appear. That way, auto-saving still happens even when
|
// "Saving" indicators appear. That way, auto-saving still happens even when
|
||||||
// the indicator isn't on the page, e.g. when searching. We also mount a
|
// the indicator isn't on the page, e.g. when searching. We also mount a
|
||||||
|
@ -113,12 +116,19 @@ function WardrobePage() {
|
||||||
itemsAndMaybeSearchPanel={
|
itemsAndMaybeSearchPanel={
|
||||||
<ItemsAndSearchPanels
|
<ItemsAndSearchPanels
|
||||||
loading={loading}
|
loading={loading}
|
||||||
|
searchQuery={searchQuery}
|
||||||
|
onChangeSearchQuery={setSearchQuery}
|
||||||
outfitState={outfitState}
|
outfitState={outfitState}
|
||||||
outfitSaving={outfitSaving}
|
outfitSaving={outfitSaving}
|
||||||
dispatchToOutfit={dispatchToOutfit}
|
dispatchToOutfit={dispatchToOutfit}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
searchFooter={<SearchFooter />}
|
searchFooter={
|
||||||
|
<SearchFooter
|
||||||
|
searchQuery={searchQuery}
|
||||||
|
onChangeSearchQuery={setSearchQuery}
|
||||||
|
/>
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</OutfitStateContext.Provider>
|
</OutfitStateContext.Provider>
|
||||||
</>
|
</>
|
||||||
|
|
Loading…
Reference in a new issue