diff --git a/components/LinkCard.tsx b/components/LinkCard.tsx index 9140216..89396d5 100644 --- a/components/LinkCard.tsx +++ b/components/LinkCard.tsx @@ -15,6 +15,7 @@ import Dropdown from "./Dropdown"; import useLinkStore from "@/store/links"; import Link from "next/link"; import useCollectionStore from "@/store/collections"; +import useAccountStore from "@/store/account"; import useModalStore from "@/store/modals"; type Props = { @@ -30,6 +31,8 @@ export default function LinkCard({ link, count, className }: Props) { const { collections } = useCollectionStore(); + const { account } = useAccountStore(); + const [collection, setCollection] = useState( collections.find( (e) => e.id === link.collection.id @@ -44,7 +47,7 @@ export default function LinkCard({ link, count, className }: Props) { ); }, [collections]); - const { removeLink } = useLinkStore(); + const { removeLink, updateLink } = useLinkStore(); const url = new URL(link.url); const formattedDate = new Date(link.createdAt as string).toLocaleString( @@ -66,7 +69,7 @@ export default function LinkCard({ link, count, className }: Props) { width={42} height={42} alt="" - className="select-none mt-3 z-10 rounded-full shadow border-[3px] border-white bg-white" + className="select-none mt-3 z-10 rounded-full shadow border-[3px] border-white bg-white aspect-square" draggable="false" onError={(e) => { const target = e.target as HTMLElement; @@ -129,7 +132,7 @@ export default function LinkCard({ link, count, className }: Props) { className="group/url" >
-

{url.host}

+

{url.host}

{ + updateLink({ + ...link, + pinnedBy: + link?.pinnedBy && link.pinnedBy[0] + ? undefined + : [{ id: account.id }], + }); + setExpandDropdown(false); + }, + }, { name: "Edit", onClick: () => { diff --git a/components/Modal/LinkModal.tsx b/components/Modal/LinkModal.tsx index cbe3b9f..74e5db5 100644 --- a/components/Modal/LinkModal.tsx +++ b/components/Modal/LinkModal.tsx @@ -37,8 +37,6 @@ export default function EditLink({ name: "", url: "", title: "", - screenshotPath: "", - pdfPath: "", tags: [], collection: { name: "", diff --git a/components/ProfilePhoto.tsx b/components/ProfilePhoto.tsx index b4407a5..17d8c5d 100644 --- a/components/ProfilePhoto.tsx +++ b/components/ProfilePhoto.tsx @@ -33,9 +33,9 @@ export default function ProfilePhoto({ return error || !src ? (
- +
) : ( ); } diff --git a/components/PublicPage/LinkCard.tsx b/components/PublicPage/LinkCard.tsx index dc06d05..a71b04f 100644 --- a/components/PublicPage/LinkCard.tsx +++ b/components/PublicPage/LinkCard.tsx @@ -7,7 +7,7 @@ import Image from "next/image"; import { Link as LinkType } from "@prisma/client"; type Props = { - link: Omit; + link: LinkType; count: number; }; diff --git a/lib/api/controllers/links/getLinks.ts b/lib/api/controllers/links/getLinks.ts index d85a010..3d10f73 100644 --- a/lib/api/controllers/links/getLinks.ts +++ b/lib/api/controllers/links/getLinks.ts @@ -20,6 +20,10 @@ export default async function getLink(userId: number) { include: { tags: true, collection: true, + pinnedBy: { + where: { id: userId }, + select: { id: true }, + }, }, }); diff --git a/lib/api/controllers/links/updateLink.ts b/lib/api/controllers/links/updateLink.ts index ad323db..4e8f765 100644 --- a/lib/api/controllers/links/updateLink.ts +++ b/lib/api/controllers/links/updateLink.ts @@ -64,10 +64,18 @@ export default async function updateLink( }, })), }, + pinnedBy: + link?.pinnedBy && link.pinnedBy[0] + ? { connect: { id: userId } } + : { disconnect: { id: userId } }, }, include: { tags: true, collection: true, + pinnedBy: { + where: { id: userId }, + select: { id: true }, + }, }, }); diff --git a/pages/dashboard.tsx b/pages/dashboard.tsx index 6a04047..021e226 100644 --- a/pages/dashboard.tsx +++ b/pages/dashboard.tsx @@ -102,7 +102,7 @@ export default function Dashboard() {
-
+
{ setLinkPinDisclosure(!linkPinDisclosure); @@ -131,15 +131,17 @@ export default function Dashboard() { leaveTo="transform opacity-0 -translate-y-3" > - {links.slice(0, 5).map((e, i) => ( - - ))} + {links + .filter((e) => e.pinnedBy && e.pinnedBy[0]) + .map((e, i) => ( + + ))}
- + {/*
{ @@ -174,9 +176,9 @@ export default function Dashboard() {
-
+
*/} - + {/*
{ @@ -217,7 +219,7 @@ export default function Dashboard() {
-
+
*/}
diff --git a/prisma/migrations/20230613142801_init/migration.sql b/prisma/migrations/20230613191848_init/migration.sql similarity index 67% rename from prisma/migrations/20230613142801_init/migration.sql rename to prisma/migrations/20230613191848_init/migration.sql index 8f5a1af..e882db8 100644 --- a/prisma/migrations/20230613142801_init/migration.sql +++ b/prisma/migrations/20230613191848_init/migration.sql @@ -24,33 +24,6 @@ CREATE TABLE "Collection" ( CONSTRAINT "Collection_pkey" PRIMARY KEY ("id") ); --- CreateTable -CREATE TABLE "PinnedCollections" ( - "id" SERIAL NOT NULL, - "userId" INTEGER NOT NULL, - "collectionId" INTEGER NOT NULL, - - CONSTRAINT "PinnedCollections_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "PinnedLinks" ( - "id" SERIAL NOT NULL, - "userId" INTEGER NOT NULL, - "linkId" INTEGER NOT NULL, - - CONSTRAINT "PinnedLinks_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "PinnedTags" ( - "id" SERIAL NOT NULL, - "userId" INTEGER NOT NULL, - "tagId" INTEGER NOT NULL, - - CONSTRAINT "PinnedTags_pkey" PRIMARY KEY ("id") -); - -- CreateTable CREATE TABLE "UsersAndCollections" ( "userId" INTEGER NOT NULL, @@ -83,6 +56,12 @@ CREATE TABLE "Tag" ( CONSTRAINT "Tag_pkey" PRIMARY KEY ("id") ); +-- CreateTable +CREATE TABLE "_LinkToUser" ( + "A" INTEGER NOT NULL, + "B" INTEGER NOT NULL +); + -- CreateTable CREATE TABLE "_LinkToTag" ( "A" INTEGER NOT NULL, @@ -98,6 +77,12 @@ CREATE UNIQUE INDEX "Collection_name_ownerId_key" ON "Collection"("name", "owner -- CreateIndex CREATE UNIQUE INDEX "Tag_name_ownerId_key" ON "Tag"("name", "ownerId"); +-- CreateIndex +CREATE UNIQUE INDEX "_LinkToUser_AB_unique" ON "_LinkToUser"("A", "B"); + +-- CreateIndex +CREATE INDEX "_LinkToUser_B_index" ON "_LinkToUser"("B"); + -- CreateIndex CREATE UNIQUE INDEX "_LinkToTag_AB_unique" ON "_LinkToTag"("A", "B"); @@ -107,24 +92,6 @@ CREATE INDEX "_LinkToTag_B_index" ON "_LinkToTag"("B"); -- AddForeignKey ALTER TABLE "Collection" ADD CONSTRAINT "Collection_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; --- AddForeignKey -ALTER TABLE "PinnedCollections" ADD CONSTRAINT "PinnedCollections_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "PinnedCollections" ADD CONSTRAINT "PinnedCollections_collectionId_fkey" FOREIGN KEY ("collectionId") REFERENCES "Collection"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "PinnedLinks" ADD CONSTRAINT "PinnedLinks_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "PinnedLinks" ADD CONSTRAINT "PinnedLinks_linkId_fkey" FOREIGN KEY ("linkId") REFERENCES "Link"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "PinnedTags" ADD CONSTRAINT "PinnedTags_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "PinnedTags" ADD CONSTRAINT "PinnedTags_tagId_fkey" FOREIGN KEY ("tagId") REFERENCES "Tag"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - -- AddForeignKey ALTER TABLE "UsersAndCollections" ADD CONSTRAINT "UsersAndCollections_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; @@ -137,6 +104,12 @@ ALTER TABLE "Link" ADD CONSTRAINT "Link_collectionId_fkey" FOREIGN KEY ("collect -- AddForeignKey ALTER TABLE "Tag" ADD CONSTRAINT "Tag_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; +-- AddForeignKey +ALTER TABLE "_LinkToUser" ADD CONSTRAINT "_LinkToUser_A_fkey" FOREIGN KEY ("A") REFERENCES "Link"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_LinkToUser" ADD CONSTRAINT "_LinkToUser_B_fkey" FOREIGN KEY ("B") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + -- AddForeignKey ALTER TABLE "_LinkToTag" ADD CONSTRAINT "_LinkToTag_A_fkey" FOREIGN KEY ("A") REFERENCES "Link"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 37503c7..4607fad 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -14,9 +14,9 @@ model User { password String collections Collection[] tags Tag[] - pinnedCollections PinnedCollections[] - pinnedLinks PinnedLinks[] - pinnedTags PinnedTags[] + + pinnedLinks Link[] + collectionsJoined UsersAndCollections[] isPrivate Boolean @default(false) whitelistedUsers String[] @default([]) @@ -29,7 +29,8 @@ model Collection { description String @default("") color String @default("#0ea5e9") isPublic Boolean @default(false) - pins PinnedCollections[] + + owner User @relation(fields: [ownerId], references: [id]) ownerId Int members UsersAndCollections[] @@ -39,37 +40,6 @@ model Collection { @@unique([name, ownerId]) } -model PinnedCollections { - id Int @id @default(autoincrement()) - - user User @relation(fields: [userId], references: [id]) - userId Int - - collection Collection @relation(fields: [collectionId], references: [id]) - collectionId Int -} - -model PinnedLinks { - id Int @id @default(autoincrement()) - - user User @relation(fields: [userId], references: [id]) - userId Int - - link Link @relation(fields: [linkId], references: [id]) - linkId Int -} - -model PinnedTags { - id Int @id @default(autoincrement()) - - user User @relation(fields: [userId], references: [id]) - userId Int - - tag Tag @relation(fields: [tagId], references: [id]) - tagId Int -} - - model UsersAndCollections { user User @relation(fields: [userId], references: [id]) userId Int @@ -89,10 +59,12 @@ model Link { name String url String title String + + pinnedBy User[] + collection Collection @relation(fields: [collectionId], references: [id]) collectionId Int tags Tag[] - pins PinnedLinks[] createdAt DateTime @default(now()) } @@ -100,7 +72,6 @@ model Tag { id Int @id @default(autoincrement()) name String links Link[] - pins PinnedTags[] owner User @relation(fields: [ownerId], references: [id]) ownerId Int diff --git a/types/global.ts b/types/global.ts index 900b3e7..a73c8a4 100644 --- a/types/global.ts +++ b/types/global.ts @@ -9,6 +9,9 @@ export interface LinkIncludingCollectionAndTags createdAt?: string; collectionId?: number; tags: Tag[]; + pinnedBy?: { + id: number; + }[]; collection: OptionalExcluding; } @@ -37,5 +40,5 @@ export interface AccountSettings extends User { export interface PublicCollectionIncludingLinks extends Omit { ownerName?: string; - links: Omit[]; + links: Link[]; }