Skip to content

Commit 14adca6

Browse files
committed
ユーザー名検索
1 parent 7b253fb commit 14adca6

File tree

3 files changed

+116
-2
lines changed

3 files changed

+116
-2
lines changed

web/app/search/layout.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import BottomBar from "~/components/BottomBar";
2+
import Header from "~/components/Header";
3+
4+
export default function HomePageLayout({
5+
children,
6+
}: {
7+
children: React.ReactNode;
8+
}) {
9+
return (
10+
<>
11+
<Header title="ホーム/Home" />
12+
<div className="absolute top-14 right-0 bottom-14 left-0 overflow-y-auto sm:top-16">
13+
{children}
14+
</div>
15+
<BottomBar activeTab="4_search" />
16+
</>
17+
);
18+
}

web/app/search/page.tsx

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
"use client";
2+
3+
import type React from "react";
4+
import { useEffect, useState } from "react";
5+
import { useRecommended } from "~/api/user";
6+
7+
import { useModal } from "~/components/common/modal/ModalProvider";
8+
import { HumanListItem } from "~/components/human/humanListItem";
9+
10+
const SearchPage: React.FC = () => {
11+
const [searchWord, setSearchWord] = useState("");
12+
const { data: recommended } = useRecommended();
13+
const { openModal } = useModal();
14+
const [users, setUsers] = useState<
15+
| {
16+
id: number;
17+
guid: string;
18+
name: string;
19+
gender: string;
20+
grade: string;
21+
faculty: string;
22+
department: string;
23+
intro: string;
24+
pictureUrl: string;
25+
}[]
26+
| null
27+
>(null);
28+
29+
useEffect(() => {
30+
if (recommended) {
31+
setUsers(recommended);
32+
}
33+
}, [recommended]);
34+
35+
function searchByUserName() {
36+
const filteredUsers = recommended?.filter((user) =>
37+
user.name.toLowerCase().includes(searchWord.toLowerCase()),
38+
);
39+
setUsers(filteredUsers || null);
40+
}
41+
42+
return (
43+
<div className="flex min-h-screen items-center justify-center bg-gray-100">
44+
<div className="card w-96 bg-white p-6 shadow-md">
45+
<h2 className="mb-4 font-bold text-2xl">Search</h2>
46+
47+
<div className="form-control mb-4">
48+
<label htmlFor="searchInput" className="label">
49+
<span className="label-text">Enter search term</span>
50+
</label>
51+
<input
52+
type="text"
53+
value={searchWord}
54+
onChange={(e) => setSearchWord(e.target.value)}
55+
placeholder="Type here"
56+
className="input input-bordered w-full"
57+
/>
58+
</div>
59+
60+
<button
61+
type="button"
62+
onClick={searchByUserName}
63+
className="btn btn-primary w-full"
64+
>
65+
Search
66+
</button>
67+
{users?.map((user) => (
68+
<HumanListItem
69+
key={user.id}
70+
id={user.id}
71+
name={user.name}
72+
pictureUrl={user.pictureUrl}
73+
onOpen={() => openModal(user)}
74+
hasDots
75+
></HumanListItem>
76+
))}
77+
</div>
78+
</div>
79+
);
80+
};
81+
82+
export default SearchPage;

web/components/BottomBar.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import ChatIcon from "@mui/icons-material/Chat";
22
import HomeIcon from "@mui/icons-material/Home";
33
import PeopleIcon from "@mui/icons-material/People";
4+
import SearchIcon from "@mui/icons-material/Search";
45
import SettingsIcon from "@mui/icons-material/Settings";
56
import { BottomNavigation, BottomNavigationAction, Box } from "@mui/material";
67
import Link from "next/link";
78

89
type Props = {
9-
activeTab: "0_home" | "1_friends" | "2_chat" | "3_settings";
10+
activeTab: "0_home" | "1_friends" | "2_chat" | "3_settings" | "4_search";
1011
};
1112

1213
export default function BottomBar(props: Props) {
@@ -58,7 +59,7 @@ export default function BottomBar(props: Props) {
5859
<ChatIcon
5960
sx={{
6061
color:
61-
activeTab === "2_chat" ? "primary.main" : "secondary.main",
62+
activeTab === "2_chat" ? "#primary.main" : "secondary.main",
6263
}}
6364
/>
6465
}
@@ -78,6 +79,19 @@ export default function BottomBar(props: Props) {
7879
/>
7980
}
8081
/>
82+
<BottomNavigationAction
83+
component={Link}
84+
href="/search"
85+
label="Search"
86+
icon={
87+
<SearchIcon
88+
sx={{
89+
color:
90+
activeTab === "4_search" ? "primary.main" : "secondary.main",
91+
}}
92+
/>
93+
}
94+
/>
8195
</BottomNavigation>
8296
</Box>
8397
);

0 commit comments

Comments
 (0)