2023-05-14 10:41:08 -05:00
|
|
|
import useLinkStore from "@/store/links";
|
2023-12-16 09:11:35 -06:00
|
|
|
import useCollectionStore from "@/store/collections";
|
2023-05-14 10:41:08 -05:00
|
|
|
import useTagStore from "@/store/tags";
|
2023-12-16 09:11:35 -06:00
|
|
|
import MainLayout from "@/layouts/MainLayout";
|
2023-12-21 04:08:56 -06:00
|
|
|
import LinkCard from "@/components/LinkViews/LinkCard";
|
2023-05-14 10:41:08 -05:00
|
|
|
import { useEffect, useState } from "react";
|
2023-06-14 17:34:54 -05:00
|
|
|
import useLinks from "@/hooks/useLinks";
|
2023-10-23 09:45:48 -05:00
|
|
|
import Link from "next/link";
|
|
|
|
import useWindowDimensions from "@/hooks/useWindowDimensions";
|
|
|
|
import React from "react";
|
|
|
|
import { toast } from "react-hot-toast";
|
|
|
|
import { MigrationFormat, MigrationRequest } from "@/types/global";
|
2023-11-09 10:44:49 -06:00
|
|
|
import DashboardItem from "@/components/DashboardItem";
|
2023-12-01 16:44:34 -06:00
|
|
|
import NewLinkModal from "@/components/ModalContent/NewLinkModal";
|
2023-12-16 09:15:56 -06:00
|
|
|
import PageHeader from "@/components/PageHeader";
|
2023-05-14 10:41:08 -05:00
|
|
|
|
2023-06-09 17:31:14 -05:00
|
|
|
export default function Dashboard() {
|
2023-05-14 10:41:08 -05:00
|
|
|
const { collections } = useCollectionStore();
|
|
|
|
const { links } = useLinkStore();
|
|
|
|
const { tags } = useTagStore();
|
|
|
|
|
2023-06-16 08:02:02 -05:00
|
|
|
const [numberOfLinks, setNumberOfLinks] = useState(0);
|
|
|
|
|
2023-11-11 13:57:46 -06:00
|
|
|
const [showLinks, setShowLinks] = useState(3);
|
2023-06-12 13:23:11 -05:00
|
|
|
|
2023-06-15 07:39:30 -05:00
|
|
|
useLinks({ pinnedOnly: true, sort: 0 });
|
2023-06-14 17:34:54 -05:00
|
|
|
|
2023-06-16 08:02:02 -05:00
|
|
|
useEffect(() => {
|
|
|
|
setNumberOfLinks(
|
|
|
|
collections.reduce(
|
2023-06-20 09:39:03 -05:00
|
|
|
(accumulator, collection) =>
|
|
|
|
accumulator + (collection._count as any).links,
|
2023-12-17 22:32:33 -06:00
|
|
|
0
|
|
|
|
)
|
2023-06-16 08:02:02 -05:00
|
|
|
);
|
|
|
|
}, [collections]);
|
|
|
|
|
2023-11-11 13:57:46 -06:00
|
|
|
const handleNumberOfLinksToShow = () => {
|
|
|
|
if (window.innerWidth > 1535) {
|
|
|
|
setShowLinks(6);
|
2023-10-23 09:45:48 -05:00
|
|
|
} else if (window.innerWidth > 1295) {
|
2023-11-11 13:57:46 -06:00
|
|
|
setShowLinks(4);
|
|
|
|
} else setShowLinks(3);
|
2023-10-23 09:45:48 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
const { width } = useWindowDimensions();
|
|
|
|
|
|
|
|
useEffect(() => {
|
2023-11-11 13:57:46 -06:00
|
|
|
handleNumberOfLinksToShow();
|
2023-10-23 09:45:48 -05:00
|
|
|
}, [width]);
|
|
|
|
|
|
|
|
const importBookmarks = async (e: any, format: MigrationFormat) => {
|
|
|
|
const file: File = e.target.files[0];
|
|
|
|
|
|
|
|
if (file) {
|
|
|
|
var reader = new FileReader();
|
|
|
|
reader.readAsText(file, "UTF-8");
|
|
|
|
reader.onload = async function (e) {
|
|
|
|
const load = toast.loading("Importing...");
|
|
|
|
|
|
|
|
const request: string = e.target?.result as string;
|
|
|
|
|
|
|
|
const body: MigrationRequest = {
|
|
|
|
format,
|
|
|
|
data: request,
|
|
|
|
};
|
|
|
|
|
|
|
|
const response = await fetch("/api/v1/migration", {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify(body),
|
|
|
|
});
|
|
|
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
|
|
|
toast.dismiss(load);
|
|
|
|
|
|
|
|
toast.success("Imported the Bookmarks! Reloading the page...");
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
location.reload();
|
|
|
|
}, 2000);
|
|
|
|
};
|
|
|
|
reader.onerror = function (e) {
|
|
|
|
console.log("Error:", e);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-12-01 15:29:17 -06:00
|
|
|
const [newLinkModal, setNewLinkModal] = useState(false);
|
|
|
|
|
2023-05-14 10:41:08 -05:00
|
|
|
return (
|
|
|
|
<MainLayout>
|
2023-09-01 17:04:11 -05:00
|
|
|
<div style={{ flex: "1 1 auto" }} className="p-5 flex flex-col gap-5">
|
2023-12-17 22:32:33 -06:00
|
|
|
<PageHeader
|
|
|
|
icon={"bi-house "}
|
|
|
|
title={"Dashboard"}
|
|
|
|
description={"A brief overview of your data"}
|
|
|
|
/>
|
2023-11-09 10:44:49 -06:00
|
|
|
<div>
|
2023-12-19 10:50:43 -06:00
|
|
|
<div className="flex justify-evenly flex-col xl:flex-row xl:items-center gap-2 xl:w-full h-full rounded-2xl p-8 border border-neutral-content bg-base-200">
|
2023-11-09 10:44:49 -06:00
|
|
|
<DashboardItem
|
|
|
|
name={numberOfLinks === 1 ? "Link" : "Links"}
|
|
|
|
value={numberOfLinks}
|
2023-12-16 09:11:35 -06:00
|
|
|
icon={"bi-link-45deg"}
|
2023-11-09 10:44:49 -06:00
|
|
|
/>
|
2023-05-14 10:41:08 -05:00
|
|
|
|
2023-12-19 10:50:43 -06:00
|
|
|
<div className="divider xl:divider-horizontal"></div>
|
2023-11-09 10:44:49 -06:00
|
|
|
|
|
|
|
<DashboardItem
|
|
|
|
name={collections.length === 1 ? "Collection" : "Collections"}
|
|
|
|
value={collections.length}
|
2023-12-16 09:11:35 -06:00
|
|
|
icon={"bi-folder"}
|
2023-11-09 10:44:49 -06:00
|
|
|
/>
|
|
|
|
|
2023-12-19 10:50:43 -06:00
|
|
|
<div className="divider xl:divider-horizontal"></div>
|
2023-11-09 10:44:49 -06:00
|
|
|
|
|
|
|
<DashboardItem
|
|
|
|
name={tags.length === 1 ? "Tag" : "Tags"}
|
|
|
|
value={tags.length}
|
2023-12-16 09:11:35 -06:00
|
|
|
icon={"bi-hash"}
|
2023-11-09 10:44:49 -06:00
|
|
|
/>
|
2023-05-14 10:41:08 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2023-10-23 09:45:48 -05:00
|
|
|
<div className="flex justify-between items-center">
|
|
|
|
<div className="flex gap-2 items-center">
|
2023-12-19 10:50:43 -06:00
|
|
|
<PageHeader
|
|
|
|
icon={"bi-clock-history"}
|
|
|
|
title={"Recent"}
|
|
|
|
description={"Recently added Links"}
|
|
|
|
/>
|
2023-10-23 09:45:48 -05:00
|
|
|
</div>
|
|
|
|
<Link
|
|
|
|
href="/links"
|
2023-12-16 09:11:35 -06:00
|
|
|
className="flex items-center text-sm text-black/75 dark:text-white/75 gap-2 cursor-pointer"
|
2023-10-23 09:45:48 -05:00
|
|
|
>
|
|
|
|
View All
|
2023-12-19 10:50:43 -06:00
|
|
|
<i className="bi-chevron-right text-sm"></i>
|
2023-10-23 09:45:48 -05:00
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div
|
|
|
|
style={{ flex: "0 1 auto" }}
|
|
|
|
className="flex flex-col 2xl:flex-row items-start 2xl:gap-2"
|
|
|
|
>
|
2023-12-17 01:35:09 -06:00
|
|
|
{links[0] ? (
|
2023-10-23 09:45:48 -05:00
|
|
|
<div className="w-full">
|
|
|
|
<div
|
2023-12-23 18:00:53 -06:00
|
|
|
className={`grid min-[1900px]:grid-cols-4 xl:grid-cols-3 sm:grid-cols-2 grid-cols-1 gap-5 w-full`}
|
2023-10-23 09:45:48 -05:00
|
|
|
>
|
2023-11-11 13:57:46 -06:00
|
|
|
{links.slice(0, showLinks).map((e, i) => (
|
2023-12-17 22:32:33 -06:00
|
|
|
<LinkCard key={i} link={e} count={i} />
|
2023-10-23 09:45:48 -05:00
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div
|
|
|
|
style={{ flex: "1 1 auto" }}
|
2023-11-25 04:54:43 -06:00
|
|
|
className="sky-shadow flex flex-col justify-center h-full border border-solid border-neutral-content w-full mx-auto p-10 rounded-2xl bg-base-200"
|
2023-10-23 09:45:48 -05:00
|
|
|
>
|
2023-11-24 07:39:55 -06:00
|
|
|
<p className="text-center text-2xl">
|
2023-10-23 09:45:48 -05:00
|
|
|
View Your Recently Added Links Here!
|
|
|
|
</p>
|
2023-11-25 04:39:56 -06:00
|
|
|
<p className="text-center mx-auto max-w-96 w-fit text-neutral text-sm mt-2">
|
2023-10-23 09:45:48 -05:00
|
|
|
This section will view your latest added Links across every
|
|
|
|
Collections you have access to.
|
|
|
|
</p>
|
|
|
|
|
2023-11-24 07:39:55 -06:00
|
|
|
<div className="text-center w-full mt-4 flex flex-wrap gap-4 justify-center">
|
2023-10-23 09:45:48 -05:00
|
|
|
<div
|
|
|
|
onClick={() => {
|
2023-12-01 15:29:17 -06:00
|
|
|
setNewLinkModal(true);
|
2023-10-23 09:45:48 -05:00
|
|
|
}}
|
2023-12-19 10:50:43 -06:00
|
|
|
className="inline-flex items-center gap-2 text-sm btn btn-accent dark:border-violet-400 text-white"
|
2023-10-23 09:45:48 -05:00
|
|
|
>
|
2023-12-17 22:32:33 -06:00
|
|
|
<i className="bi-plus-lg text-xl duration-100"></i>
|
2023-12-16 09:11:35 -06:00
|
|
|
<span className="group-hover:opacity-0 text-right duration-100">
|
|
|
|
Add New Link
|
2023-10-23 09:45:48 -05:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
|
2023-12-01 15:29:17 -06:00
|
|
|
<div className="dropdown dropdown-bottom">
|
|
|
|
<div
|
|
|
|
tabIndex={0}
|
|
|
|
role="button"
|
2023-12-16 09:11:35 -06:00
|
|
|
className="inline-flex items-center gap-2 text-sm btn btn-outline btn-neutral"
|
2023-12-01 15:29:17 -06:00
|
|
|
id="import-dropdown"
|
|
|
|
>
|
2023-12-16 09:11:35 -06:00
|
|
|
<i className="bi-cloud-upload text-xl duration-100"></i>
|
2023-12-01 15:29:17 -06:00
|
|
|
<p>Import From</p>
|
|
|
|
</div>
|
2023-12-17 22:32:33 -06:00
|
|
|
<ul className="shadow menu dropdown-content z-[1] bg-base-200 border border-neutral-content rounded-box mt-1 w-60">
|
2023-11-27 15:38:38 -06:00
|
|
|
<li>
|
2023-11-30 03:36:40 -06:00
|
|
|
<label
|
2023-12-01 15:29:17 -06:00
|
|
|
tabIndex={0}
|
|
|
|
role="button"
|
2023-11-30 03:36:40 -06:00
|
|
|
htmlFor="import-linkwarden-file"
|
|
|
|
title="JSON File"
|
|
|
|
>
|
2023-11-27 15:38:38 -06:00
|
|
|
From Linkwarden
|
|
|
|
<input
|
|
|
|
type="file"
|
|
|
|
name="photo"
|
|
|
|
id="import-linkwarden-file"
|
|
|
|
accept=".json"
|
|
|
|
className="hidden"
|
|
|
|
onChange={(e) =>
|
|
|
|
importBookmarks(e, MigrationFormat.linkwarden)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</label>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<label
|
2023-12-01 15:29:17 -06:00
|
|
|
tabIndex={0}
|
|
|
|
role="button"
|
2023-11-27 15:38:38 -06:00
|
|
|
htmlFor="import-html-file"
|
|
|
|
title="HTML File"
|
|
|
|
>
|
|
|
|
From Bookmarks HTML file
|
|
|
|
<input
|
|
|
|
type="file"
|
|
|
|
name="photo"
|
|
|
|
id="import-html-file"
|
|
|
|
accept=".html"
|
|
|
|
className="hidden"
|
|
|
|
onChange={(e) =>
|
|
|
|
importBookmarks(e, MigrationFormat.htmlFile)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</label>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2023-12-01 15:29:17 -06:00
|
|
|
</div>
|
2023-10-23 09:45:48 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
|
2023-08-28 13:03:06 -05:00
|
|
|
<div className="flex justify-between items-center">
|
|
|
|
<div className="flex gap-2 items-center">
|
2023-12-19 10:50:43 -06:00
|
|
|
<PageHeader
|
|
|
|
icon={"bi-pin-angle"}
|
|
|
|
title={"Pinned"}
|
|
|
|
description={"Your pinned Links"}
|
|
|
|
/>
|
2023-08-28 13:03:06 -05:00
|
|
|
</div>
|
2023-11-11 13:57:46 -06:00
|
|
|
<Link
|
|
|
|
href="/links/pinned"
|
2023-12-16 09:11:35 -06:00
|
|
|
className="flex items-center text-sm text-black/75 dark:text-white/75 gap-2 cursor-pointer"
|
2023-11-11 13:57:46 -06:00
|
|
|
>
|
|
|
|
View All
|
2023-12-16 09:11:35 -06:00
|
|
|
<i className="bi-chevron-right text-sm "></i>
|
2023-11-11 13:57:46 -06:00
|
|
|
</Link>
|
2023-08-28 13:03:06 -05:00
|
|
|
</div>
|
2023-06-12 13:23:11 -05:00
|
|
|
|
2023-09-01 17:04:11 -05:00
|
|
|
<div
|
2023-11-11 14:56:45 -06:00
|
|
|
style={{ flex: "1 1 auto" }}
|
2023-10-12 13:59:24 -05:00
|
|
|
className="flex flex-col 2xl:flex-row items-start 2xl:gap-2"
|
2023-09-01 17:04:11 -05:00
|
|
|
>
|
2023-11-11 15:06:50 -06:00
|
|
|
{links.some((e) => e.pinnedBy && e.pinnedBy[0]) ? (
|
2023-10-12 13:59:24 -05:00
|
|
|
<div className="w-full">
|
|
|
|
<div
|
2023-12-23 18:00:53 -06:00
|
|
|
className={`grid min-[1900px]:grid-cols-4 xl:grid-cols-3 sm:grid-cols-2 grid-cols-1 gap-5 w-full`}
|
2023-10-12 13:59:24 -05:00
|
|
|
>
|
|
|
|
{links
|
|
|
|
.filter((e) => e.pinnedBy && e.pinnedBy[0])
|
2023-12-17 22:32:33 -06:00
|
|
|
.map((e, i) => <LinkCard key={i} link={e} count={i} />)
|
2023-11-11 13:57:46 -06:00
|
|
|
.slice(0, showLinks)}
|
2023-10-12 13:59:24 -05:00
|
|
|
</div>
|
2023-08-28 13:03:06 -05:00
|
|
|
</div>
|
2023-07-18 10:34:43 -05:00
|
|
|
) : (
|
2023-09-01 17:04:11 -05:00
|
|
|
<div
|
|
|
|
style={{ flex: "1 1 auto" }}
|
2023-11-25 04:54:43 -06:00
|
|
|
className="sky-shadow flex flex-col justify-center h-full border border-solid border-neutral-content w-full mx-auto p-10 rounded-2xl bg-base-200"
|
2023-09-01 17:04:11 -05:00
|
|
|
>
|
2023-11-24 07:39:55 -06:00
|
|
|
<p className="text-center text-2xl">
|
2023-09-01 17:04:11 -05:00
|
|
|
Pin Your Favorite Links Here!
|
2023-07-18 10:34:43 -05:00
|
|
|
</p>
|
2023-11-25 04:39:56 -06:00
|
|
|
<p className="text-center mx-auto max-w-96 w-fit text-neutral text-sm mt-2">
|
2023-08-28 13:03:06 -05:00
|
|
|
You can Pin your favorite Links by clicking on the three dots on
|
|
|
|
each Link and clicking{" "}
|
|
|
|
<span className="font-semibold">Pin to Dashboard</span>.
|
2023-07-18 10:34:43 -05:00
|
|
|
</p>
|
2023-05-14 10:41:08 -05:00
|
|
|
</div>
|
2023-07-18 10:34:43 -05:00
|
|
|
)}
|
2023-05-14 10:41:08 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-12-01 16:42:45 -06:00
|
|
|
{newLinkModal ? (
|
2023-12-17 22:32:33 -06:00
|
|
|
<NewLinkModal onClose={() => setNewLinkModal(false)} />
|
2023-12-01 16:42:45 -06:00
|
|
|
) : undefined}
|
2023-05-14 10:41:08 -05:00
|
|
|
</MainLayout>
|
|
|
|
);
|
|
|
|
}
|