Skip to content

Commit

Permalink
feature: Add support for markdown in the text bookmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Feb 28, 2024
1 parent 2fa7177 commit 24e1dbe
Show file tree
Hide file tree
Showing 7 changed files with 692 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default function BookmarkOptions({ bookmark }: { bookmark: ZBookmark }) {
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
className="focus-visible:ring-0 focus-visible:ring-offset-0"
className="px-1 focus-visible:ring-0 focus-visible:ring-offset-0"
>
<MoreHorizontal />
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
Expand Down Expand Up @@ -83,15 +84,16 @@ export function BookmarkedTextEditor({
<Dialog open={open} onOpenChange={setOpen}>
<DialogContent>
<DialogHeader>
<DialogTitle className="pb-4">
{isNewBookmark ? "New Note" : "Edit Note"}
</DialogTitle>
<Textarea
value={noteText}
onChange={(e) => setNoteText(e.target.value)}
className="h-52 grow"
/>
<DialogTitle>{isNewBookmark ? "New Note" : "Edit Note"}</DialogTitle>
<DialogDescription>
Write your note with markdown support
</DialogDescription>
</DialogHeader>
<Textarea
value={noteText}
onChange={(e) => setNoteText(e.target.value)}
className="h-52 grow"
/>
<DialogFooter className="flex-shrink gap-1 sm:justify-end">
<DialogClose asChild>
<Button type="button" variant="secondary">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ZBookmark } from "@/lib/types/api/bookmarks";
import { Dialog, DialogContent } from "@/components/ui/dialog";
import Markdown from "react-markdown";

export function BookmarkedTextViewer({
content,
open,
setOpen,
}: {
content: string;
open: boolean;
setOpen: (open: boolean) => void;
}) {
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogContent className="max-h-[75%] overflow-scroll">
<Markdown className="prose">{content}</Markdown>
</DialogContent>
</Dialog>
);
}
76 changes: 49 additions & 27 deletions packages/web/app/dashboard/bookmarks/components/TextCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import { ZBookmark } from "@/lib/types/api/bookmarks";
import BookmarkOptions from "./BookmarkOptions";
import { api } from "@/lib/trpc";
import { Star } from "lucide-react";
import { Maximize2, Star } from "lucide-react";
import { cn } from "@/lib/utils";
import TagList from "./TagList";
import Markdown from "react-markdown";
import { useState } from "react";
import { BookmarkedTextViewer } from "./BookmarkedTextViewer";
import { Button } from "@/components/ui/button";

export default function TextCard({
bookmark: initialData,
Expand All @@ -22,6 +26,7 @@ export default function TextCard({
initialData,
},
);
const [previewModalOpen, setPreviewModalOpen] = useState(false);
const bookmarkedText = bookmark.content;
if (bookmarkedText.type != "text") {
throw new Error("Unexpected bookmark type");
Expand All @@ -30,33 +35,50 @@ export default function TextCard({
const numWords = bookmarkedText.text.split(" ").length;

return (
<div
className={cn(
className,
cn(
"flex flex-col gap-y-1 overflow-hidden rounded-lg p-2 shadow-md",
numWords > 12 ? "row-span-2 h-96" : "row-span-1 h-40",
),
)}
>
<p className="grow overflow-hidden text-ellipsis">
{bookmarkedText.text}
</p>
<div className="flex flex-none flex-wrap gap-1 overflow-hidden">
<TagList bookmark={bookmark} />
</div>
<div className="flex w-full justify-between">
<div>
{bookmark.favourited && (
<Star
className="my-1 size-8 rounded p-1"
color="#ebb434"
fill="#ebb434"
/>
)}
<>
<BookmarkedTextViewer
content={bookmarkedText.text}
open={previewModalOpen}
setOpen={setPreviewModalOpen}
/>
<div
className={cn(
className,
cn(
"flex flex-col gap-y-1 overflow-hidden rounded-lg p-2 shadow-md",
numWords > 12 ? "row-span-2 h-96" : "row-span-1 h-40",
),
)}
>
<Markdown className="prose grow overflow-hidden">
{bookmarkedText.text}
</Markdown>
<div className="flex flex-none flex-wrap gap-1 overflow-hidden">
<TagList bookmark={bookmark} />
</div>
<div className="flex w-full justify-between">
<div />
<div className="flex gap-0 text-gray-500">
<div>
{bookmark.favourited && (
<Star
className="my-1 size-8 rounded p-1"
color="#ebb434"
fill="#ebb434"
/>
)}
</div>
<Button
className="px-2"
variant="ghost"
onClick={() => setPreviewModalOpen(true)}
>
<Maximize2 size="20" />
</Button>
<BookmarkOptions bookmark={bookmark} />
</div>
</div>
<BookmarkOptions bookmark={bookmark} />
</div>
</div>
</>
);
}
2 changes: 2 additions & 0 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"react": "^18",
"react-dom": "^18",
"react-hook-form": "^7.50.1",
"react-markdown": "^9.0.1",
"server-only": "^0.0.1",
"superjson": "^2.2.1",
"tailwind-merge": "^2.2.1",
Expand All @@ -50,6 +51,7 @@
"zustand": "^4.5.1"
},
"devDependencies": {
"@tailwindcss/typography": "^0.5.10",
"@types/bcrypt": "^5.0.2",
"@types/react": "^18",
"@types/react-dom": "^18",
Expand Down
2 changes: 1 addition & 1 deletion packages/web/tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const config = {
},
},
},
plugins: [require("tailwindcss-animate")],
plugins: [require("tailwindcss-animate"), require("@tailwindcss/typography")],
} satisfies Config;

export default config;
Loading

0 comments on commit 24e1dbe

Please sign in to comment.