-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# PRの概要 検索機能(現在は、ユーザー名のみの部分一致検索) ## 具体的な変更内容 ## 影響範囲 searchタブ内 ## 動作 https://github.com/user-attachments/assets/61db87ab-a4ad-4fea-8b9c-669745bb9713 ## レビューリクエストを出す前にチェック! - [ ✓] 改めてセルフレビューしたか - [ ✓] 手動での動作検証を行ったか - [ ] server の機能追加ならば、テストを書いたか - 理由: 書いた | server の機能追加ではない - [ ] 間違った使い方が存在するならば、それのドキュメントをコメントで書いたか - 理由: 書いた | 間違った使い方は存在しない - [ ] わかりやすいPRになっているか <!-- レビューリクエスト後は、Slackでもメンションしてお願いすることを推奨します。 --> --------- Co-authored-by: KaichiManabe <[email protected]> Co-authored-by: aster <[email protected]>
- Loading branch information
1 parent
84a13ab
commit 4c60edc
Showing
11 changed files
with
165 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,18 +1,19 @@ | ||
import BottomBar from "~/components/BottomBar"; | ||
import Header from "~/components/Header"; | ||
import { NavigateByAuthState } from "~/components/common/NavigateByAuthState"; | ||
|
||
export default function FriendsPageLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<> | ||
<NavigateByAuthState type="toLoginForUnauthenticated"> | ||
<Header title="フレンド/Friends" /> | ||
<div className="absolute top-14 right-0 bottom-14 left-0 overflow-y-auto sm:top-16"> | ||
{children} | ||
</div> | ||
<BottomBar activeTab="1_friends" /> | ||
</> | ||
</NavigateByAuthState> | ||
); | ||
} |
This file contains 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 |
---|---|---|
@@ -1,18 +1,19 @@ | ||
import BottomBar from "~/components/BottomBar"; | ||
import Header from "~/components/Header"; | ||
import { NavigateByAuthState } from "~/components/common/NavigateByAuthState"; | ||
|
||
export default function HomePageLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<> | ||
<NavigateByAuthState type="toLoginForUnauthenticated"> | ||
<Header title="ホーム/Home" /> | ||
<div className="relative top-14 right-0 bottom-14 left-0 overflow-y-auto sm:top-16"> | ||
{children} | ||
</div> | ||
<BottomBar activeTab="0_home" /> | ||
</> | ||
</NavigateByAuthState> | ||
); | ||
} |
This file contains 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,18 @@ | ||
import BottomBar from "~/components/BottomBar"; | ||
import Header from "~/components/Header"; | ||
|
||
export default function HomePageLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<> | ||
<Header title="検索/Search" /> | ||
<div className="absolute top-14 right-0 bottom-14 left-0 overflow-y-auto sm:top-16"> | ||
{children} | ||
</div> | ||
<BottomBar activeTab="2_search" /> | ||
</> | ||
); | ||
} |
This file contains 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,27 @@ | ||
"use client"; | ||
|
||
import type React from "react"; | ||
import { useState } from "react"; | ||
import Search from "~/components/search/search"; | ||
import Table from "~/components/search/table"; | ||
|
||
export default function SearchPage({ | ||
searchParams, | ||
}: { | ||
searchParams?: { | ||
query?: string; | ||
page?: string; | ||
}; | ||
}) { | ||
const [query, setQuery] = useState<string>(searchParams?.query ?? ""); | ||
|
||
return ( | ||
<div className="flex min-h-screen justify-center "> | ||
<div className="w-full"> | ||
<h2 className="m-5 mb-4 font-bold text-2xl">ユーザー検索</h2> | ||
<Search placeholder="検索" setSearchString={setQuery} /> | ||
<Table query={query} /> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains 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 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 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,39 @@ | ||
"use client"; | ||
|
||
import { usePathname, useSearchParams } from "next/navigation"; | ||
import { MdOutlineSearch } from "react-icons/md"; | ||
|
||
type Props = { placeholder: string; setSearchString: (s: string) => void }; | ||
export default function Search({ placeholder, setSearchString }: Props) { | ||
const searchParams = useSearchParams(); | ||
const pathname = usePathname(); | ||
|
||
function handleSearch(term: string) { | ||
setSearchString(term); | ||
const params = new URLSearchParams(searchParams); | ||
if (term) { | ||
params.set("query", term); | ||
} else { | ||
params.delete("query"); | ||
} | ||
const newUrl = `${pathname}?${params.toString()}`; | ||
history.replaceState(undefined, "", newUrl); | ||
} | ||
|
||
return ( | ||
<div className="relative mr-5 ml-5 flex flex-1 flex-shrink-0"> | ||
<label htmlFor="search" className="sr-only"> | ||
Search | ||
</label> | ||
<input | ||
className=" block w-full rounded-md border border-gray-200 py-[9px] pl-10 text-sm outline-none placeholder:text-gray-500 focus:border-primary focus:ring-1 focus:ring-primary" | ||
placeholder={placeholder} | ||
onChange={(e) => { | ||
handleSearch(e.target.value); | ||
}} | ||
defaultValue={searchParams.get("query")?.toString()} | ||
/> | ||
<MdOutlineSearch className="-translate-y-1/2 absolute top-1/2 left-3 h-[18px] w-[18px] text-gray-500 peer-focus:text-gray-900" /> | ||
</div> | ||
); | ||
} |
This file contains 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,37 @@ | ||
"use client"; | ||
import { useMemo } from "react"; | ||
import { useAll, useMyID } from "~/api/user"; | ||
import { useModal } from "../common/modal/ModalProvider"; | ||
import { HumanListItem } from "../human/humanListItem"; | ||
|
||
export default function UserTable({ query }: { query: string }) { | ||
const { openModal } = useModal(); | ||
const { | ||
state: { data }, | ||
} = useAll(); | ||
const { | ||
state: { data: myId }, | ||
} = useMyID(); | ||
const initialData = useMemo(() => { | ||
return data?.filter((item) => item.id !== myId && item.id !== 0) ?? null; | ||
}, [data, myId]); | ||
const users = query | ||
? initialData?.filter((user) => | ||
user.name.toLowerCase().includes(query.toLowerCase()), | ||
) | ||
: initialData; | ||
|
||
return ( | ||
<div> | ||
{users?.map((user) => ( | ||
<HumanListItem | ||
key={user.id} | ||
id={user.id} | ||
name={user.name} | ||
pictureUrl={user.pictureUrl} | ||
onOpen={() => openModal(user)} | ||
/> | ||
))} | ||
</div> | ||
); | ||
} |
This file contains 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