-
-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor] Extract the bookmark model to be a high level model to sup…
…port other type of bookmarks
- Loading branch information
1 parent
c5bfa50
commit 08a5694
Showing
20 changed files
with
330 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/db/prisma/migrations/20240209013653_toplevel_bookmark/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the `BookmarkedLinkDetails` table. If the table is not empty, all the data it contains will be lost. | ||
- You are about to drop the `TagsOnLinks` table. If the table is not empty, all the data it contains will be lost. | ||
- You are about to drop the column `createdAt` on the `BookmarkedLink` table. All the data in the column will be lost. | ||
- You are about to drop the column `userId` on the `BookmarkedLink` table. All the data in the column will be lost. | ||
*/ | ||
-- DropIndex | ||
DROP INDEX "TagsOnLinks_linkId_tagId_key"; | ||
|
||
-- DropTable | ||
PRAGMA foreign_keys=off; | ||
DROP TABLE "BookmarkedLinkDetails"; | ||
PRAGMA foreign_keys=on; | ||
|
||
-- DropTable | ||
PRAGMA foreign_keys=off; | ||
DROP TABLE "TagsOnLinks"; | ||
PRAGMA foreign_keys=on; | ||
|
||
-- CreateTable | ||
CREATE TABLE "Bookmark" ( | ||
"id" TEXT NOT NULL PRIMARY KEY, | ||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"archived" BOOLEAN NOT NULL DEFAULT false, | ||
"favourited" BOOLEAN NOT NULL DEFAULT false, | ||
"userId" TEXT NOT NULL, | ||
CONSTRAINT "Bookmark_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "TagsOnBookmarks" ( | ||
"bookmarkId" TEXT NOT NULL, | ||
"tagId" TEXT NOT NULL, | ||
"attachedAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"attachedBy" TEXT NOT NULL, | ||
CONSTRAINT "TagsOnBookmarks_bookmarkId_fkey" FOREIGN KEY ("bookmarkId") REFERENCES "Bookmark" ("id") ON DELETE CASCADE ON UPDATE CASCADE, | ||
CONSTRAINT "TagsOnBookmarks_tagId_fkey" FOREIGN KEY ("tagId") REFERENCES "BookmarkTags" ("id") ON DELETE CASCADE ON UPDATE CASCADE | ||
); | ||
|
||
-- RedefineTables | ||
PRAGMA foreign_keys=OFF; | ||
CREATE TABLE "new_BookmarkedLink" ( | ||
"id" TEXT NOT NULL PRIMARY KEY, | ||
"url" TEXT NOT NULL, | ||
"title" TEXT, | ||
"description" TEXT, | ||
"imageUrl" TEXT, | ||
"favicon" TEXT, | ||
"crawledAt" DATETIME, | ||
CONSTRAINT "BookmarkedLink_id_fkey" FOREIGN KEY ("id") REFERENCES "Bookmark" ("id") ON DELETE CASCADE ON UPDATE CASCADE | ||
); | ||
INSERT INTO "new_BookmarkedLink" ("id", "url") SELECT "id", "url" FROM "BookmarkedLink"; | ||
DROP TABLE "BookmarkedLink"; | ||
ALTER TABLE "new_BookmarkedLink" RENAME TO "BookmarkedLink"; | ||
PRAGMA foreign_key_check; | ||
PRAGMA foreign_keys=ON; | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "TagsOnBookmarks_bookmarkId_tagId_key" ON "TagsOnBookmarks"("bookmarkId", "tagId"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/web/app/dashboard/bookmarks/components/BookmarksGrid.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { getServerSession } from "next-auth"; | ||
import { redirect } from "next/navigation"; | ||
import { authOptions } from "@/lib/auth"; | ||
import { getBookmarks } from "@/lib/services/bookmarks"; | ||
import LinkCard from "./LinkCard"; | ||
import { ZBookmark } from "@/lib/types/api/bookmarks"; | ||
|
||
function renderBookmark(bookmark: ZBookmark) { | ||
switch (bookmark.content.type) { | ||
case "link": | ||
return <LinkCard key={bookmark.id} bookmark={bookmark} />; | ||
} | ||
} | ||
|
||
export default async function BookmarksGrid() { | ||
const session = await getServerSession(authOptions); | ||
if (!session) { | ||
redirect("/"); | ||
} | ||
const bookmarks = await getBookmarks(session.user.id); | ||
|
||
return ( | ||
<div className="container grid gap-4 grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4"> | ||
{bookmarks.map((b) => renderBookmark(b))} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
packages/web/app/dashboard/bookmarks/components/LinksGrid.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.