From 0a58f98a90cc0e52b748aaa5cbd85ff21f7d49a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20Andre=20Tangen=20=40gorillatron?= Date: Wed, 29 Nov 2023 12:04:13 +0100 Subject: [PATCH 1/9] Update MarketSearch.tsx --- components/markets/MarketSearch.tsx | 139 +++++++++++++++------------- 1 file changed, 77 insertions(+), 62 deletions(-) diff --git a/components/markets/MarketSearch.tsx b/components/markets/MarketSearch.tsx index f1f6acc96..0d4b4789a 100644 --- a/components/markets/MarketSearch.tsx +++ b/components/markets/MarketSearch.tsx @@ -1,7 +1,9 @@ +import { Transition } from "@headlessui/react"; import { MarketStatus } from "@zeitgeistpm/indexer"; import { useMarketSearch } from "lib/hooks/queries/useMarketSearch"; import Link from "next/link"; -import { useEffect, useRef, useState } from "react"; +import { FaDeleteLeft } from "react-icons/fa6"; +import { Fragment, useEffect, useRef, useState } from "react"; import { Search, X } from "react-feather"; const MarketSearch = () => { @@ -12,6 +14,7 @@ const MarketSearch = () => { const inputRef = useRef(null); const { data: markets } = useMarketSearch(searchTerm); + useEffect(() => { const handleClickOutside = (event) => { if (wrapperRef.current && !wrapperRef.current.contains(event.target)) { @@ -30,77 +33,89 @@ const MarketSearch = () => {
+ { + setShowResults(true); + setSearchTerm(event.target.value); + }} + onFocus={() => { + setShowResults(true); + }} + /> + {showSearch && ( + + )} + - {showSearch && ( - <> - { - setShowResults(true); - setSearchTerm(event.target.value); - }} - onFocus={() => { - setShowResults(true); - }} - /> - - - )}
- {showResults && markets && ( -
-
Results
- - {markets.length > 0 ? ( - markets?.map((market) => ( - { - setShowResults(false); - }} - > -
- {market.question} -
-
+
+
+ {markets?.length ? ( + markets?.map((market) => ( + { + setShowResults(false); + }} > - {market.status === MarketStatus.Active - ? "Active" - : "Inactive"} -
- - )) - ) : ( -
No results
- )} +
+ {market.question} +
+
+ {market.status === MarketStatus.Active + ? "Active" + : "Inactive"} +
+ + )) + ) : ( +
No results
+ )} +
- )} +
); }; From ef75937af676301de5df184b4343fe808e9db678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20Andre=20Tangen=20=40gorillatron?= Date: Wed, 29 Nov 2023 12:05:56 +0100 Subject: [PATCH 2/9] set focus when opening search --- components/markets/MarketSearch.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/markets/MarketSearch.tsx b/components/markets/MarketSearch.tsx index 0d4b4789a..f9ec291e8 100644 --- a/components/markets/MarketSearch.tsx +++ b/components/markets/MarketSearch.tsx @@ -64,7 +64,7 @@ const MarketSearch = () => { e.stopPropagation(); setShowSearch(!showSearch); setTimeout(() => { - if (showSearch) { + if (!showSearch) { inputRef.current?.focus(); } }); From d8c001ba7c4460ce0c261f9bf3e81b376a9be47b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20Andre=20Tangen=20=40gorillatron?= Date: Wed, 29 Nov 2023 12:17:41 +0100 Subject: [PATCH 3/9] remove outline flash on focus and retain focus when clearing --- components/markets/MarketSearch.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/markets/MarketSearch.tsx b/components/markets/MarketSearch.tsx index f9ec291e8..97381cedb 100644 --- a/components/markets/MarketSearch.tsx +++ b/components/markets/MarketSearch.tsx @@ -37,7 +37,7 @@ const MarketSearch = () => { ref={inputRef} className={`h-10 transition-all ${ showSearch ? "max-w-[500px] px-3" : "max-w-[0px]" - } w-full rounded-lg bg-sky-900 text-white focus:outline-none`} + } w-full rounded-lg bg-sky-900 text-white outline-none`} value={searchTerm} placeholder="Search markets" onChange={(event) => { @@ -53,6 +53,7 @@ const MarketSearch = () => { className="relative right-6 text-sky-600" onClick={() => { setSearchTerm(""); + inputRef.current?.focus(); }} > From 517f538c577f1be16db451595291d9f787d9b718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20Andre=20Tangen=20=40gorillatron?= Date: Wed, 29 Nov 2023 12:44:56 +0100 Subject: [PATCH 4/9] mobile market search --- components/markets/MarketSearch.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/components/markets/MarketSearch.tsx b/components/markets/MarketSearch.tsx index 97381cedb..b08d80f89 100644 --- a/components/markets/MarketSearch.tsx +++ b/components/markets/MarketSearch.tsx @@ -45,7 +45,9 @@ const MarketSearch = () => { setSearchTerm(event.target.value); }} onFocus={() => { - setShowResults(true); + if (searchTerm?.length > 0) { + setShowResults(true); + } }} /> {showSearch && ( @@ -53,7 +55,12 @@ const MarketSearch = () => { className="relative right-6 text-sky-600" onClick={() => { setSearchTerm(""); - inputRef.current?.focus(); + if (showResults) { + setShowResults(false); + } + setTimeout(() => { + inputRef.current?.focus(); + }, 66); }} > From 885db18669f85c0c60b38c40bc9b4564b33cb48f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20Andre=20Tangen=20=40gorillatron?= Date: Wed, 29 Nov 2023 12:45:08 +0100 Subject: [PATCH 5/9] Handle focus states and clearing better --- pages/search.tsx | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/pages/search.tsx b/pages/search.tsx index b5ac81916..0eeed287d 100644 --- a/pages/search.tsx +++ b/pages/search.tsx @@ -2,26 +2,33 @@ import { MarketStatus } from "@zeitgeistpm/indexer"; import { useMarketSearch } from "lib/hooks/queries/useMarketSearch"; import { NextPage } from "next"; import Link from "next/link"; -import { useState } from "react"; +import { use, useEffect, useRef, useState } from "react"; import { X } from "react-feather"; const SearchPage: NextPage = () => { const [searchTerm, setSearchTerm] = useState(""); const { data: markets } = useMarketSearch(searchTerm); + const inputRef = useRef(null); + + useEffect(() => { + inputRef?.current?.focus(); + }, [inputRef]); + return ( -
-
+
+
{ setSearchTerm(event.target.value); }} />
{markets && ( -
-
Results
- +
{markets.length > 0 ? ( markets?.map((market) => ( {
{market.status === MarketStatus.Active From 14459ca7bada388bc90f99266519b22a08b9f831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20Andre=20Tangen=20=40gorillatron?= Date: Wed, 29 Nov 2023 13:28:38 +0100 Subject: [PATCH 6/9] Update search.tsx --- pages/search.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pages/search.tsx b/pages/search.tsx index 0eeed287d..c38f494e1 100644 --- a/pages/search.tsx +++ b/pages/search.tsx @@ -12,7 +12,9 @@ const SearchPage: NextPage = () => { const inputRef = useRef(null); useEffect(() => { - inputRef?.current?.focus(); + setTimeout(() => { + inputRef?.current?.focus(); + }, 66); }, [inputRef]); return ( From f712820c7ab55db8f35ba66535277a04ddf2a034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20Andre=20Tangen=20=40gorillatron?= Date: Thu, 30 Nov 2023 12:31:46 +0100 Subject: [PATCH 7/9] indication of typing --- components/markets/MarketSearch.tsx | 74 ++++++++++-------- components/ui/TypingIndicator.tsx | 116 ++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+), 31 deletions(-) create mode 100644 components/ui/TypingIndicator.tsx diff --git a/components/markets/MarketSearch.tsx b/components/markets/MarketSearch.tsx index b08d80f89..7e468cfec 100644 --- a/components/markets/MarketSearch.tsx +++ b/components/markets/MarketSearch.tsx @@ -3,8 +3,11 @@ import { MarketStatus } from "@zeitgeistpm/indexer"; import { useMarketSearch } from "lib/hooks/queries/useMarketSearch"; import Link from "next/link"; import { FaDeleteLeft } from "react-icons/fa6"; -import { Fragment, useEffect, useRef, useState } from "react"; +import { Fragment, RefObject, use, useEffect, useRef, useState } from "react"; import { Search, X } from "react-feather"; +import { AnimatePresence, Variants, motion, useAnimate } from "framer-motion"; +import { TAILWIND } from "lib/constants"; +import { TypingIndicator } from "components/ui/TypingIndicator"; const MarketSearch = () => { const [searchTerm, setSearchTerm] = useState(""); @@ -13,7 +16,7 @@ const MarketSearch = () => { const wrapperRef = useRef(null); const inputRef = useRef(null); - const { data: markets } = useMarketSearch(searchTerm); + const { data: markets, isFetching } = useMarketSearch(searchTerm); useEffect(() => { const handleClickOutside = (event) => { @@ -33,39 +36,48 @@ const MarketSearch = () => {
- { - setShowResults(true); - setSearchTerm(event.target.value); - }} - onFocus={() => { - if (searchTerm?.length > 0) { + }`} + > + { setShowResults(true); - } - }} - /> - {showSearch && ( - - )} + /> + +
+ +
+ + {showSearch && ( + + )} +
{markets && (