Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/api/gfi-issues-webhook/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const LABELS_TO_EMOJI = {
const GFI_LABEL = "good first issue"

export async function POST(req: Request) {

const { action, label, issue } = await req.json()

if (action !== "labeled") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useEffect, useRef, useState } from "react"
import { useLocale } from "next-intl"

import { FilterInputState, Lang } from "@/lib/types"

import Input from "@/components/ui/input"
import {
Select,
SelectContent,
Expand Down Expand Up @@ -34,15 +36,31 @@ const FindWalletLanguageSelectInput = ({
updateFilterState,
}: FindWalletLanguageSelectInputProps) => {
const locale = useLocale()
const [searchQuery, setSearchQuery] = useState("")
const [isSelectOpen, setIsSelectOpen] = useState(false)
const searchInputRef = useRef<HTMLInputElement>(null)
const { t } = useTranslation("page-wallets-find-wallet")
const languageCountWalletsData = getLanguageCountWalletsData(locale as string)
const countSortedLanguagesCount = languageCountWalletsData.sort(
const countSortedLanguagesCount = [...languageCountWalletsData].sort(
(a, b) => b.count - a.count
)

useEffect(() => {
if (isSelectOpen) {
//Delay focus to ensure input is rendered
const frame = requestAnimationFrame(() => {
searchInputRef.current?.focus()
})

return () => clearTimeout(frame)
}
}, [isSelectOpen])

return (
<div className="flex flex-col gap-2">
<Select
open={isSelectOpen}
onOpenChange={setIsSelectOpen}
value={inputState as string}
onValueChange={(e: Lang) => {
trackCustomEvent({
Expand All @@ -51,15 +69,58 @@ const FindWalletLanguageSelectInput = ({
eventName: getLanguageCodeName(e, locale!),
})
updateFilterState(filterIndex, itemIndex, e)
setSearchQuery("") // Reset search when selection is made
}}
>
<SelectTrigger className="w-full">
<SelectValue />
</SelectTrigger>
<SelectContent>
<div
className="sticky -top-2 z-10 bg-background p-2"
onKeyDown={(e) => e.stopPropagation()}
onClick={(e) => e.stopPropagation()}
>
<Input
ref={searchInputRef}
type="search"
placeholder={t("page-find-wallet-search-languages")}
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
onKeyDown={(e) => {
if (e.key !== "Enter") return

const selectedLanguage = languageCountWalletsData.find((lang) =>
lang.name.toLowerCase().includes(searchQuery.toLowerCase())
)
if (!selectedLanguage) return

trackCustomEvent({
eventCategory: "WalletFilterSidebar",
eventAction: "Language search",
eventName: selectedLanguage.name,
})
updateFilterState(
filterIndex,
itemIndex,
selectedLanguage.langCode
)
setIsSelectOpen(false)
setSearchQuery("")
}}
className="w-full"
/>
</div>
{languageCountWalletsData.map((language) => {
const isVisible = language.name
.toLowerCase()
.includes(searchQuery.toLowerCase())
return (
<SelectItem key={language.langCode} value={language.langCode}>
<SelectItem
key={language.langCode}
value={language.langCode}
className={!isVisible ? "hidden" : ""}
>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using hidden here instead of filtering the array directly, to avoid SelectValue losing its value and in turn leads to Input losing focus when searchQuery changes

{`${language.name} (${language.count})`}
</SelectItem>
)
Expand Down
5 changes: 3 additions & 2 deletions src/intl/en/page-wallets-find-wallet.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
"page-find-wallet-social-links": "Links",
"page-find-wallet-empty-results-title": "No results",
"page-find-wallet-empty-results-desc": "There are no wallets matching your criteria, try removing some filters.",
"page-find-wallet-see-wallets": "See wallets",
"page-find-wallet-privacy": "Privacy",
"page-find-wallet-privacy-desc": "Wallets that support built-in private transactions"
"page-find-wallet-privacy-desc": "Wallets that support built-in private transactions",
"page-find-wallet-see-wallets": "See wallets",
"page-find-wallet-search-languages": "Search languages..."
}