-
Notifications
You must be signed in to change notification settings - Fork 1
feat: connect backend via trpc, homepage group search #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+287
−11
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| "use client" | ||
| import { useAsyncDebouncer } from "@tanstack/react-pacer" | ||
| import Image from "next/image" | ||
| import Link from "next/link" | ||
| import { useEffect, useState } from "react" | ||
| import { FiSearch } from "react-icons/fi" | ||
| import telegram from "@/assets/icons/telegram-fill.svg" | ||
| import { Input } from "@/components/ui/input" | ||
| import { cn } from "@/lib/utils" | ||
| import { searchGroups } from "@/queries/groups" | ||
| import type { ApiOutput } from "@/types" | ||
| import { Glass } from "../glass" | ||
| import { Spinner } from "../spinner" | ||
|
|
||
| export function GroupSearch() { | ||
| const [query, setQuery] = useState("") | ||
| const [results, setResults] = useState<ApiOutput["tg"]["groups"]["search"] | null>(null) | ||
|
|
||
| const debouncedSearch = useAsyncDebouncer( | ||
| async (searchTerm: string) => { | ||
| const res = await searchGroups(searchTerm, 20) | ||
| setResults(res) | ||
| }, | ||
| { | ||
| wait: 500, | ||
| }, | ||
| (state) => ({ isLoading: state.isPending || state.isExecuting }) | ||
| ) | ||
|
|
||
| useEffect(() => { | ||
| setResults(null) | ||
| if (query) debouncedSearch.maybeExecute(query) | ||
| }, [query, debouncedSearch.maybeExecute]) | ||
|
|
||
| return ( | ||
| <div className="relative w-full max-w-lg"> | ||
| <Input | ||
| icon={<FiSearch className="h-5 w-5" />} | ||
| type="text" | ||
| placeholder="Find your group" | ||
| aria-label="Find your group" | ||
| containerClassName="w-full" | ||
| className="typo-body-medium" | ||
| value={query} | ||
| onChange={(e) => { | ||
| setQuery(e.target.value) | ||
| }} | ||
| /> | ||
|
|
||
| {query && ( | ||
| <Glass className={cn("absolute top-15 grid w-full overflow-hidden rounded-xl p-0")}> | ||
| <div className="max-h-70 overflow-y-auto"> | ||
| {results && results.count > 0 ? ( | ||
| results?.groups | ||
| .filter((g): g is typeof g & { link: string } => !!g.link) | ||
| .map((g) => ( | ||
| <Link key={g.telegramId} href={g.link} target="_blank"> | ||
| <div className="flex items-center justify-start gap-3 px-4 py-3 text-start hover:bg-background-blur"> | ||
| <Image key="telegram" src={telegram} alt="Telegram" className="size-5" /> | ||
| {g.title} | ||
| </div> | ||
| </Link> | ||
| )) | ||
| ) : ( | ||
| <div className="flex h-12 items-center justify-center px-4"> | ||
| {debouncedSearch.state.isLoading ? ( | ||
| <Spinner className="fill-blue-primary text-blue-primary/20" /> | ||
| ) : ( | ||
| "No group found" | ||
| )} | ||
| </div> | ||
| )} | ||
|
BIA3IA marked this conversation as resolved.
|
||
| </div> | ||
| </Glass> | ||
| )} | ||
| </div> | ||
| ) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Se in results ci fossero gruppi senza link (non so se puó succedere), poi verrebbero filtrati qui senza entrare nell'else e non si vedrebbe né il risultato né il messaggio
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lo avevo detto il coniglio, non avevo visto :)
Comunque, quando i designers faranno il design dovremo comunque cambiarlo