-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,230 additions
and
33 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
src/app/posts/_components/PostSearch/SortOptionsSelect.tsx
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,31 @@ | ||
import * as React from "react"; | ||
|
||
import { | ||
Select, | ||
SelectContent, | ||
SelectGroup, | ||
SelectItem, | ||
SelectLabel, | ||
SelectTrigger, | ||
SelectValue, | ||
} from "@/components/ui/select"; | ||
|
||
interface SortOptionsSelectProps { | ||
className?: string; | ||
} | ||
|
||
export function SortOptionsSelect({ className }: SortOptionsSelectProps) { | ||
return ( | ||
<Select> | ||
<SelectTrigger className={className}> | ||
<SelectValue placeholder="Select a fruit" /> | ||
</SelectTrigger> | ||
<SelectContent> | ||
<SelectItem value="liked">Most Liked</SelectItem> | ||
<SelectItem value="popular">Most Popular</SelectItem> | ||
<SelectItem value="new">Newest First</SelectItem> | ||
<SelectItem value="old">Oldest First</SelectItem> | ||
</SelectContent> | ||
</Select> | ||
); | ||
} |
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,66 @@ | ||
"use client"; | ||
import { Input } from "@/components/ui/input"; | ||
import { Button } from "@/components/ui/button"; | ||
import { Search } from "lucide-react"; | ||
import { SortOptionsSelect } from "./SortOptionsSelect"; | ||
import { useMemo, useState } from "react"; | ||
|
||
interface PostSearchProps { | ||
tags: { value: number; label: string }[]; | ||
} | ||
|
||
function PostSearch({ tags }: PostSearchProps) { | ||
const [selectedTagIds, setSelectedTagIds] = useState<number[]>([]); | ||
|
||
const sortedTags = useMemo(() => { | ||
return tags.sort((a, b) => { | ||
if (selectedTagIds.includes(a.value)) { | ||
return -1; | ||
} | ||
return 0; | ||
}); | ||
}, [selectedTagIds]); | ||
|
||
function handleSelectTag(tagId: number) { | ||
setSelectedTagIds((prev) => { | ||
if (prev.includes(tagId)) { | ||
return prev.filter((id) => id !== tagId); | ||
} | ||
return [...prev, tagId]; | ||
}); | ||
} | ||
|
||
return ( | ||
<div className="0:w-full flex max-w-[1080px] flex-col gap-[16px]"> | ||
{/* search with select */} | ||
<div className=" flex justify-between rounded bg-gradient-to-r from-[#4F3ABA] to-[#D94E68] p-[16px] max-sm:flex-col max-sm:gap-[16px]"> | ||
<div className="flex w-full flex-[.55] gap-[8px]"> | ||
<Input placeholder="Search for a post..." /> | ||
<Button variant="outline" className="p-[8px]"> | ||
<Search /> | ||
</Button> | ||
</div> | ||
<SortOptionsSelect className="w-full flex-[.2]" /> | ||
</div> | ||
|
||
{/* tags */} | ||
<div className="flex gap-[8px] overflow-x-auto"> | ||
{sortedTags.map((tag) => ( | ||
<Button | ||
variant={ | ||
selectedTagIds.some((id) => id === tag.value) | ||
? "outline-selected" | ||
: "outline" | ||
} | ||
key={tag.value} | ||
onClick={() => handleSelectTag(tag.value)} | ||
> | ||
{tag.label} | ||
</Button> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export { PostSearch }; |
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,17 +1,22 @@ | ||
import { api } from "@/trpc/server"; | ||
import { PostSearch } from "./_components/PostSearch"; | ||
|
||
export default async function Page() { | ||
const resonse = await api.post.getPosts.query({ | ||
const postsResponse = await api.post.getPosts.query({ | ||
page: 0, | ||
pageSize: 10, | ||
search: "w", | ||
tagIds: [1, 2], | ||
}); | ||
|
||
const tags = await api.post.getAllTags.query(); | ||
|
||
return ( | ||
<section> | ||
<pre>{JSON.stringify(resonse.posts, undefined, 2)}</pre> | ||
{resonse.left} | ||
<main className="flex flex-col items-center px-[16px] py-[62px]"> | ||
<PostSearch tags={tags} /> | ||
<span>{JSON.stringify(postsResponse, undefined, 2)}</span> | ||
{postsResponse.left} | ||
<h1>Working on it cap</h1> | ||
</section> | ||
</main> | ||
); | ||
} |
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
Oops, something went wrong.