Skip to content

Commit

Permalink
fix(openai-search): loading icon no loading
Browse files Browse the repository at this point in the history
  • Loading branch information
XuHaoJun committed Sep 25, 2024
1 parent e0caa13 commit b2944b5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/app/[lang]/pokedex/OpenAISearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import * as React from "react"
import { useFetchPokemonMquery } from "@/api/query"
import { msg } from "@lingui/macro"
import { useLingui } from "@lingui/react"
import { Loader2, Search } from "lucide-react"
import { Search } from "lucide-react"
import * as R from "remeda"

import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { LoadingSpinner } from "@/components/ui/loading-spinner"

export interface OpenAISearchProps {
mquery?: any
Expand Down Expand Up @@ -34,7 +35,7 @@ export const OpenAISearch = ({ mquery, onChange }: OpenAISearchProps) => {

const sampleQuestions = [
msg`Fairy and Psychic dual-type with at least 125 Special Attack and 100 Special Defense, knowing Psychic or Moonblast.`,
msg`Not a Fire-type, but can Flamethrower, Special Attack is at least 90, Speed is 80 or higher`
msg`Not a Fire-type, but can Flamethrower, Special Attack is at least 90, Speed is 80 or higher`,
]

return (
Expand All @@ -55,13 +56,14 @@ export const OpenAISearch = ({ mquery, onChange }: OpenAISearchProps) => {
disabled={query.isLoading}
/>
<Button disabled={query.isLoading} onClick={() => setEnableQuery(true)}>
{query.isLoading ? <Loader2 /> : <Search />}
{query.isLoading ? <LoadingSpinner /> : <Search />}
</Button>
</div>
<div className="flex gap-1">
<div className="flex flex-wrap gap-1">
{sampleQuestions.map((question, i) => (
<Button
key={`sampleQuestions[${i}]`}
className="md:max-w-[50%] whitespace-normal"
variant="outline"
onClick={() => {
setEnableQuery(true)
Expand Down
6 changes: 5 additions & 1 deletion src/app/[lang]/pokedex/PokedexPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,11 @@ export function PokedexPageBase() {
const { downloadJSON } = useDownloadJSON(data, "pokedex")

if (query.isLoading) {
return <Skeleton className="w-100% h-[500px]" />
return (
<div className="md:container flex flex-col gap-2 py-6">
<Skeleton className="w-100% h-[500px]" />
</div>
)
}

return (
Expand Down
12 changes: 11 additions & 1 deletion src/components/MobileNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export function MobileNav() {
<Icons.logo className="mr-2 h-4 w-4" />
<span className="font-bold">{i18n._(siteConfig.name)}</span>
</MobileLink>

<ScrollArea className="my-4 h-[calc(100vh-8rem)] pb-10 pl-6">
<div className="flex flex-col space-y-3">
<MobileLink
Expand All @@ -55,6 +54,17 @@ export function MobileNav() {
>
<Trans>Type Calculator</Trans>
</MobileLink>
<MobileLink
href="/pokedex"
className={cn(
"transition-colors hover:text-foreground/80",
pathname.startsWith("/pokedex")
? "text-foreground"
: "text-foreground/60"
)}
>
<Trans>Pokédex</Trans>
</MobileLink>
<MobileLink
href="/whos-that-pokemon"
className={cn(
Expand Down
9 changes: 9 additions & 0 deletions src/components/ui/loading-spinner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Loader2 } from "lucide-react"

import { cn } from "@/lib/utils"

const LoadingSpinner = ({ className }: { className?: string }) => {
return <Loader2 className={cn("my-28 animate-spin", className)} />
}

export { LoadingSpinner }

0 comments on commit b2944b5

Please sign in to comment.