2023-04-07 20:10:55 -05:00
|
|
|
import useCollectionStore from "@/store/collections";
|
2023-03-22 18:11:54 -05:00
|
|
|
import useLinkStore from "@/store/links";
|
2023-12-17 00:25:46 -06:00
|
|
|
import {
|
|
|
|
CollectionIncludingMembersAndLinkCount,
|
|
|
|
Sort,
|
|
|
|
ViewMode,
|
|
|
|
} from "@/types/global";
|
2023-02-24 11:32:28 -06:00
|
|
|
import { useRouter } from "next/router";
|
2023-12-17 03:32:59 -06:00
|
|
|
import React, { useEffect, useState } from "react";
|
2023-05-14 10:41:08 -05:00
|
|
|
import MainLayout from "@/layouts/MainLayout";
|
2023-05-27 14:05:07 -05:00
|
|
|
import ProfilePhoto from "@/components/ProfilePhoto";
|
2023-06-14 17:34:54 -05:00
|
|
|
import useLinks from "@/hooks/useLinks";
|
2023-06-22 09:35:02 -05:00
|
|
|
import usePermissions from "@/hooks/usePermissions";
|
2023-07-19 16:49:54 -05:00
|
|
|
import NoLinksFound from "@/components/NoLinksFound";
|
2023-11-24 06:50:16 -06:00
|
|
|
import useLocalSettingsStore from "@/store/localSettings";
|
2023-11-30 05:13:42 -06:00
|
|
|
import useAccountStore from "@/store/account";
|
|
|
|
import getPublicUserData from "@/lib/client/getPublicUserData";
|
2023-12-01 16:44:34 -06:00
|
|
|
import EditCollectionModal from "@/components/ModalContent/EditCollectionModal";
|
|
|
|
import EditCollectionSharingModal from "@/components/ModalContent/EditCollectionSharingModal";
|
|
|
|
import DeleteCollectionModal from "@/components/ModalContent/DeleteCollectionModal";
|
2023-12-21 04:08:56 -06:00
|
|
|
import CardView from "@/components/LinkViews/Layouts/CardView";
|
|
|
|
import ListView from "@/components/LinkViews/Layouts/ListView";
|
2024-01-14 09:09:09 -06:00
|
|
|
import { dropdownTriggerer } from "@/lib/client/utils";
|
2024-02-06 15:46:05 -06:00
|
|
|
import NewCollectionModal from "@/components/ModalContent/NewCollectionModal";
|
2024-04-23 20:48:15 -05:00
|
|
|
import MasonryView from "@/components/LinkViews/Layouts/MasonryView";
|
2024-06-04 15:59:49 -05:00
|
|
|
import getServerSideProps from "@/lib/client/getServerSideProps";
|
|
|
|
import { useTranslation } from "next-i18next";
|
|
|
|
import LinkListOptions from "@/components/LinkListOptions";
|
2023-02-24 11:32:28 -06:00
|
|
|
|
2023-06-09 17:31:14 -05:00
|
|
|
export default function Index() {
|
2024-06-04 15:59:49 -05:00
|
|
|
const { t } = useTranslation();
|
2023-11-24 06:50:16 -06:00
|
|
|
const { settings } = useLocalSettingsStore();
|
|
|
|
|
2023-02-24 11:32:28 -06:00
|
|
|
const router = useRouter();
|
2023-04-07 20:10:55 -05:00
|
|
|
|
2024-06-04 15:59:49 -05:00
|
|
|
const { links } = useLinkStore();
|
2023-04-07 20:10:55 -05:00
|
|
|
const { collections } = useCollectionStore();
|
2023-02-24 11:32:28 -06:00
|
|
|
|
2023-06-14 17:34:54 -05:00
|
|
|
const [sortBy, setSortBy] = useState<Sort>(Sort.DateNewestFirst);
|
2023-05-15 15:45:06 -05:00
|
|
|
|
2023-04-27 18:13:21 -05:00
|
|
|
const [activeCollection, setActiveCollection] =
|
2023-06-16 07:55:21 -05:00
|
|
|
useState<CollectionIncludingMembersAndLinkCount>();
|
2023-05-15 15:45:06 -05:00
|
|
|
|
2023-06-22 09:35:02 -05:00
|
|
|
const permissions = usePermissions(activeCollection?.id as number);
|
|
|
|
|
2023-06-14 17:34:54 -05:00
|
|
|
useLinks({ collectionId: Number(router.query.id), sort: sortBy });
|
2023-05-31 21:43:42 -05:00
|
|
|
|
2023-05-15 15:45:06 -05:00
|
|
|
useEffect(() => {
|
2023-04-07 20:10:55 -05:00
|
|
|
setActiveCollection(
|
|
|
|
collections.find((e) => e.id === Number(router.query.id))
|
|
|
|
);
|
2023-06-13 23:40:23 -05:00
|
|
|
}, [router, collections]);
|
2023-02-24 11:32:28 -06:00
|
|
|
|
2023-11-30 05:13:42 -06:00
|
|
|
const { account } = useAccountStore();
|
|
|
|
|
|
|
|
const [collectionOwner, setCollectionOwner] = useState({
|
|
|
|
id: null as unknown as number,
|
|
|
|
name: "",
|
|
|
|
username: "",
|
|
|
|
image: "",
|
2023-12-19 10:50:43 -06:00
|
|
|
archiveAsScreenshot: undefined as unknown as boolean,
|
2024-03-15 13:41:41 -05:00
|
|
|
archiveAsSinglefile: undefined as unknown as boolean,
|
2023-12-19 10:50:43 -06:00
|
|
|
archiveAsPDF: undefined as unknown as boolean,
|
2023-11-30 05:13:42 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
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,
|
2023-12-19 10:50:43 -06:00
|
|
|
archiveAsScreenshot: account.archiveAsScreenshot as boolean,
|
2024-03-15 13:41:41 -05:00
|
|
|
archiveAsSinglefile: account.archiveAsScreenshot as boolean,
|
2023-12-19 10:50:43 -06:00
|
|
|
archiveAsPDF: account.archiveAsPDF as boolean,
|
2023-11-30 05:13:42 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
fetchOwner();
|
|
|
|
}, [activeCollection]);
|
|
|
|
|
2023-12-01 11:01:56 -06:00
|
|
|
const [editCollectionModal, setEditCollectionModal] = useState(false);
|
2024-02-06 15:46:05 -06:00
|
|
|
const [newCollectionModal, setNewCollectionModal] = useState(false);
|
2023-12-01 11:01:56 -06:00
|
|
|
const [editCollectionSharingModal, setEditCollectionSharingModal] =
|
|
|
|
useState(false);
|
2023-12-01 15:29:17 -06:00
|
|
|
const [deleteCollectionModal, setDeleteCollectionModal] = useState(false);
|
2024-02-10 23:55:00 -06:00
|
|
|
const [editMode, setEditMode] = useState(false);
|
2024-03-06 08:06:38 -06:00
|
|
|
|
2024-02-13 09:55:51 -06:00
|
|
|
useEffect(() => {
|
2024-03-06 08:06:38 -06:00
|
|
|
if (editMode) return setEditMode(false);
|
2024-02-13 09:55:51 -06:00
|
|
|
}, [router]);
|
2024-02-10 16:23:59 -06:00
|
|
|
|
2023-12-17 00:25:46 -06:00
|
|
|
const [viewMode, setViewMode] = useState<string>(
|
2023-12-21 09:55:07 -06:00
|
|
|
localStorage.getItem("viewMode") || ViewMode.Card
|
2023-12-17 00:25:46 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
const linkView = {
|
2023-12-21 09:55:07 -06:00
|
|
|
[ViewMode.Card]: CardView,
|
2023-12-17 00:25:46 -06:00
|
|
|
[ViewMode.List]: ListView,
|
2024-04-23 20:48:15 -05:00
|
|
|
[ViewMode.Masonry]: MasonryView,
|
2023-12-17 00:25:46 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
const LinkComponent = linkView[viewMode];
|
|
|
|
|
2023-03-05 15:03:20 -06:00
|
|
|
return (
|
2023-05-14 10:41:08 -05:00
|
|
|
<MainLayout>
|
2023-11-30 05:55:37 -06:00
|
|
|
<div
|
2023-12-17 23:05:41 -06:00
|
|
|
className="h-[60rem] p-5 flex gap-3 flex-col"
|
2023-11-30 05:55:37 -06:00
|
|
|
style={{
|
2024-02-22 03:15:14 -06:00
|
|
|
backgroundImage: `linear-gradient(${activeCollection?.color}20 10%, ${
|
|
|
|
settings.theme === "dark" ? "#262626" : "#f3f4f6"
|
|
|
|
} 13rem, ${settings.theme === "dark" ? "#171717" : "#ffffff"} 100%)`,
|
2023-11-30 05:55:37 -06:00
|
|
|
}}
|
|
|
|
>
|
2023-12-17 00:25:46 -06:00
|
|
|
{activeCollection && (
|
|
|
|
<div className="flex gap-3 items-start justify-between">
|
2024-02-06 15:46:05 -06:00
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
<i
|
|
|
|
className="bi-folder-fill text-3xl drop-shadow"
|
|
|
|
style={{ color: activeCollection?.color }}
|
|
|
|
></i>
|
2024-02-06 06:44:08 -06:00
|
|
|
|
2024-02-06 15:46:05 -06:00
|
|
|
<p className="sm:text-4xl text-3xl capitalize w-full py-1 break-words hyphens-auto font-thin">
|
|
|
|
{activeCollection?.name}
|
|
|
|
</p>
|
2023-12-17 00:25:46 -06:00
|
|
|
</div>
|
|
|
|
|
2023-12-19 10:50:43 -06:00
|
|
|
<div className="dropdown dropdown-bottom dropdown-end mt-2">
|
2023-12-17 00:25:46 -06:00
|
|
|
<div
|
|
|
|
tabIndex={0}
|
|
|
|
role="button"
|
2024-01-14 09:09:09 -06:00
|
|
|
onMouseDown={dropdownTriggerer}
|
2023-12-17 00:25:46 -06:00
|
|
|
className="btn btn-ghost btn-sm btn-square text-neutral"
|
|
|
|
>
|
2023-12-17 22:32:33 -06:00
|
|
|
<i className="bi-three-dots text-xl" title="More"></i>
|
2023-05-15 15:45:06 -05:00
|
|
|
</div>
|
2023-12-17 00:25:46 -06:00
|
|
|
<ul className="dropdown-content z-[30] menu shadow bg-base-200 border border-neutral-content rounded-box w-52 mt-1">
|
2024-02-11 01:01:52 -06:00
|
|
|
{permissions === true && (
|
2023-12-17 00:25:46 -06:00
|
|
|
<li>
|
|
|
|
<div
|
|
|
|
role="button"
|
|
|
|
tabIndex={0}
|
|
|
|
onClick={() => {
|
|
|
|
(document?.activeElement as HTMLElement)?.blur();
|
|
|
|
setEditCollectionModal(true);
|
|
|
|
}}
|
|
|
|
>
|
2024-06-04 15:59:49 -05:00
|
|
|
{t("edit_collection_info")}
|
2023-12-17 00:25:46 -06:00
|
|
|
</div>
|
|
|
|
</li>
|
2024-02-11 01:01:52 -06:00
|
|
|
)}
|
2023-12-17 00:25:46 -06:00
|
|
|
<li>
|
|
|
|
<div
|
|
|
|
role="button"
|
|
|
|
tabIndex={0}
|
|
|
|
onClick={() => {
|
|
|
|
(document?.activeElement as HTMLElement)?.blur();
|
|
|
|
setEditCollectionSharingModal(true);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{permissions === true
|
2024-06-04 15:59:49 -05:00
|
|
|
? t("share_and_collaborate")
|
|
|
|
: t("view_team")}
|
2023-12-17 00:25:46 -06:00
|
|
|
</div>
|
|
|
|
</li>
|
2024-02-11 01:01:52 -06:00
|
|
|
{permissions === true && (
|
2024-02-06 15:46:05 -06:00
|
|
|
<li>
|
|
|
|
<div
|
|
|
|
role="button"
|
|
|
|
tabIndex={0}
|
|
|
|
onClick={() => {
|
|
|
|
(document?.activeElement as HTMLElement)?.blur();
|
|
|
|
setNewCollectionModal(true);
|
|
|
|
}}
|
|
|
|
>
|
2024-06-04 15:59:49 -05:00
|
|
|
{t("create_subcollection")}
|
2024-02-06 15:46:05 -06:00
|
|
|
</div>
|
|
|
|
</li>
|
2024-02-11 01:01:52 -06:00
|
|
|
)}
|
2023-12-17 00:25:46 -06:00
|
|
|
<li>
|
|
|
|
<div
|
|
|
|
role="button"
|
|
|
|
tabIndex={0}
|
|
|
|
onClick={() => {
|
|
|
|
(document?.activeElement as HTMLElement)?.blur();
|
|
|
|
setDeleteCollectionModal(true);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{permissions === true
|
2024-06-04 15:59:49 -05:00
|
|
|
? t("delete_collection")
|
|
|
|
: t("leave_collection")}
|
2023-12-17 00:25:46 -06:00
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2023-11-30 05:55:37 -06:00
|
|
|
</div>
|
2023-12-17 00:25:46 -06:00
|
|
|
</div>
|
|
|
|
)}
|
2023-05-15 15:45:06 -05:00
|
|
|
|
2024-02-11 01:01:52 -06:00
|
|
|
{activeCollection && (
|
2023-11-30 05:55:37 -06:00
|
|
|
<div className={`min-w-[15rem]`}>
|
|
|
|
<div className="flex gap-1 justify-center sm:justify-end items-center w-fit">
|
2023-05-27 14:05:07 -05:00
|
|
|
<div
|
2023-11-30 05:13:42 -06:00
|
|
|
className="flex items-center btn px-2 btn-ghost rounded-full w-fit"
|
2023-12-01 11:01:56 -06:00
|
|
|
onClick={() => setEditCollectionSharingModal(true)}
|
2023-05-27 14:05:07 -05:00
|
|
|
>
|
2023-11-30 05:13:42 -06:00
|
|
|
{collectionOwner.id ? (
|
2023-12-05 03:39:01 -06:00
|
|
|
<ProfilePhoto
|
|
|
|
src={collectionOwner.image || undefined}
|
|
|
|
name={collectionOwner.name}
|
|
|
|
/>
|
2023-11-30 05:13:42 -06:00
|
|
|
) : undefined}
|
|
|
|
{activeCollection.members
|
|
|
|
.sort((a, b) => (a.userId as number) - (b.userId as number))
|
|
|
|
.map((e, i) => {
|
|
|
|
return (
|
|
|
|
<ProfilePhoto
|
|
|
|
key={i}
|
|
|
|
src={e.user.image ? e.user.image : undefined}
|
|
|
|
className="-ml-3"
|
2023-12-05 03:39:01 -06:00
|
|
|
name={e.user.name}
|
2023-11-30 05:13:42 -06:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.slice(0, 3)}
|
|
|
|
{activeCollection.members.length - 3 > 0 ? (
|
2023-12-05 03:39:01 -06:00
|
|
|
<div className={`avatar drop-shadow-md placeholder -ml-3`}>
|
2023-11-30 05:13:42 -06:00
|
|
|
<div className="bg-base-100 text-neutral rounded-full w-8 h-8 ring-2 ring-neutral-content">
|
|
|
|
<span>+{activeCollection.members.length - 3}</span>
|
2023-05-25 13:45:54 -05:00
|
|
|
</div>
|
2023-11-30 05:13:42 -06:00
|
|
|
</div>
|
|
|
|
) : null}
|
2023-05-25 13:44:08 -05:00
|
|
|
</div>
|
2024-06-04 15:59:49 -05:00
|
|
|
|
|
|
|
<p className="text-neutral text-sm">
|
2024-02-11 01:01:52 -06:00
|
|
|
{activeCollection.members.length > 0 &&
|
2024-06-04 15:59:49 -05:00
|
|
|
activeCollection.members.length === 1
|
|
|
|
? t("by_author_and_other", {
|
|
|
|
author: collectionOwner.name,
|
|
|
|
count: activeCollection.members.length,
|
|
|
|
})
|
|
|
|
: activeCollection.members.length > 0 &&
|
|
|
|
activeCollection.members.length !== 1
|
|
|
|
? t("by_author_and_others", {
|
|
|
|
author: collectionOwner.name,
|
|
|
|
count: activeCollection.members.length,
|
|
|
|
})
|
|
|
|
: t("by_author", {
|
|
|
|
author: collectionOwner.name,
|
|
|
|
})}
|
2023-11-30 05:55:37 -06:00
|
|
|
</p>
|
|
|
|
</div>
|
2023-05-25 13:44:08 -05:00
|
|
|
</div>
|
2024-02-11 01:01:52 -06:00
|
|
|
)}
|
2023-05-15 15:45:06 -05:00
|
|
|
|
2024-02-11 01:01:52 -06:00
|
|
|
{activeCollection?.description && (
|
2023-11-30 05:55:37 -06:00
|
|
|
<p>{activeCollection?.description}</p>
|
2024-02-11 01:01:52 -06:00
|
|
|
)}
|
2023-11-30 05:55:37 -06:00
|
|
|
|
2024-02-06 06:46:57 -06:00
|
|
|
{/* {collections.some((e) => e.parentId === activeCollection.id) ? (
|
2024-02-06 06:44:08 -06:00
|
|
|
<fieldset className="border rounded-md p-2 border-neutral-content">
|
|
|
|
<legend className="text-sm ml-2">Sub-Collections</legend>
|
|
|
|
<div className="flex gap-3">
|
|
|
|
{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>
|
|
|
|
</fieldset>
|
|
|
|
) : undefined} */}
|
|
|
|
|
2023-12-01 11:01:56 -06:00
|
|
|
<div className="divider my-0"></div>
|
2023-11-30 05:55:37 -06:00
|
|
|
|
2024-06-04 15:59:49 -05:00
|
|
|
<LinkListOptions
|
|
|
|
t={t}
|
|
|
|
viewMode={viewMode}
|
|
|
|
setViewMode={setViewMode}
|
|
|
|
sortBy={sortBy}
|
|
|
|
setSortBy={setSortBy}
|
|
|
|
editMode={
|
|
|
|
permissions === true ||
|
|
|
|
permissions?.canUpdate ||
|
|
|
|
permissions?.canDelete
|
|
|
|
? editMode
|
|
|
|
: undefined
|
|
|
|
}
|
|
|
|
setEditMode={
|
|
|
|
permissions === true ||
|
|
|
|
permissions?.canUpdate ||
|
|
|
|
permissions?.canDelete
|
|
|
|
? setEditMode
|
|
|
|
: undefined
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<p>
|
|
|
|
{activeCollection?._count?.links === 1
|
|
|
|
? t("showing_count_result", {
|
|
|
|
count: activeCollection?._count?.links,
|
|
|
|
})
|
|
|
|
: t("showing_count_results", {
|
|
|
|
count: activeCollection?._count?.links,
|
|
|
|
})}
|
|
|
|
</p>
|
|
|
|
</LinkListOptions>
|
2024-02-10 23:55:00 -06:00
|
|
|
|
2023-10-03 06:04:13 -05:00
|
|
|
{links.some((e) => e.collectionId === Number(router.query.id)) ? (
|
2023-12-17 00:25:46 -06:00
|
|
|
<LinkComponent
|
2024-02-10 23:55:00 -06:00
|
|
|
editMode={editMode}
|
2023-12-17 00:25:46 -06:00
|
|
|
links={links.filter(
|
|
|
|
(e) => e.collection.id === activeCollection?.id
|
|
|
|
)}
|
|
|
|
/>
|
2023-07-19 16:49:54 -05:00
|
|
|
) : (
|
|
|
|
<NoLinksFound />
|
|
|
|
)}
|
2023-04-07 20:10:55 -05:00
|
|
|
</div>
|
2024-02-10 00:37:48 -06:00
|
|
|
{activeCollection && (
|
2023-12-01 11:01:56 -06:00
|
|
|
<>
|
2024-02-10 00:37:48 -06:00
|
|
|
{editCollectionModal && (
|
2023-12-01 16:42:45 -06:00
|
|
|
<EditCollectionModal
|
|
|
|
onClose={() => setEditCollectionModal(false)}
|
|
|
|
activeCollection={activeCollection}
|
|
|
|
/>
|
2024-02-10 00:37:48 -06:00
|
|
|
)}
|
|
|
|
{editCollectionSharingModal && (
|
2023-12-01 16:42:45 -06:00
|
|
|
<EditCollectionSharingModal
|
|
|
|
onClose={() => setEditCollectionSharingModal(false)}
|
|
|
|
activeCollection={activeCollection}
|
|
|
|
/>
|
2024-02-10 00:37:48 -06:00
|
|
|
)}
|
|
|
|
{newCollectionModal && (
|
2024-02-06 15:46:05 -06:00
|
|
|
<NewCollectionModal
|
|
|
|
onClose={() => setNewCollectionModal(false)}
|
|
|
|
parent={activeCollection}
|
|
|
|
/>
|
2024-02-10 00:37:48 -06:00
|
|
|
)}
|
|
|
|
{deleteCollectionModal && (
|
2023-12-01 16:42:45 -06:00
|
|
|
<DeleteCollectionModal
|
|
|
|
onClose={() => setDeleteCollectionModal(false)}
|
|
|
|
activeCollection={activeCollection}
|
|
|
|
/>
|
2024-02-10 00:37:48 -06:00
|
|
|
)}
|
2023-12-01 11:01:56 -06:00
|
|
|
</>
|
2024-02-10 00:37:48 -06:00
|
|
|
)}
|
2023-05-14 10:41:08 -05:00
|
|
|
</MainLayout>
|
2023-03-05 15:03:20 -06:00
|
|
|
);
|
2023-02-24 11:32:28 -06:00
|
|
|
}
|
2024-06-04 15:59:49 -05:00
|
|
|
|
|
|
|
export { getServerSideProps };
|