🎨 add drawing button to NoteForm and remove floppy disk save icon
Browse files at this commitec8cb82cd379f2c3e9e861bb0d311a86ff465f35Parent: 92aa7eb- feat
- 🎨 add drawing button to NoteForm and remove floppy disk save icon
2 changed files +49 -16
src/components/notes/note-form.tsxmodified+47 -13
| @@ -1,16 +1,20 @@ | |||
| 1 | -import { For, Show, createResource, createSignal } from "solid-js"; | 1 | +import { For, Show, Suspense, createResource, createSignal, lazy } from "solid-js"; |
| 2 | import { formatApiError } from "@/api/client"; | 2 | import { formatApiError } from "@/api/client"; |
| 3 | import { getSettings } from "@/api/settings"; | 3 | import { getSettings } from "@/api/settings"; |
| 4 | import type { Note } from "@/api/client"; | 4 | import type { Note } from "@/api/client"; |
| 5 | import { Button } from "@/components/ui/button"; | 5 | import { Button } from "@/components/ui/button"; |
| 6 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | 6 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 7 | -import { IconPlus, IconTrash } from "@/components/ui/icons"; | 7 | +import { FormDialog } from "@/components/ui/form-dialog"; |
| 8 | +import { IconEdit, IconPlus, IconTrash } from "@/components/ui/icons"; | ||
| 8 | import { Input } from "@/components/ui/input"; | 9 | import { Input } from "@/components/ui/input"; |
| 9 | import { Label } from "@/components/ui/label"; | 10 | import { Label } from "@/components/ui/label"; |
| 11 | +import { PageSpinner } from "@/components/ui/page-spinner"; | ||
| 10 | import { Textarea } from "@/components/ui/textarea"; | 12 | import { Textarea } from "@/components/ui/textarea"; |
| 11 | import { formatBytes, maxUploadBytes } from "@/lib/upload-limits"; | 13 | import { formatBytes, maxUploadBytes } from "@/lib/upload-limits"; |
| 12 | import { useT } from "@/stores/preferences-context"; | 14 | import { useT } from "@/stores/preferences-context"; |
| 13 | 15 | ||
| 16 | +const DrawCanvas = lazy(() => import("@/components/ui/draw-canvas").then((m) => ({ default: m.DrawCanvas }))); | ||
| 17 | + | ||
| 14 | export type NoteFormValues = { | 18 | export type NoteFormValues = { |
| 15 | title: string; | 19 | title: string; |
| 16 | content: string; | 20 | content: string; |
| @@ -36,6 +40,7 @@ export function NoteForm(props: { | |||
| 36 | const [error, setError] = createSignal(""); | 40 | const [error, setError] = createSignal(""); |
| 37 | const [pending, setPending] = createSignal(false); | 41 | const [pending, setPending] = createSignal(false); |
| 38 | const [confirmOpen, setConfirmOpen] = createSignal(false); | 42 | const [confirmOpen, setConfirmOpen] = createSignal(false); |
| 43 | + const [drawOpen, setDrawOpen] = createSignal(false); | ||
| 39 | const [pendingValues, setPendingValues] = createSignal<NoteFormValues | null>(null); | 44 | const [pendingValues, setPendingValues] = createSignal<NoteFormValues | null>(null); |
| 40 | const [settings] = createResource(async () => { | 45 | const [settings] = createResource(async () => { |
| 41 | try { | 46 | try { |
| @@ -147,17 +152,29 @@ export function NoteForm(props: { | |||
| 147 | disabled={pending() || files().length >= MAX_NOTE_FILES} | 152 | disabled={pending() || files().length >= MAX_NOTE_FILES} |
| 148 | onChange={(event) => addFile(event.currentTarget.files?.[0])} | 153 | onChange={(event) => addFile(event.currentTarget.files?.[0])} |
| 149 | /> | 154 | /> |
| 150 | - <Button | 155 | + <div class="flex flex-wrap items-center gap-2"> |
| 151 | - type="button" | 156 | + <Button |
| 152 | - size="sm" | 157 | + type="button" |
| 153 | - variant="outline" | 158 | + variant="outline" |
| 154 | - class="rounded-md" | 159 | + size="sm" |
| 155 | - disabled={pending() || files().length >= MAX_NOTE_FILES} | 160 | + class="rounded-md" |
| 156 | - onClick={() => fileInput?.click()} | 161 | + disabled={pending() || files().length >= MAX_NOTE_FILES} |
| 157 | - > | 162 | + onClick={() => setDrawOpen(true)} |
| 158 | - <IconPlus class="h-4 w-4" /> | 163 | + > |
| 159 | - {t("notes.addFile")} | 164 | + <IconEdit class="h-4 w-4" /> |
| 160 | - </Button> | 165 | + {t("notes.draw")} |
| 166 | + </Button> | ||
| 167 | + <Button | ||
| 168 | + type="button" | ||
| 169 | + size="sm" | ||
| 170 | + class="rounded-md" | ||
| 171 | + disabled={pending() || files().length >= MAX_NOTE_FILES} | ||
| 172 | + onClick={() => fileInput?.click()} | ||
| 173 | + > | ||
| 174 | + <IconPlus class="h-4 w-4" /> | ||
| 175 | + {t("notes.addFile")} | ||
| 176 | + </Button> | ||
| 177 | + </div> | ||
| 161 | </div> | 178 | </div> |
| 162 | <Show | 179 | <Show |
| 163 | when={files().length > 0} | 180 | when={files().length > 0} |
| @@ -207,6 +224,23 @@ export function NoteForm(props: { | |||
| 207 | </div> | 224 | </div> |
| 208 | </form> | 225 | </form> |
| 209 | 226 | ||
| 227 | + <FormDialog | ||
| 228 | + open={drawOpen()} | ||
| 229 | + onOpenChange={setDrawOpen} | ||
| 230 | + title={t("notes.draw")} | ||
| 231 | + description={t("notes.filesHelp", { size: formatBytes(maxFileBytes()) })} | ||
| 232 | + class="max-w-4xl" | ||
| 233 | + > | ||
| 234 | + <Suspense fallback={<PageSpinner />}> | ||
| 235 | + <DrawCanvas | ||
| 236 | + onSave={(file) => { | ||
| 237 | + addFile(file); | ||
| 238 | + setDrawOpen(false); | ||
| 239 | + }} | ||
| 240 | + /> | ||
| 241 | + </Suspense> | ||
| 242 | + </FormDialog> | ||
| 243 | + | ||
| 210 | <ConfirmDialog | 244 | <ConfirmDialog |
| 211 | open={confirmOpen()} | 245 | open={confirmOpen()} |
| 212 | onOpenChange={setConfirmOpen} | 246 | onOpenChange={setConfirmOpen} |
src/components/ui/draw-canvas.tsxmodified+2 -3
| @@ -1,6 +1,6 @@ | |||
| 1 | import { For, Match, Show, Switch, createEffect, createSignal, onCleanup, onMount, untrack } from "solid-js"; | 1 | import { For, Match, Show, Switch, createEffect, createSignal, onCleanup, onMount, untrack } from "solid-js"; |
| 2 | import { Button } from "@/components/ui/button"; | 2 | import { Button } from "@/components/ui/button"; |
| 3 | -import { IconDownload, IconEdit, IconEraser, IconGrid, IconMove, IconRuled, IconSave, IconSquareOff, IconTrash, IconUndo, IconZoomIn, IconZoomOut } from "@/components/ui/icons"; | 3 | +import { IconDownload, IconEdit, IconEraser, IconGrid, IconMove, IconRuled, IconSquareOff, IconTrash, IconUndo, IconZoomIn, IconZoomOut } from "@/components/ui/icons"; |
| 4 | import { cn } from "@/lib/cn"; | 4 | import { cn } from "@/lib/cn"; |
| 5 | import { PAPER_CELL, PAPER_LINE, canvasPx, paintStroke, paintTip, strokesBounds, type BgKind, type DrawScene, type Point, type Stroke } from "@/lib/draw-stroke"; | 5 | import { PAPER_CELL, PAPER_LINE, canvasPx, paintStroke, paintTip, strokesBounds, type BgKind, type DrawScene, type Point, type Stroke } from "@/lib/draw-stroke"; |
| 6 | import { canvasToImageBlob, sceneToPngFile } from "@/lib/drawing-file"; | 6 | import { canvasToImageBlob, sceneToPngFile } from "@/lib/drawing-file"; |
| @@ -618,8 +618,7 @@ export function DrawCanvas(props: { | |||
| 618 | </div> | 618 | </div> |
| 619 | 619 | ||
| 620 | <div class="flex flex-wrap items-center gap-2"> | 620 | <div class="flex flex-wrap items-center gap-2"> |
| 621 | - <Button type="button" class="h-10 gap-2" disabled={props.pending || !canSave()} onClick={() => void save()}> | 621 | + <Button type="button" class="h-10 px-5" disabled={props.pending || !canSave()} onClick={() => void save()}> |
| 622 | - <IconSave class="h-4 w-4" /> | ||
| 623 | {t("draw.save")} | 622 | {t("draw.save")} |
| 624 | </Button> | 623 | </Button> |
| 625 | <Button type="button" variant="outline" class="h-10 gap-2" disabled={strokes().length === 0} onClick={() => void download("image/png", "png")}> | 624 | <Button type="button" variant="outline" class="h-10 gap-2" disabled={strokes().length === 0} onClick={() => void download("image/png", "png")}> |