From 3a5ae28f869d4096717f82fc17580f83fcfc4742 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 25 Mar 2023 17:47:34 +0330 Subject: [PATCH] ui improvements --- components/AddLinkModal.tsx | 8 +++---- components/CollectionCard.tsx | 2 +- components/Dropdown.tsx | 6 ++--- components/InputSelect/styles.ts | 2 +- components/LinkList.tsx | 31 ++++++++++++++++++------ components/Navbar.tsx | 32 ++++++++++++++++++------- components/Sidebar/SidebarItem.tsx | 3 +-- components/Sidebar/index.tsx | 19 ++++++++------- lib/api/archive.ts | 14 +++++++++-- lib/api/controllers/links/deleteLink.ts | 15 ++++++++---- lib/api/controllers/links/postLink.ts | 4 ++-- lib/api/controllers/tags/getTags.ts | 9 +++++++ pages/collections/[id].tsx | 4 ++-- pages/collections/index.tsx | 2 +- pages/login.tsx | 6 ++--- pages/register.tsx | 8 +++---- store/links.ts | 7 +++++- 17 files changed, 117 insertions(+), 55 deletions(-) diff --git a/components/AddLinkModal.tsx b/components/AddLinkModal.tsx index 8ba37db..d4f8519 100644 --- a/components/AddLinkModal.tsx +++ b/components/AddLinkModal.tsx @@ -40,7 +40,7 @@ export default function ({ toggleLinkModal }: { toggleLinkModal: Function }) { }; return ( -
+

New Link

@@ -50,7 +50,7 @@ export default function ({ toggleLinkModal }: { toggleLinkModal: Function }) { onChange={(e) => setNewLink({ ...newLink, name: e.target.value })} type="text" placeholder="e.g. Example Link" - className="w-60 rounded p-3 border-sky-100 border-solid border text-sm outline-none focus:border-sky-500 duration-100" + className="w-60 rounded-md p-3 border-sky-100 border-solid border text-sm outline-none focus:border-sky-500 duration-100" />
@@ -61,7 +61,7 @@ export default function ({ toggleLinkModal }: { toggleLinkModal: Function }) { onChange={(e) => setNewLink({ ...newLink, url: e.target.value })} type="text" placeholder="e.g. http://example.com/" - className="w-60 rounded p-3 border-sky-100 border-solid border text-sm outline-none focus:border-sky-500 duration-100" + className="w-60 rounded-md p-3 border-sky-100 border-solid border text-sm outline-none focus:border-sky-500 duration-100" />
@@ -76,7 +76,7 @@ export default function ({ toggleLinkModal }: { toggleLinkModal: Function }) {
diff --git a/components/CollectionCard.tsx b/components/CollectionCard.tsx index 6a682cd..b9efac6 100644 --- a/components/CollectionCard.tsx +++ b/components/CollectionCard.tsx @@ -12,7 +12,7 @@ export default function ({ collection }: { collection: Collection }) { return ( -
+

{collection.name}

diff --git a/components/Dropdown.tsx b/components/Dropdown.tsx index e6d165a..3d64adf 100644 --- a/components/Dropdown.tsx +++ b/components/Dropdown.tsx @@ -19,12 +19,12 @@ export default function ({ onClickOutside, className, items }: Props) { return ( {items.map((e, i) => { const inner = ( -
-
+
+
{React.cloneElement(e.icon, { className: "text-sky-500 w-5 h-5", })} diff --git a/components/InputSelect/styles.ts b/components/InputSelect/styles.ts index 28940b5..81fd567 100644 --- a/components/InputSelect/styles.ts +++ b/components/InputSelect/styles.ts @@ -23,7 +23,7 @@ export const styles: StylesConfig = { ...styles, width: "15rem", border: "1px solid #e0f2fe", - borderRadius: "0.25rem", + borderRadius: "0.375rem", fontSize: "0.875rem", lineHeight: "1.25rem", }), diff --git a/components/LinkList.tsx b/components/LinkList.tsx index 48d7209..b513a26 100644 --- a/components/LinkList.tsx +++ b/components/LinkList.tsx @@ -35,16 +35,32 @@ export default function ({ }); return ( -
+
{ + const target = e.target as HTMLElement; + target.style.opacity = "0"; + }} /> -
+ { + const target = e.target as HTMLElement; + target.style.opacity = "0"; + }} + /> +

{count + 1}.

@@ -87,7 +103,8 @@ export default function ({
setEditDropdown(!editDropdown)} id="edit-dropdown" /> @@ -153,7 +170,7 @@ export default function ({ const target = e.target as HTMLInputElement; if (target.id !== "edit-dropdown") setEditDropdown(false); }} - className="absolute top-10 right-0" + className="absolute top-8 right-0" /> ) : null}
diff --git a/components/Navbar.tsx b/components/Navbar.tsx index 075463b..c5aa529 100644 --- a/components/Navbar.tsx +++ b/components/Navbar.tsx @@ -65,22 +65,38 @@ export default function () { }; return ( -
-
+
+
{pageIcon ? ( ) : null}

{pageName}

-
+ +
+
+ + +
- {linkModal ? ( diff --git a/components/Sidebar/SidebarItem.tsx b/components/Sidebar/SidebarItem.tsx index b1e7f4f..45d9c0f 100644 --- a/components/Sidebar/SidebarItem.tsx +++ b/components/Sidebar/SidebarItem.tsx @@ -1,4 +1,3 @@ -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import Link from "next/link"; import React, { ReactElement } from "react"; @@ -11,7 +10,7 @@ interface SidebarItemProps { export default function ({ text, icon, path }: SidebarItemProps) { return ( -
+
{React.cloneElement(icon, { className: "w-4 text-sky-300", })} diff --git a/components/Sidebar/index.tsx b/components/Sidebar/index.tsx index 8004545..de03dd1 100644 --- a/components/Sidebar/index.tsx +++ b/components/Sidebar/index.tsx @@ -48,10 +48,10 @@ export default function () { }; return ( -
+
setProfileDropdown(!profileDropdown)} id="profile-dropdown" > @@ -84,27 +84,27 @@ export default function () { const target = e.target as HTMLInputElement; if (target.id !== "profile-dropdown") setProfileDropdown(false); }} - className="absolute top-12 left-0" + className="absolute top-10 left-0" /> ) : null}
-
+

All Links

-
+

All Collections

-

Collections

+

Collections

{collectionInput ? ( @@ -122,7 +122,8 @@ export default function () { )}
@@ -139,7 +140,7 @@ export default function () { })}
-

Tags

+

Tags

{tags.map((e, i) => { diff --git a/lib/api/archive.ts b/lib/api/archive.ts index 9dd401c..b4f12f5 100644 --- a/lib/api/archive.ts +++ b/lib/api/archive.ts @@ -1,4 +1,5 @@ import { chromium, devices } from "playwright"; +import { prisma } from "@/lib/api/db"; export default async (url: string, collectionId: number, linkId: number) => { const archivePath = `data/archives/${collectionId}/${linkId}`; @@ -12,9 +13,18 @@ export default async (url: string, collectionId: number, linkId: number) => { await page.goto(url); - await page.pdf({ path: archivePath + ".pdf" }); + const linkExists = await prisma.link.findFirst({ + where: { + id: linkId, + }, + }); - await page.screenshot({ fullPage: true, path: archivePath + ".png" }); + if (linkExists) { + await Promise.all([ + page.pdf({ path: archivePath + ".pdf" }), + page.screenshot({ fullPage: true, path: archivePath + ".png" }), + ]); + } await context.close(); await browser.close(); diff --git a/lib/api/controllers/links/deleteLink.ts b/lib/api/controllers/links/deleteLink.ts index 05ae85d..15f119e 100644 --- a/lib/api/controllers/links/deleteLink.ts +++ b/lib/api/controllers/links/deleteLink.ts @@ -1,12 +1,9 @@ import type { NextApiRequest, NextApiResponse } from "next"; import { prisma } from "@/lib/api/db"; import { Session } from "next-auth"; -import { ExtendedLink, NewLink } from "@/types/global"; -import { existsSync, mkdirSync } from "fs"; -import getTitle from "../../getTitle"; -import archive from "../../archive"; +import { ExtendedLink } from "@/types/global"; +import fs from "fs"; import { Link, UsersAndCollections } from "@prisma/client"; -import AES from "crypto-js/aes"; import hasAccessToCollection from "@/lib/api/hasAccessToCollection"; export default async function ( @@ -42,6 +39,14 @@ export default async function ( }, }); + fs.unlink(`data/archives/${link.collectionId}/${link.id}.pdf`, (err) => { + if (err) console.log(err); + }); + + fs.unlink(`data/archives/${link.collectionId}/${link.id}.png`, (err) => { + if (err) console.log(err); + }); + return res.status(200).json({ response: deleteLink, }); diff --git a/lib/api/controllers/links/postLink.ts b/lib/api/controllers/links/postLink.ts index d333e68..2994843 100644 --- a/lib/api/controllers/links/postLink.ts +++ b/lib/api/controllers/links/postLink.ts @@ -118,7 +118,7 @@ export default async function ( const AES_SECRET = process.env.AES_SECRET as string; - const screenShotHashedPath = AES.encrypt( + const screenshotHashedPath = AES.encrypt( `data/archives/${newLink.collectionId}/${newLink.id}.png`, AES_SECRET ).toString(); @@ -130,7 +130,7 @@ export default async function ( const updatedLink: ExtendedLink = await prisma.link.update({ where: { id: newLink.id }, - data: { screenshotPath: screenShotHashedPath, pdfPath: pdfHashedPath }, + data: { screenshotPath: screenshotHashedPath, pdfPath: pdfHashedPath }, include: { tags: true, collection: true }, }); diff --git a/lib/api/controllers/tags/getTags.ts b/lib/api/controllers/tags/getTags.ts index c0816d3..0fd7bf9 100644 --- a/lib/api/controllers/tags/getTags.ts +++ b/lib/api/controllers/tags/getTags.ts @@ -7,6 +7,15 @@ export default async function ( res: NextApiResponse, session: Session ) { + // tag cleanup + await prisma.tag.deleteMany({ + where: { + links: { + none: {}, + }, + }, + }); + const tags = await prisma.tag.findMany({ where: { collections: { diff --git a/pages/collections/[id].tsx b/pages/collections/[id].tsx index 032e439..cf06f26 100644 --- a/pages/collections/[id].tsx +++ b/pages/collections/[id].tsx @@ -12,8 +12,8 @@ export default function () { return ( // ml-80 -
-

+

+

{linksByCollection.length || 0} Links Found

{linksByCollection.map((e, i) => { diff --git a/pages/collections/index.tsx b/pages/collections/index.tsx index 1b8e76b..8a9dfe6 100644 --- a/pages/collections/index.tsx +++ b/pages/collections/index.tsx @@ -11,7 +11,7 @@ export default function () { return ( // ml-80 -
+
{collections.map((e, i) => { return ; })} diff --git a/pages/login.tsx b/pages/login.tsx index d2e8d5b..5f32162 100644 --- a/pages/login.tsx +++ b/pages/login.tsx @@ -42,17 +42,17 @@ export default function () { placeholder="Email" value={form.email} onChange={(e) => setForm({ ...form, email: e.target.value })} - className="border border-gray-700 rounded block m-2 mx-auto p-2" + className="border border-gray-700 rounded-md block m-2 mx-auto p-2" /> setForm({ ...form, password: e.target.value })} - className="border border-gray-700 rounded block m-2 mx-auto p-2" + className="border border-gray-700 rounded-md block m-2 mx-auto p-2" />
Login diff --git a/pages/register.tsx b/pages/register.tsx index 5ea073d..abae07f 100644 --- a/pages/register.tsx +++ b/pages/register.tsx @@ -57,24 +57,24 @@ export default function () { placeholder="Name" value={form.name} onChange={(e) => setForm({ ...form, name: e.target.value })} - className="border border-gray-700 rounded block m-2 mx-auto p-2" + className="border border-gray-700 rounded-md block m-2 mx-auto p-2" /> setForm({ ...form, email: e.target.value })} - className="border border-gray-700 rounded block m-2 mx-auto p-2" + className="border border-gray-700 rounded-md block m-2 mx-auto p-2" /> setForm({ ...form, password: e.target.value })} - className="border border-gray-700 rounded block m-2 mx-auto p-2" + className="border border-gray-700 rounded-md block m-2 mx-auto p-2" />
Register diff --git a/store/links.ts b/store/links.ts index a9ba598..9fe9db7 100644 --- a/store/links.ts +++ b/store/links.ts @@ -1,5 +1,7 @@ import { create } from "zustand"; import { ExtendedLink, NewLink } from "@/types/global"; +import useTagStore from "./tags"; +import useCollectionStore from "./collections"; type LinkStore = { links: ExtendedLink[]; @@ -34,6 +36,9 @@ const useLinkStore = create()((set) => ({ links: [...state.links, data.response], })); + useTagStore.getState().setTags(); + useCollectionStore.getState().setCollections(); + return response.ok; }, updateLink: (link) => @@ -56,7 +61,7 @@ const useLinkStore = create()((set) => ({ links: state.links.filter((e) => e.id !== link.id), })); - console.log(data); + useTagStore.getState().setTags(); return response.ok; },