("");
-
- useEffect(() => {
- router.query.q
- ? setSearchQuery(decodeURIComponent(router.query.q as string))
- : setSearchQuery("");
- }, [router.query.q]);
-
- return (
-
-
-
- {
- e.target.value.includes("%") &&
- toast.error("The search query should not contain '%'.");
- setSearchQuery(e.target.value.replace("%", ""));
- }}
- onKeyDown={(e) => {
- if (e.key === "Enter") {
- if (!searchQuery) {
- return router.push("/public/collections/" + router.query.id);
- }
-
- return router.push(
- "/public/collections/" +
- router.query.id +
- "?q=" +
- encodeURIComponent(searchQuery || "")
- );
- }
- }}
- className="border text-sm border-neutral-content bg-base-200 focus:border-primary rounded-md pl-8 py-2 pr-2 w-44 sm:w-60 md:focus:w-80 duration-100 outline-none"
- />
-
- );
-}
diff --git a/components/SearchBar.tsx b/components/SearchBar.tsx
index 2d80c30..cc390e1 100644
--- a/components/SearchBar.tsx
+++ b/components/SearchBar.tsx
@@ -4,7 +4,11 @@ import { useState } from "react";
import { useRouter } from "next/router";
import { toast } from "react-hot-toast";
-export default function SearchBar() {
+type Props = {
+ placeholder?: string;
+};
+
+export default function SearchBar({ placeholder }: Props) {
const router = useRouter();
const routeQuery = router.query.q;
@@ -17,7 +21,7 @@ export default function SearchBar() {
@@ -25,18 +29,34 @@ export default function SearchBar() {
{
e.target.value.includes("%") &&
toast.error("The search query should not contain '%'.");
setSearchQuery(e.target.value.replace("%", ""));
}}
- onKeyDown={(e) =>
- e.key === "Enter" &&
- router.push("/search?q=" + encodeURIComponent(searchQuery))
- }
- className="border border-neutral-content bg-base-200 focus:border-primary py-2 rounded-md pl-10 pr-2 w-44 sm:w-60 md:focus:w-80 duration-100 outline-none"
+ onKeyDown={(e) => {
+ if (e.key === "Enter") {
+ if (router.pathname.startsWith("/public")) {
+ if (!searchQuery) {
+ return router.push("/public/collections/" + router.query.id);
+ }
+
+ return router.push(
+ "/public/collections/" +
+ router.query.id +
+ "?q=" +
+ encodeURIComponent(searchQuery || "")
+ );
+ } else {
+ return router.push(
+ "/search?q=" + encodeURIComponent(searchQuery)
+ );
+ }
+ }
+ }}
+ className="border border-neutral-content bg-base-200 focus:border-primary py-1 rounded-md pl-9 pr-2 w-44 sm:w-60 md:focus:w-80 duration-100 outline-none"
/>
);
diff --git a/pages/collections/[id].tsx b/pages/collections/[id].tsx
index 587c679..2c6b2ab 100644
--- a/pages/collections/[id].tsx
+++ b/pages/collections/[id].tsx
@@ -14,6 +14,8 @@ import useLinks from "@/hooks/useLinks";
import usePermissions from "@/hooks/usePermissions";
import NoLinksFound from "@/components/NoLinksFound";
import useLocalSettingsStore from "@/store/localSettings";
+import useAccountStore from "@/store/account";
+import getPublicUserData from "@/lib/client/getPublicUserData";
export default function Index() {
const { setModal } = useModalStore();
@@ -40,6 +42,35 @@ export default function Index() {
);
}, [router, collections]);
+ const { account } = useAccountStore();
+
+ const [collectionOwner, setCollectionOwner] = useState({
+ id: null as unknown as number,
+ name: "",
+ username: "",
+ image: "",
+ });
+
+ useEffect(() => {
+ const fetchOwner = async () => {
+ if (activeCollection && activeCollection.ownerId !== account.id) {
+ const owner = await getPublicUserData(
+ activeCollection.ownerId as number
+ );
+ setCollectionOwner(owner);
+ } else if (activeCollection && activeCollection.ownerId === account.id) {
+ setCollectionOwner({
+ id: account.id as number,
+ name: account.name,
+ username: account.username as string,
+ image: account.image as string,
+ });
+ }
+ };
+
+ fetchOwner();
+ }, [activeCollection]);
+
return (
@@ -71,46 +102,46 @@ export default function Index() {
{activeCollection ? (
+ activeCollection &&
+ setModal({
+ modal: "COLLECTION",
+ state: true,
+ method: "UPDATE",
+ isOwner: permissions === true,
+ active: activeCollection,
+ defaultIndex: permissions === true ? 1 : 0,
+ })
+ }
>
-
- setModal({
- modal: "COLLECTION",
- state: true,
- method: "UPDATE",
- isOwner: permissions === true,
- active: activeCollection,
- defaultIndex: permissions === true ? 1 : 0,
- })
- }
- className="hover:opacity-80 duration-100 flex justify-center sm:justify-end items-center w-fit sm:mr-0 sm:ml-auto cursor-pointer"
- >
- {activeCollection?.members
- .sort((a, b) => (a.userId as number) - (b.userId as number))
- .map((e, i) => {
- return (
-
- );
- })
- .slice(0, 4)}
- {activeCollection?.members.length &&
- activeCollection.members.length - 4 > 0 ? (
-
- +{activeCollection?.members?.length - 4}
+ {collectionOwner.id ? (
+
+ ) : undefined}
+ {activeCollection.members
+ .sort((a, b) => (a.userId as number) - (b.userId as number))
+ .map((e, i) => {
+ return (
+
+ );
+ })
+ .slice(0, 3)}
+ {activeCollection.members.length - 3 > 0 ? (
+
+
+ +{activeCollection.members.length - 3}
- ) : null}
-
+
+ ) : null}
- ) : null}
+ ) : undefined}
diff --git a/pages/public/collections/[id].tsx b/pages/public/collections/[id].tsx
index 87a8add..1cd4058 100644
--- a/pages/public/collections/[id].tsx
+++ b/pages/public/collections/[id].tsx
@@ -15,10 +15,10 @@ import ToggleDarkMode from "@/components/ToggleDarkMode";
import getPublicUserData from "@/lib/client/getPublicUserData";
import Image from "next/image";
import Link from "next/link";
-import PublicSearchBar from "@/components/PublicPage/PublicSearchBar";
import FilterSearchDropdown from "@/components/FilterSearchDropdown";
import SortDropdown from "@/components/SortDropdown";
import useLocalSettingsStore from "@/store/localSettings";
+import SearchBar from "@/components/SearchBar";
const cardVariants: Variants = {
offscreen: {
@@ -63,7 +63,6 @@ export default function PublicCollections() {
tags: true,
});
- const [filterDropdown, setFilterDropdown] = useState(false);
const [sortBy, setSortBy] = useState
(Sort.DateNewestFirst);
useLinks({
@@ -200,8 +199,8 @@ export default function PublicCollections() {