Skip to content

Commit 1a271c9

Browse files
committed
home画面のタグ表示
1 parent 829f695 commit 1a271c9

File tree

3 files changed

+70
-33
lines changed

3 files changed

+70
-33
lines changed

client/src/app/user/home/page.tsx

+23-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import CardTag from "@/components/tags/card-tag";
44
import { getTags } from "@/components/tags/hooks/get-tags";
55
import { Input } from "@/components/ui/input";
6-
import { ScrollArea } from "@/components/ui/scroll-area";
6+
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
77
import { Community } from "@/features/account/types/community";
88
import { CommunityCard } from "@/features/home/user/components/CommunityCard";
99
import { GetCommunities } from "@/features/home/user/hooks/gets-communities";
@@ -20,6 +20,11 @@ export default function Home() {
2020
const [tags, setTags] = useState<TagType[]>([]);
2121
const [selectedTags, setSelectedTags] = useState<TagType[]>([]);
2222
const isFirstRender = useRef(true);
23+
const [searchQueryTag, setSearchQueryTag] = useState("");
24+
25+
const filteredTags = tags?.filter(tag =>
26+
tag.name.toLowerCase().includes(searchQueryTag.toLowerCase())
27+
);
2328

2429
useEffect(() => {
2530
if (isFirstRender.current) {
@@ -82,13 +87,23 @@ export default function Home() {
8287

8388
<div className="bg-[#FFFFFF1A] p-4 rounded-md mb-6">
8489
<h1 className="text-xl font-bold text-[#FFFFFFD0] mb-2">タグで絞り込む</h1>
85-
<div className="flex flex-wrap gap-2">
86-
{tags?.map(tag => (
87-
<CardTag key={tag.name} variant={tag.color} onClick={() => handleTagClick(tag)}>
88-
{tag.name}
89-
</CardTag>
90-
))}
91-
</div>
90+
<Input
91+
type="text"
92+
placeholder="タグ名で検索..."
93+
value={searchQueryTag}
94+
onChange={(e) => setSearchQueryTag(e.target.value)}
95+
className="mb-4"
96+
/>
97+
<ScrollArea className="w-full whitespace-nowrap rounded-md gap-1">
98+
<div className="flex w-max space-x-4 p-4">
99+
{filteredTags?.map(tag => (
100+
<CardTag key={tag.name} variant={tag.color} onClick={() => handleTagClick(tag)}>
101+
{tag.name}
102+
</CardTag>
103+
))}
104+
</div>
105+
<ScrollBar orientation="horizontal" />
106+
</ScrollArea>
92107
</div>
93108

94109
<ScrollArea className={styles.communityContainer}>
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import CardTag from "@/components/tags/card-tag";
22
import { TagType } from "@/features/tags/types/tag";
3+
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
4+
import { Input } from "@/components/ui/input";
5+
import { useState } from "react";
36
import style from "../styles/search-tags.module.scss";
47

58
type SearchTagsProps = {
@@ -8,16 +11,32 @@ type SearchTagsProps = {
811
};
912

1013
export function SearchTags({ tags, handleTagClick }: SearchTagsProps) {
14+
const [searchQuery, setSearchQuery] = useState("");
15+
16+
const filteredTags = tags?.filter(tag =>
17+
tag.name.toLowerCase().includes(searchQuery.toLowerCase())
18+
);
19+
1120
return (
1221
<div className={style.container}>
1322
<h1 className={style.title}>タグで絞り込む</h1>
14-
<div className={style.tags}>
15-
{tags?.map(tag => (
16-
<CardTag key={tag.name} variant={tag.color} onClick={() => handleTagClick(tag)}>
17-
{tag.name}
18-
</CardTag>
19-
))}
20-
</div>
23+
<Input
24+
type="text"
25+
placeholder="タグ名で検索..."
26+
value={searchQuery}
27+
onChange={(e) => setSearchQuery(e.target.value)}
28+
className="mb-4"
29+
/>
30+
<ScrollArea className="w-full whitespace-nowrap rounded-md border gap-1">
31+
<div className="flex w-max space-x-4 p-4">
32+
{filteredTags?.map(tag => (
33+
<CardTag key={tag.name} variant={tag.color} onClick={() => handleTagClick(tag)}>
34+
{tag.name}
35+
</CardTag>
36+
))}
37+
</div>
38+
<ScrollBar orientation="horizontal" />
39+
</ScrollArea>
2140
</div>
2241
);
23-
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
@use "@/styles/theme";
22

3-
43
.container {
5-
background-color: theme.$theme-community-sub;
6-
padding: 1rem;
7-
border-radius: 0.5rem;
8-
margin: 1rem 0;
9-
}
4+
background-color: theme.$theme-community-sub;
5+
padding: 1rem;
6+
border-radius: 0.5rem;
7+
margin: 1rem 0;
8+
}
9+
10+
.title {
11+
font-size: 1.25rem;
12+
font-weight: bold;
13+
color: black;
14+
margin-bottom: 0.5rem;
15+
}
1016

11-
.title {
12-
font-size: 1.25rem;
13-
font-weight: bold;
14-
color: black;
15-
margin-bottom: 0.5rem;
16-
}
17+
.tags {
18+
overflow-x: auto;
19+
white-space: nowrap;
20+
}
1721

18-
.tags {
19-
display: flex;
20-
flex-wrap: wrap;
21-
gap: 0.5rem;
22-
}
22+
.tagsContainer {
23+
display: inline-flex;
24+
gap: 0.5rem;
25+
}

0 commit comments

Comments
 (0)