From 864e275769d2fd6da979e5df5480b5d2e7baaf1c Mon Sep 17 00:00:00 2001 From: Matt Dunn-Rankin Date: Sun, 26 Apr 2020 01:42:24 -0700 Subject: [PATCH] SearchPanel docs & cleanup --- src/app/SearchPanel.js | 289 +++++++++++++++++++++++++---------------- 1 file changed, 178 insertions(+), 111 deletions(-) diff --git a/src/app/SearchPanel.js b/src/app/SearchPanel.js index 3f5a01d..fe34d3d 100644 --- a/src/app/SearchPanel.js +++ b/src/app/SearchPanel.js @@ -7,6 +7,13 @@ import { Delay, Heading1, useDebounce } from "./util"; import { Item, ItemListContainer, ItemListSkeleton } from "./Item"; import { itemAppearanceFragment } from "./OutfitPreview"; +/** + * SearchPanel shows item search results to the user, so they can preview them + * and add them to their outfit! + * + * It's tightly coordinated with SearchToolbar, using refs to control special + * keyboard and focus interactions. + */ function SearchPanel({ query, outfitState, @@ -22,6 +29,7 @@ function SearchPanel({ } }, [query, scrollContainerRef]); + // Sometimes we want to give focus back to the search field! const onMoveFocusUpToQuery = (e) => { if (searchQueryRef.current) { searchQueryRef.current.focus(); @@ -33,6 +41,8 @@ function SearchPanel({ { + // This will catch any Escape presses when the user's focus is inside + // the SearchPanel. if (e.key === "Escape") { onMoveFocusUpToQuery(e); } @@ -51,6 +61,14 @@ function SearchPanel({ ); } +/** + * SearchResults loads the search results from the user's query, renders them, + * and tracks the scroll container for infinite scrolling. + * + * For each item, we render a