From 048fc0c4f57ba657d258b5ffc458e8b68999f8b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Wed, 22 Jul 2026 12:56:41 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=93=A5=20relocate=20=C4=B0=C3=A7e?= =?UTF-8?q?=20Aktar=20(Import)=20button=20to=20Notes=20page=20header=20as?= =?UTF-8?q?=20a=20separate=20side=20panel=20-=20remove=20=C4=B0=C3=A7e=20A?= =?UTF-8?q?ktar=20button=20from=20inside=20NoteForm=20attachments=20sectio?= =?UTF-8?q?n=20per=20user=20directive=20-=20position=20=C4=B0=C3=A7e=20Akt?= =?UTF-8?q?ar=20button=20to=20the=20right=20of=20New=20Note=20button=20on?= =?UTF-8?q?=20Notes=20page=20header=20-=20open=20dedicated=20=C4=B0=C3=A7e?= =?UTF-8?q?=20Aktar=20side=20panel=20containing=20NoteImportPanel=20-=20ad?= =?UTF-8?q?d=20localized=20Turkish=20and=20English=20i18n=20strings=20for?= =?UTF-8?q?=20import=20help=20description?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/notes/note-import-panel.tsx | 199 +++++++++++++++++++ src/components/ui/icons.tsx | 10 + src/i18n/messages.ts | 6 + src/lib/__tests__/note-importer.test.ts | 69 +++++++ src/lib/note-importer.ts | 215 +++++++++++++++++++++ src/pages/notes-page.tsx | 38 +++- 6 files changed, 532 insertions(+), 5 deletions(-) create mode 100644 src/components/notes/note-import-panel.tsx create mode 100644 src/lib/__tests__/note-importer.test.ts create mode 100644 src/lib/note-importer.ts diff --git a/src/components/notes/note-import-panel.tsx b/src/components/notes/note-import-panel.tsx new file mode 100644 index 0000000..96e1d38 --- /dev/null +++ b/src/components/notes/note-import-panel.tsx @@ -0,0 +1,199 @@ +import { Show, createSignal } from "solid-js"; +import { Button } from "@/components/ui/button"; +import { IconFileText, IconUploadCloud } from "@/components/ui/icons"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { Textarea } from "@/components/ui/textarea"; +import { processImportedText } from "@/lib/note-importer"; +import { formatBytes } from "@/lib/upload-limits"; +import { useT } from "@/stores/preferences-context"; + +export function NoteImportPanel(props: { + onImport: (title: string, content: string) => void; + onCancel?: () => void; +}) { + const t = useT(); + let fileInput: HTMLInputElement | undefined; + + const [file, setFile] = createSignal(null); + const [processing, setProcessing] = createSignal(false); + const [error, setError] = createSignal(""); + const [importedTitle, setImportedTitle] = createSignal(""); + const [importedMarkdown, setImportedMarkdown] = createSignal(""); + const [hasGarbled, setHasGarbled] = createSignal(false); + + const handleFileSelect = async (selectedFile: File | undefined) => { + if (!selectedFile) return; + setError(""); + + const name = selectedFile.name.toLowerCase(); + const isText = name.endsWith(".txt") || name.endsWith(".md") || selectedFile.type.startsWith("text/"); + const isPdf = name.endsWith(".pdf") || selectedFile.type === "application/pdf"; + + if (!isText && !isPdf) { + setError(t("notes.previewUnsupported")); + return; + } + + setFile(selectedFile); + setProcessing(true); + + try { + let rawText = ""; + if (isPdf) { + rawText = await extractPdfText(selectedFile); + } else { + rawText = await selectedFile.text(); + } + + const result = processImportedText(rawText, selectedFile.name); + setImportedTitle(result.title); + setImportedMarkdown(result.markdown); + setHasGarbled(result.hasGarbledWarning); + } catch (err) { + setError(t("notes.previewUnsupported")); + } finally { + setProcessing(false); + } + }; + + const handleApply = () => { + const title = importedTitle().trim() || "Imported Note"; + const content = importedMarkdown(); + props.onImport(title, content); + }; + + return ( +
+ +
fileInput?.click()} + > + { + fileInput = el; + }} + type="file" + accept=".pdf,.txt,.md,text/plain,text/markdown,application/pdf" + class="hidden" + onChange={(e) => void handleFileSelect(e.currentTarget.files?.[0])} + /> + + + +
+

+ {t("notes.import")} (PDF, TXT, Markdown) +

+

+ {t("notes.importHelp")} +

+
+
+
+ + +
+
+
+ + {file()?.name} + ({formatBytes(file()?.size ?? 0)}) +
+ +
+ + +

+ ⚠️ Some content may be unreadable due to OCR/extraction issues +

+
+ +
+ + setImportedTitle(e.currentTarget.value)} + /> +
+ +
+ +