diff --git a/src/components/StackedNote.vue b/src/components/StackedNote.vue index e2b18e6..94a3efa 100644 --- a/src/components/StackedNote.vue +++ b/src/components/StackedNote.vue @@ -10,6 +10,7 @@ import { import { useEditionMode } from "@/hooks/useEditionMode" import { useFile } from "@/hooks/useFile.hook" import { useGitHubContent } from "@/hooks/useGitHubContent.hook" +import { useImageUpload } from "@/hooks/useImageUpload.hook" import { useLinks } from "@/hooks/useLinks.hook" import { renderCodeFile } from "@/hooks/useMarkdown.hook" import { useMarkdownPostRender } from "@/hooks/useMarkdownPostRender.hook" @@ -109,6 +110,27 @@ const { updateFile } = useGitHubContent({ repo: repo.value }) +const { uploadImage } = useImageUpload({ + user: user.value, + repo: repo.value, + notePath: path +}) + +const fileInput = ref(null) +const editKey = ref(0) + +const onImagePicked = async (e: Event) => { + const input = e.target as HTMLInputElement + const file = input.files?.[0] + input.value = "" + if (!file || !path.value) return + const result = await uploadImage(file) + if (!result) return + const suffix = rawContent.value.endsWith("\n") ? "" : "\n\n" + rawContent.value = `${rawContent.value}${suffix}![](${result.filename})\n` + editKey.value++ +} + const { status: freshnessStatus, lastCheckedAt, @@ -273,6 +295,42 @@ const onBadgeClick = async () => { @click="onBadgeClick" class="action" /> + +