From d98ac0505a243cabb71831481ac97904995caede Mon Sep 17 00:00:00 2001 From: Marin Minnerly Date: Sat, 20 Jul 2024 11:39:52 -0700 Subject: [PATCH] Remember search term between themes --- plugin/src/components/App.luau | 3 +++ plugin/src/components/HomeWrapper.luau | 13 +++++++------ plugin/src/components/HomeWrapper.story.luau | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/plugin/src/components/App.luau b/plugin/src/components/App.luau index d83d631..3d10465 100644 --- a/plugin/src/components/App.luau +++ b/plugin/src/components/App.luau @@ -18,6 +18,7 @@ export type Props = { local function App(_props: Props) local view, setView = useState("Home" :: View) local extension, setExtension = useState(nil :: PublishedExtension?) + local searchTerm, setSearchTerm = useState(nil :: string?) local onBack = useCallback(function() setExtension(nil) @@ -35,7 +36,9 @@ local function App(_props: Props) }, { Home = if view == "Home" then React.createElement(HomeWrapper, { + onSearch = setSearchTerm, onViewExtension = onViewExtension, + searchTerm = searchTerm, }) else nil, diff --git a/plugin/src/components/HomeWrapper.luau b/plugin/src/components/HomeWrapper.luau index c5a8c9b..33de1a9 100644 --- a/plugin/src/components/HomeWrapper.luau +++ b/plugin/src/components/HomeWrapper.luau @@ -11,13 +11,14 @@ local useEffect = React.useEffect local useState = React.useState export type Props = { + onSearch: (searchTerm: string) -> (), onViewExtension: (extension: PublishedExtension) -> (), + searchTerm: string?, } local function HomeWrapper(props: Props) local page, setPage = useState(1) local extensions, setExtensions = useState({} :: { PublishedExtension }) - local searchTerm, setSearchTerm = useState(nil :: string?) local err, setErr = useState(nil :: string?) local onFetchMore = useCallback(function() @@ -28,14 +29,14 @@ local function HomeWrapper(props: Props) useEffect(function() setPage(1) - end, { searchTerm }) + end, { props.searchTerm }) useEffect(function() setErr(nil) fetchVisualStudioExtensions({ page = page, pageSize = 20, - searchTerm = if searchTerm then searchTerm else "theme", + searchTerm = if props.searchTerm then props.searchTerm else "theme", }) :andThen(function(newExtensions) setExtensions(function(prev) @@ -49,13 +50,13 @@ local function HomeWrapper(props: Props) :catch(function() setErr(`No extensions found. Please try again later`) end) - end, { searchTerm, page }) + end, { props.searchTerm, page }) return React.createElement(Home, { extensions = extensions, err = err, - searchTerm = searchTerm, - onSearch = setSearchTerm, + searchTerm = props.searchTerm, + onSearch = props.onSearch, onFetchMore = onFetchMore, onViewExtension = props.onViewExtension, }) diff --git a/plugin/src/components/HomeWrapper.story.luau b/plugin/src/components/HomeWrapper.story.luau index 0f39ea6..3b934f3 100644 --- a/plugin/src/components/HomeWrapper.story.luau +++ b/plugin/src/components/HomeWrapper.story.luau @@ -5,6 +5,7 @@ return { story = function() return React.createElement(HomeWrapper, { onViewExtension = print, + onSearch = print, }) end, }