feat: use app router for home search
This commit is contained in:
parent
cc56cacb09
commit
8aedb073f7
|
|
@ -0,0 +1,31 @@
|
||||||
|
import { Hydrate, dehydrate } from "@tanstack/react-query"
|
||||||
|
|
||||||
|
import { SearchInput } from "~/components/common/SearchInput"
|
||||||
|
import { HomeFeed } from "~/components/home/HomeFeed"
|
||||||
|
import { HomeSidebar } from "~/components/home/HomeSidebar"
|
||||||
|
import getQueryClient from "~/lib/query-client"
|
||||||
|
import { prefetchGetShowcase } from "~/queries/home.server"
|
||||||
|
|
||||||
|
async function Search() {
|
||||||
|
const queryClient = getQueryClient()
|
||||||
|
await prefetchGetShowcase(queryClient)
|
||||||
|
const dehydratedState = dehydrate(queryClient)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Hydrate state={dehydratedState}>
|
||||||
|
<section className="pt-24">
|
||||||
|
<div className="max-w-screen-lg px-5 mx-auto flex">
|
||||||
|
<div className="flex-1 min-w-[300px]">
|
||||||
|
<SearchInput />
|
||||||
|
<div className="mt-10">
|
||||||
|
<HomeFeed type="search" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<HomeSidebar hideSearch={true} />
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</Hydrate>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Search
|
||||||
|
|
@ -1,20 +1,22 @@
|
||||||
import { useRouter } from "next/navigation"
|
"use client"
|
||||||
|
|
||||||
|
import { useRouter, useSearchParams } from "next/navigation"
|
||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form"
|
||||||
|
|
||||||
import { useTranslation } from "~/lib/i18n/client"
|
import { useTranslation } from "~/lib/i18n/client"
|
||||||
import { cn } from "~/lib/utils"
|
import { cn } from "~/lib/utils"
|
||||||
|
|
||||||
export const SearchInput: React.FC<{
|
export const SearchInput: React.FC<{
|
||||||
value?: string
|
|
||||||
noBorder?: boolean
|
noBorder?: boolean
|
||||||
onSubmit?: (value?: string) => void
|
onSubmit?: (value?: string) => void
|
||||||
}> = ({ value, noBorder, onSubmit }) => {
|
}> = ({ noBorder, onSubmit }) => {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const searchParams = useSearchParams()
|
||||||
const { t } = useTranslation("common")
|
const { t } = useTranslation("common")
|
||||||
|
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
content: value || "",
|
content: searchParams?.get("q") || "",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter, useSearchParams } from "next/navigation"
|
||||||
import { memo, useEffect, useState } from "react"
|
import { memo, useEffect, useState } from "react"
|
||||||
import reactStringReplace from "react-string-replace"
|
import reactStringReplace from "react-string-replace"
|
||||||
import { Virtuoso } from "react-virtuoso"
|
import { Virtuoso } from "react-virtuoso"
|
||||||
|
|
@ -164,10 +164,12 @@ const MemoedPost = memo(Post)
|
||||||
export const HomeFeed: React.FC<{
|
export const HomeFeed: React.FC<{
|
||||||
noteIds?: string[]
|
noteIds?: string[]
|
||||||
keyword?: string
|
keyword?: string
|
||||||
}> = ({ noteIds, keyword }) => {
|
type?: FeedType
|
||||||
|
}> = ({ noteIds, keyword, type }) => {
|
||||||
const { t } = useTranslation("common")
|
const { t } = useTranslation("common")
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
|
||||||
const [feedType, setFeedType] = useState<FeedType>("latest")
|
const [feedType, setFeedType] = useState<FeedType>(type || "latest")
|
||||||
|
|
||||||
const currentCharacterId = useAccountState(
|
const currentCharacterId = useAccountState(
|
||||||
(s) => s.computed.account?.characterId,
|
(s) => s.computed.account?.characterId,
|
||||||
|
|
@ -181,7 +183,7 @@ export const HomeFeed: React.FC<{
|
||||||
characterId: currentCharacterId,
|
characterId: currentCharacterId,
|
||||||
noteIds: noteIds,
|
noteIds: noteIds,
|
||||||
daysInterval: hotInterval,
|
daysInterval: hotInterval,
|
||||||
searchKeyword: keyword,
|
searchKeyword: searchParams?.get("q") || undefined,
|
||||||
searchType,
|
searchType,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -318,7 +320,7 @@ export const HomeFeed: React.FC<{
|
||||||
key={`${post.characterId}-${post.noteId}`}
|
key={`${post.characterId}-${post.noteId}`}
|
||||||
post={post}
|
post={post}
|
||||||
filtering={aiFiltering ? 60 : 0}
|
filtering={aiFiltering ? 60 : 0}
|
||||||
keyword={keyword}
|
keyword={searchParams?.get("q") || undefined}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue