fully added support for sub-collections
This commit is contained in:
parent
392d98f090
commit
3600f6398a
|
@ -5,17 +5,20 @@ import toast from "react-hot-toast";
|
||||||
import { HexColorPicker } from "react-colorful";
|
import { HexColorPicker } from "react-colorful";
|
||||||
import { Collection } from "@prisma/client";
|
import { Collection } from "@prisma/client";
|
||||||
import Modal from "../Modal";
|
import Modal from "../Modal";
|
||||||
|
import { CollectionIncludingMembersAndLinkCount } from "@/types/global";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onClose: Function;
|
onClose: Function;
|
||||||
|
parent?: CollectionIncludingMembersAndLinkCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function NewCollectionModal({ onClose }: Props) {
|
export default function NewCollectionModal({ onClose, parent }: Props) {
|
||||||
const initial = {
|
const initial = {
|
||||||
|
parentId: parent?.id,
|
||||||
name: "",
|
name: "",
|
||||||
description: "",
|
description: "",
|
||||||
color: "#0ea5e9",
|
color: "#0ea5e9",
|
||||||
};
|
} as Partial<Collection>;
|
||||||
|
|
||||||
const [collection, setCollection] = useState<Partial<Collection>>(initial);
|
const [collection, setCollection] = useState<Partial<Collection>>(initial);
|
||||||
|
|
||||||
|
@ -47,7 +50,14 @@ export default function NewCollectionModal({ onClose }: Props) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal toggleModal={onClose}>
|
<Modal toggleModal={onClose}>
|
||||||
<p className="text-xl font-thin">Create a New Collection</p>
|
{parent?.id ? (
|
||||||
|
<>
|
||||||
|
<p className="text-xl font-thin">New Sub-Collection</p>
|
||||||
|
<p className="capitalize text-sm">For {parent.name}</p>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<p className="text-xl font-thin">Create a New Collection</p>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className="divider mb-3 mt-1"></div>
|
<div className="divider mb-3 mt-1"></div>
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,10 @@ export default async function postCollection(
|
||||||
const checkIfCollectionExists = findCollection?.collections[0];
|
const checkIfCollectionExists = findCollection?.collections[0];
|
||||||
|
|
||||||
if (checkIfCollectionExists)
|
if (checkIfCollectionExists)
|
||||||
return { response: "Collection already exists.", status: 400 };
|
return {
|
||||||
|
response: "Oops! There's already a Collection with that name.",
|
||||||
|
status: 400,
|
||||||
|
};
|
||||||
|
|
||||||
const newCollection = await prisma.collection.create({
|
const newCollection = await prisma.collection.create({
|
||||||
data: {
|
data: {
|
||||||
|
|
|
@ -25,6 +25,7 @@ import CardView from "@/components/LinkViews/Layouts/CardView";
|
||||||
import ListView from "@/components/LinkViews/Layouts/ListView";
|
import ListView from "@/components/LinkViews/Layouts/ListView";
|
||||||
import { dropdownTriggerer } from "@/lib/client/utils";
|
import { dropdownTriggerer } from "@/lib/client/utils";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import NewCollectionModal from "@/components/ModalContent/NewCollectionModal";
|
||||||
|
|
||||||
export default function Index() {
|
export default function Index() {
|
||||||
const { settings } = useLocalSettingsStore();
|
const { settings } = useLocalSettingsStore();
|
||||||
|
@ -83,6 +84,7 @@ export default function Index() {
|
||||||
}, [activeCollection]);
|
}, [activeCollection]);
|
||||||
|
|
||||||
const [editCollectionModal, setEditCollectionModal] = useState(false);
|
const [editCollectionModal, setEditCollectionModal] = useState(false);
|
||||||
|
const [newCollectionModal, setNewCollectionModal] = useState(false);
|
||||||
const [editCollectionSharingModal, setEditCollectionSharingModal] =
|
const [editCollectionSharingModal, setEditCollectionSharingModal] =
|
||||||
useState(false);
|
useState(false);
|
||||||
const [deleteCollectionModal, setDeleteCollectionModal] = useState(false);
|
const [deleteCollectionModal, setDeleteCollectionModal] = useState(false);
|
||||||
|
@ -112,45 +114,15 @@ export default function Index() {
|
||||||
>
|
>
|
||||||
{activeCollection && (
|
{activeCollection && (
|
||||||
<div className="flex gap-3 items-start justify-between">
|
<div className="flex gap-3 items-start justify-between">
|
||||||
<div>
|
<div className="flex items-center gap-2">
|
||||||
<div className="flex items-center gap-2">
|
<i
|
||||||
<i
|
className="bi-folder-fill text-3xl drop-shadow"
|
||||||
className="bi-folder-fill text-3xl drop-shadow"
|
style={{ color: activeCollection?.color }}
|
||||||
style={{ color: activeCollection?.color }}
|
></i>
|
||||||
></i>
|
|
||||||
|
|
||||||
<p className="sm:text-4xl text-3xl capitalize w-full py-1 break-words hyphens-auto font-thin">
|
<p className="sm:text-4xl text-3xl capitalize w-full py-1 break-words hyphens-auto font-thin">
|
||||||
{activeCollection?.name}
|
{activeCollection?.name}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
|
||||||
|
|
||||||
{collections.some((e) => e.parentId === activeCollection.id) ? (
|
|
||||||
<details className="mt-2 mb-2">
|
|
||||||
<summary className="text-sm cursor-pointer select-none">
|
|
||||||
View Sub-Collections
|
|
||||||
</summary>
|
|
||||||
|
|
||||||
<div className="flex gap-3 mt-1 pl-3 ml-1 border-l border-neutral-content">
|
|
||||||
{collections
|
|
||||||
.filter((e) => e.parentId === activeCollection?.id)
|
|
||||||
.map((e, i) => {
|
|
||||||
return (
|
|
||||||
<Link
|
|
||||||
key={i}
|
|
||||||
className="flex gap-1 items-center btn btn-ghost btn-sm"
|
|
||||||
href={`/collections/${e.id}`}
|
|
||||||
>
|
|
||||||
<i
|
|
||||||
className="bi-folder-fill text-2xl drop-shadow"
|
|
||||||
style={{ color: e.color }}
|
|
||||||
></i>
|
|
||||||
<p className="text-xs">{e.name}</p>
|
|
||||||
</Link>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
</details>
|
|
||||||
) : undefined}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="dropdown dropdown-bottom dropdown-end mt-2">
|
<div className="dropdown dropdown-bottom dropdown-end mt-2">
|
||||||
|
@ -191,6 +163,20 @@ export default function Index() {
|
||||||
: "View Team"}
|
: "View Team"}
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
{permissions === true ? (
|
||||||
|
<li>
|
||||||
|
<div
|
||||||
|
role="button"
|
||||||
|
tabIndex={0}
|
||||||
|
onClick={() => {
|
||||||
|
(document?.activeElement as HTMLElement)?.blur();
|
||||||
|
setNewCollectionModal(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Create Sub-Collection
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
) : undefined}
|
||||||
<li>
|
<li>
|
||||||
<div
|
<div
|
||||||
role="button"
|
role="button"
|
||||||
|
@ -318,6 +304,12 @@ export default function Index() {
|
||||||
activeCollection={activeCollection}
|
activeCollection={activeCollection}
|
||||||
/>
|
/>
|
||||||
) : undefined}
|
) : undefined}
|
||||||
|
{newCollectionModal ? (
|
||||||
|
<NewCollectionModal
|
||||||
|
onClose={() => setNewCollectionModal(false)}
|
||||||
|
parent={activeCollection}
|
||||||
|
/>
|
||||||
|
) : undefined}
|
||||||
{deleteCollectionModal ? (
|
{deleteCollectionModal ? (
|
||||||
<DeleteCollectionModal
|
<DeleteCollectionModal
|
||||||
onClose={() => setDeleteCollectionModal(false)}
|
onClose={() => setDeleteCollectionModal(false)}
|
||||||
|
|
Ŝarĝante…
Reference in New Issue