Skip to content

Commit

Permalink
Merge branch 'preview'
Browse files Browse the repository at this point in the history
  • Loading branch information
pdelfan committed Feb 3, 2024
2 parents 711b2ee + 08b5de8 commit fa25deb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/components/contentDisplay/searchList/SearchList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { useState } from "react";
import PostSearchContainer from "@/containers/search/PostSearchContainer";
import UserSearchContainer from "@/containers/search/UserSearchContainer";
import { useSession } from "next-auth/react";

interface Props {
query: string;
Expand All @@ -11,22 +12,31 @@ interface Props {
export default function SearchList(props: Props) {
const { query } = props;
const [currenTab, setCurrentTab] = useState<"posts" | "users">("posts");
const { data: session } = useSession();

const handleTabChange = (tab: "posts" | "users") => {
setCurrentTab(tab);
};

const onSearchPost = (query: string) => {
if (query.trim() === "from:me" && session?.user.handle) {
return `from:${session.user.handle}`;
}

return query;
};

return (
<section className="mt-5">
<div
role="tablist"
aria-orientation="horizontal"
className="flex flex-nowrap gap-3 px-3 md:px-0 overflow-auto no-scrollbar"
className="no-scrollbar flex flex-nowrap gap-3 overflow-auto px-3 md:px-0"
>
<button
role="tab"
onClick={() => handleTabChange("posts")}
className={`shrink-0 border-b-3 px-3 pb-2 font-semibold hover:text-primary cursor-pointer ${
className={`border-b-3 hover:text-primary shrink-0 cursor-pointer px-3 pb-2 font-semibold ${
currenTab === "posts"
? "border-primary-600 text-primary border-primary"
: "border-transparent text-neutral-500"
Expand All @@ -37,7 +47,7 @@ export default function SearchList(props: Props) {
<button
role="tab"
onClick={() => handleTabChange("users")}
className={`shrink-0 border-b-3 px-3 pb-2 font-semibold hover:text-primary cursor-pointer ${
className={`border-b-3 hover:text-primary shrink-0 cursor-pointer px-3 pb-2 font-semibold ${
currenTab === "users"
? "border-primary-600 text-primary border-primary"
: "border-transparent text-neutral-500"
Expand All @@ -47,7 +57,9 @@ export default function SearchList(props: Props) {
</button>
</div>

{currenTab === "posts" && <PostSearchContainer query={query} />}
{currenTab === "posts" && (
<PostSearchContainer query={onSearchPost(query)} />
)}
{currenTab === "users" && <UserSearchContainer query={query} />}
</section>
);
Expand Down
2 changes: 1 addition & 1 deletion src/containers/search/PostSearchContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default function PostSearchContainer(props: Props) {
))}
</section>
{isEmpty && !hasNextPage && (
<div className="mx-3 md:mx-0 border-t">
<div className="mx-3 border-t md:mx-0">
<FeedAlert variant="empty" message="No posts found" />
</div>
)}
Expand Down

0 comments on commit fa25deb

Please sign in to comment.