Skip to content

Commit e26a9f2

Browse files
committed
feat: enhance Markdown editor with direct image upload support and drag-and-drop functionality
- Added direct image upload handling in the Markdown editor, allowing users to upload images via drag-and-drop or paste. - Updated the editor to display a loading state during image uploads. - Improved the overall user experience with visual feedback during drag-and-drop actions.
1 parent 8426a27 commit e26a9f2

File tree

5 files changed

+278
-78
lines changed

5 files changed

+278
-78
lines changed

src/app/dashboard/_components/DashboardArticleList.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ const DashboardArticleList = () => {
133133
<div className="flex flex-col divide-y divide-dashed divide-border-color mt-2">
134134
{feedInfiniteQuery.isFetching &&
135135
Array.from({ length: 10 }).map((_, i) => (
136-
<article key={i} className=" bg-muted h-20 animate-pulse" />
136+
<article key={i} className=" bg-muted h-20 animate-pulse" suppressHydrationWarning />
137137
))}
138138

139139
{feedInfiniteQuery.data?.pages.map((page) => {
@@ -207,11 +207,9 @@ const DashboardArticleList = () => {
207207
</div> */}
208208
</div>
209209
<DropdownMenu>
210-
<DropdownMenuTrigger>
211-
<button className="flex items-center gap-2">
212-
<p className="text-sm md:hidden">{_t("Actions")}</p>
213-
<DotsHorizontalIcon className="h-5 w-5" />
214-
</button>
210+
<DropdownMenuTrigger className="flex items-center gap-2">
211+
<p className="text-sm md:hidden">{_t("Actions")}</p>
212+
<DotsHorizontalIcon className="h-5 w-5" />
215213
</DropdownMenuTrigger>
216214
<DropdownMenuContent>
217215
<DropdownMenuItem asChild>

src/app/dashboard/_components/DashboardScaffold.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const DashboardScaffold: React.FC<
7070
<div className="p-4 flex items-center gap-2 justify-between">
7171
<TooltipProvider>
7272
<Tooltip>
73-
<TooltipTrigger>
73+
<TooltipTrigger asChild>
7474
<SidebarTrigger />
7575
</TooltipTrigger>
7676
<TooltipContent>

src/app/dashboard/_components/MatrixReport.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const MatrixReport = () => {
2424
<CardContent className="flex flex-col gap-2">
2525
<p className="text-3xl font-semibold h-9">
2626
{query.isFetching && (
27-
<LoaderIcon className="animate-spin size-8 text-muted-foreground" />
27+
<LoaderIcon className="animate-spin size-8 text-muted-foreground" suppressHydrationWarning />
2828
)}
2929
{query.data?.total_articles}
3030
</p>
@@ -38,7 +38,7 @@ const MatrixReport = () => {
3838
<CardContent className="flex flex-col gap-2">
3939
<p className="text-3xl font-semibold h-9">
4040
{query.isFetching && (
41-
<LoaderIcon className="animate-spin size-8 text-muted-foreground" />
41+
<LoaderIcon className="animate-spin size-8 text-muted-foreground" suppressHydrationWarning />
4242
)}
4343
{query.data?.total_comments}
4444
</p>

src/components/Editor/MarkdownEditorContent.tsx

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
"use client";
22

3-
import { HeadingIcon, FontBoldIcon, FontItalicIcon, Link2Icon, UploadIcon } from "@radix-ui/react-icons";
3+
import { useTranslation } from "@/i18n/use-translation";
4+
import {
5+
FontBoldIcon,
6+
FontItalicIcon,
7+
HeadingIcon,
8+
Link2Icon,
9+
UploadIcon,
10+
} from "@radix-ui/react-icons";
11+
import { Loader } from "lucide-react";
412
import React from "react";
513
import EditorCommandButton from "./EditorCommandButton";
614
import { useMarkdownEditor } from "./useMarkdownEditor";
@@ -10,7 +18,11 @@ interface MarkdownEditorContentProps {
1018
onChange: (value: string) => void;
1119
}
1220

13-
export function MarkdownEditorContent({ bodyRef, onChange }: MarkdownEditorContentProps) {
21+
export function MarkdownEditorContent({
22+
bodyRef,
23+
onChange,
24+
}: MarkdownEditorContentProps) {
25+
const { _t } = useTranslation();
1426
const editor = useMarkdownEditor({
1527
ref: bodyRef,
1628
onChange,
@@ -40,15 +52,35 @@ export function MarkdownEditorContent({ bodyRef, onChange }: MarkdownEditorConte
4052
/>
4153
<EditorCommandButton
4254
onClick={() => editor?.executeCommand("upload-image")}
43-
Icon={<UploadIcon />}
55+
Icon={
56+
editor?.isUploading ? (
57+
<Loader className="w-4 h-4 animate-spin" />
58+
) : (
59+
<UploadIcon />
60+
)
61+
}
4462
title="Upload Image (Ctrl/Cmd + U)"
63+
isDisabled={editor?.isUploading}
4564
/>
65+
66+
{editor?.isUploading && (
67+
<div className="flex items-center gap-2 text-sm text-muted-foreground">
68+
<Loader className="w-4 h-4 animate-spin" />
69+
<span>{_t("Uploading image")}...</span>
70+
</div>
71+
)}
4672
</div>
4773
);
4874

4975
return (
50-
<div className="flex flex-col justify-between md:items-center md:flex-row">
51-
{renderEditorToolbar()}
76+
<div className="flex flex-col justify-between">
77+
<div className="flex flex-col md:flex-row md:items-center md:justify-between">
78+
{renderEditorToolbar()}
79+
80+
<div className="text-xs text-muted-foreground mt-2 md:mt-0 md:ml-4">
81+
{_t("Tip: Drag & drop or paste images directly into the editor")}
82+
</div>
83+
</div>
5284
</div>
5385
);
54-
}
86+
}

0 commit comments

Comments
 (0)