Skip to content

Commit 2bcb544

Browse files
authored
検索で1文字入力してからユーザを表示 (#706)
1 parent 7cd21c2 commit 2bcb544

File tree

8 files changed

+108
-116
lines changed

8 files changed

+108
-116
lines changed

web/app/chat/components/RoomList.tsx

Lines changed: 77 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { Box, List, Typography } from "@mui/material";
44
import type { RoomOverview } from "common/types";
55
import { useRouter, useSearchParams } from "next/navigation";
6+
import BackgroundText from "~/components/common/BackgroundText";
67
import { HumanListItem } from "~/components/human/humanListItem";
78
import RoomPage from "./RoomPage";
89

@@ -23,93 +24,85 @@ export function RoomList(props: RoomListProps) {
2324
return (
2425
<>
2526
{!friendId ? (
26-
<List disablePadding>
27-
<p
28-
style={{
29-
marginLeft: "40px",
30-
marginRight: "40px",
31-
}}
32-
>
33-
{roomsData && roomsData.length === 0 && (
34-
<>
35-
誰ともマッチングしていません。
36-
<br />
37-
リクエストを送りましょう!
38-
</>
39-
)}
40-
</p>
41-
{roomsData?.map((room) => {
42-
if (room.isDM) {
43-
if (room.matchingStatus === "otherRequest") {
44-
return (
45-
<Box
46-
key={room.friendId}
47-
onClick={(e) => {
48-
e.stopPropagation();
49-
openRoom(room);
50-
}}
51-
>
52-
<HumanListItem
27+
<>
28+
{roomsData && roomsData.length === 0 ? (
29+
<BackgroundText text="まだ誰ともマッチングしていません。リクエストを送りましょう!" />
30+
) : (
31+
<List>
32+
{roomsData?.map((room) => {
33+
if (room.isDM) {
34+
if (room.matchingStatus === "otherRequest") {
35+
return (
36+
<Box
37+
key={room.friendId}
38+
onClick={(e) => {
39+
e.stopPropagation();
40+
openRoom(room);
41+
}}
42+
>
43+
<HumanListItem
44+
key={room.friendId}
45+
id={room.friendId}
46+
name={room.name}
47+
pictureUrl={room.thumbnail}
48+
rollUpName={true}
49+
lastMessage={room.lastMsg?.content}
50+
statusMessage="リクエストを受けました"
51+
unreadCount={room.unreadMessages}
52+
/>
53+
</Box>
54+
);
55+
}
56+
if (room.matchingStatus === "myRequest") {
57+
return (
58+
<Box
59+
key={room.friendId}
60+
onClick={(e) => {
61+
e.stopPropagation();
62+
openRoom(room);
63+
}}
64+
>
65+
<HumanListItem
66+
key={room.friendId}
67+
id={room.friendId}
68+
name={room.name}
69+
pictureUrl={room.thumbnail}
70+
rollUpName={true}
71+
lastMessage={room.lastMsg?.content}
72+
statusMessage="リクエスト中 メッセージを送りましょう!"
73+
unreadCount={room.unreadMessages}
74+
/>
75+
</Box>
76+
);
77+
}
78+
return (
79+
<Box
5380
key={room.friendId}
54-
id={room.friendId}
55-
name={room.name}
56-
pictureUrl={room.thumbnail}
57-
rollUpName={true}
58-
lastMessage={room.lastMsg?.content}
59-
statusMessage="リクエストを受けました"
60-
unreadCount={room.unreadMessages}
61-
/>
62-
</Box>
63-
);
64-
}
65-
if (room.matchingStatus === "myRequest") {
81+
onClick={() => {
82+
openRoom(room);
83+
}}
84+
>
85+
<HumanListItem
86+
key={room.friendId}
87+
id={room.friendId}
88+
name={room.name}
89+
pictureUrl={room.thumbnail}
90+
rollUpName={true}
91+
lastMessage={room.lastMsg?.content}
92+
unreadCount={room.unreadMessages}
93+
/>
94+
</Box>
95+
);
96+
}
6697
return (
67-
<Box
68-
key={room.friendId}
69-
onClick={(e) => {
70-
e.stopPropagation();
71-
openRoom(room);
72-
}}
73-
>
74-
<HumanListItem
75-
key={room.friendId}
76-
id={room.friendId}
77-
name={room.name}
78-
pictureUrl={room.thumbnail}
79-
rollUpName={true}
80-
lastMessage={room.lastMsg?.content}
81-
statusMessage="リクエスト中 メッセージを送りましょう!"
82-
unreadCount={room.unreadMessages}
83-
/>
84-
</Box>
98+
<Typography key={room.roomId} variant="body2" sx={{ mb: 1 }}>
99+
グループチャット: {room.name}
100+
</Typography>
85101
);
86-
}
87-
return (
88-
<Box
89-
key={room.friendId}
90-
onClick={() => {
91-
openRoom(room);
92-
}}
93-
>
94-
<HumanListItem
95-
key={room.friendId}
96-
id={room.friendId}
97-
name={room.name}
98-
pictureUrl={room.thumbnail}
99-
rollUpName={true}
100-
lastMessage={room.lastMsg?.content}
101-
unreadCount={room.unreadMessages}
102-
/>
103-
</Box>
104-
);
105-
}
106-
return (
107-
<Typography key={room.roomId} variant="body2" sx={{ mb: 1 }}>
108-
グループチャット: {room.name}
109-
</Typography>
110-
);
111-
})}
112-
</List>
102+
})}
103+
</List>
104+
)}
105+
</>
113106
) : (
114107
<RoomPage id={Number.parseInt(friendId)} />
115108
)}

web/app/friends/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default function Friends() {
1515
const [activeTab, setActiveTab] = useState("matching");
1616

1717
return (
18-
<div className="relative w-full">
18+
<div className="relative h-full w-full">
1919
<div className="fixed top-12 flex h-10 w-full border-gray-200 border-b bg-white">
2020
<button
2121
type="button"
@@ -43,7 +43,7 @@ export default function Friends() {
4343
</button>
4444
</div>
4545

46-
<div className="pt-10 text-center text-gray-700 text-lg">
46+
<div className="h-full pt-10 text-center text-gray-700 text-lg">
4747
{activeTab === "matching" ? <NoSSRMatchings /> : <NoSSRRequests />}
4848
</div>
4949
</div>

web/app/home/components/NoMoreUser.tsx

Lines changed: 0 additions & 9 deletions
This file was deleted.

web/app/home/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { useAboutMe, useRecommended } from "~/api/user";
1515
import { Card } from "~/components/Card";
1616
import { DraggableCard } from "~/components/DraggableCard";
1717
import FullScreenCircularProgress from "~/components/common/FullScreenCircularProgress";
18-
import NoMoreUser from "./components/NoMoreUser";
18+
import BackgroundText from "../../components/common/BackgroundText";
1919
import PersonDetailedMenu from "./components/PersonDetailedMenu";
2020
import RoundButton from "./components/RoundButton";
2121

@@ -121,7 +121,7 @@ export default function Home() {
121121
return <FullScreenCircularProgress />;
122122
}
123123
if (recommended.size() === 0 && loading === false) {
124-
return <NoMoreUser />;
124+
return <BackgroundText text="「いいね!」を送るユーザーがいません。" />;
125125
}
126126
if (error) throw error;
127127

web/app/search/page.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useAll, useMatched, useMyID, usePendingFromMe } from "~/api/user";
66
import FullScreenCircularProgress from "~/components/common/FullScreenCircularProgress";
77
import Search from "~/components/search/search";
88
import Table from "~/components/search/table";
9+
import BackgroundText from "../../components/common/BackgroundText";
910

1011
export default function SearchPage({
1112
searchParams,
@@ -54,14 +55,17 @@ export default function SearchPage({
5455
);
5556

5657
return (
57-
<div className="flex justify-center">
58-
<div className="w-full">
59-
<h2 className="m-5 mb-4 font-bold text-2xl">ユーザー検索</h2>
60-
<Search placeholder="検索" setSearchString={setQuery} />
61-
{users ? (
62-
<Table users={users} canRequest={canRequest} />
58+
<div className="flex h-full flex-col justify-center gap-2 p-4">
59+
<Search placeholder="検索" setSearchString={setQuery} />
60+
<div className="flex-1">
61+
{query !== "" ? (
62+
users.length > 0 ? (
63+
<Table users={users} canRequest={canRequest} />
64+
) : (
65+
<BackgroundText text="ユーザが見つかりません" />
66+
)
6367
) : (
64-
<span>ユーザーが見つかりません</span>
68+
<BackgroundText text="ユーザ名・授業名・タグ名で検索してみましょう" />
6569
)}
6670
</div>
6771
</div>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function BackgroundText({ text }: { text: string }) {
2+
return (
3+
<div className="flex h-full items-center justify-center px-4 text-center">
4+
<p className="text-2xl text-gray-500">{text}</p>
5+
</div>
6+
);
7+
}

web/components/match/matching.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22
import { deleteMatch } from "~/api/match";
33
import { useMatched } from "~/api/user";
4+
import BackgroundText from "../common/BackgroundText";
45
import FullScreenCircularProgress from "../common/FullScreenCircularProgress";
56
import { useModal } from "../common/modal/ModalProvider";
67
import { HumanListItem } from "../human/humanListItem";
@@ -15,16 +16,14 @@ export default function Matchings() {
1516
if (error) throw error;
1617

1718
return (
18-
<div>
19+
<div className="h-full">
1920
{data && data.length === 0 && (
20-
<p className="p-4 text-lg">
21-
誰ともマッチングしていません。 リクエストを送りましょう!
22-
</p>
21+
<BackgroundText text="まだ誰ともマッチングしていません。リクエストを送りましょう!" />
2322
)}
2423
{current === "loading" ? (
2524
<FullScreenCircularProgress />
2625
) : (
27-
<ul className="mt-4 space-y-4">
26+
<ul className="space-y-4">
2827
{data?.map((matchedUser) =>
2928
matchedUser.id === 0 ? (
3029
//メモ帳

web/components/search/search.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,17 @@ export default function Search({ placeholder, setSearchString }: Props) {
2121
}
2222

2323
return (
24-
<div className="relative mr-5 ml-5 flex flex-1 flex-shrink-0">
25-
<label htmlFor="search" className="sr-only">
26-
Search
27-
</label>
24+
<label className="input input-bordered flex items-center gap-2">
25+
<MdOutlineSearch className="text-gray-500" />
2826
<input
29-
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"
27+
type="text"
28+
className="grow"
3029
placeholder={placeholder}
3130
onChange={(e) => {
3231
handleSearch(e.target.value);
3332
}}
3433
defaultValue={searchParams.get("query")?.toString()}
3534
/>
36-
<MdOutlineSearch className="-translate-y-1/2 absolute top-1/2 left-3 h-[18px] w-[18px] text-gray-500 peer-focus:text-gray-900" />
37-
</div>
35+
</label>
3836
);
3937
}

0 commit comments

Comments
 (0)