feat: support cover editor input

This commit is contained in:
DIYgod
2023-06-06 19:52:03 +01:00
parent 8963290c1e
commit 49262e5b75
7 changed files with 77 additions and 8 deletions
+34 -2
View File
@@ -28,6 +28,8 @@ import { PublishButton } from "~/components/dashboard/PublishButton"
import { Button } from "~/components/ui/Button"
import { CodeMirrorEditor } from "~/components/ui/CodeMirror"
import { EditorToolbar } from "~/components/ui/EditorToolbar"
import { FieldLabel } from "~/components/ui/FieldLabel"
import { ImageUploader } from "~/components/ui/ImageUploader"
import { Input } from "~/components/ui/Input"
import { Modal } from "~/components/ui/Modal"
import { TagInput } from "~/components/ui/TagInput"
@@ -239,6 +241,7 @@ export default function SubdomainEditor() {
})}/${encodeURIComponent(values.slug || defaultSlug)}`,
applications: page.data?.metadata?.content?.sources,
characterId: site.data?.characterId,
cover: values.cover,
})
}
}
@@ -292,6 +295,12 @@ export default function SubdomainEditor() {
?.filter((tag) => tag !== "post" && tag !== "page")
?.join(", ") || "",
content: page.data.metadata?.content?.content || "",
cover: page.data.metadata?.content?.attachments?.find(
(attachment) => attachment.name === "cover",
) || {
address: "",
mime_type: "",
},
})
setDefaultSlug(
getDefaultSlug(
@@ -716,7 +725,7 @@ const EditorExtraProperties: FC<{
userTags: string[]
}> = memo(({ isPost, updateValue, subdomain, defaultSlug, userTags }) => {
const values = useEditorState(
(state) => pick(state, ["publishedAt", "slug", "excerpt", "tags"]),
(state) => pick(state, ["publishedAt", "slug", "excerpt", "tags", "cover"]),
shallow,
)
const { t } = useTranslation("dashboard")
@@ -829,13 +838,36 @@ const EditorExtraProperties: FC<{
id="excerpt"
value={values.excerpt}
multiline
rows={5}
rows={4}
onChange={(e: ChangeEvent<HTMLTextAreaElement>) => {
updateValue("excerpt", e.target.value)
}}
help={t("Leave it blank to use auto-generated excerpt")}
/>
</div>
<div>
<FieldLabel label={t("Cover Image")} />
<ImageUploader
id="icon"
className="aspect-video rounded-lg"
value={values.cover as any}
hasClose={true}
withMimeType={true}
uploadEnd={(key) => {
const { address, mime_type } = key as {
address?: string
mime_type?: string
}
updateValue("cover", {
address,
mime_type,
})
}}
/>
<div className="text-xs text-gray-400 mt-1">
{t("Leave blank to use the first image in the post")}
</div>
</div>
</div>
)
})
+4 -2
View File
@@ -4,6 +4,7 @@ import { XMarkIcon } from "@heroicons/react/20/solid"
import { Image } from "~/components/ui/Image"
import { useUploadFile } from "~/hooks/useUploadFile"
import { useTranslation } from "~/lib/i18n/client"
import { toGateway } from "~/lib/ipfs-parser"
import { cn } from "~/lib/utils"
@@ -42,6 +43,7 @@ export const ImageUploader = forwardRef(function ImageUploader(
const uploadFile = useUploadFile()
const [imageUrl, setImageUrl] = useState<string>()
const [loading, setLoading] = useState(false)
const { t } = useTranslation("common")
const handleChange = async (event: ChangeEvent<HTMLInputElement>) => {
if (event.target.files?.[0]) {
@@ -128,8 +130,8 @@ export const ImageUploader = forwardRef(function ImageUploader(
/>
)}
{!imageUrl && (
<div className="w-full h-full flex justify-center items-center text-zinc-500 text-center">
Click to select files
<div className="w-full h-full flex justify-center items-center text-zinc-500 text-center bg-white">
{t("Click to select files")}
</div>
)}
<input
+18 -2
View File
@@ -8,11 +8,27 @@ export const initialEditorState = {
slug: "",
tags: "",
content: "",
cover: {
address: "",
mime_type: "",
},
}
export type Values = {
title: string
publishedAt: string
published: boolean
excerpt: string
slug: string
tags: string
content: string
cover: {
address?: string
mime_type?: string
}
}
export type Values = typeof initialEditorState
export const useEditorState = create<
typeof initialEditorState & {
Values & {
setValues: (values: Partial<typeof initialEditorState>) => void
}
>((set) => ({
+4 -1
View File
@@ -49,7 +49,10 @@ export const expandCrossbellNote = async ({
expandedNote.metadata.content.summary = rendered.excerpt
}
}
expandedNote.metadata.content.cover = rendered.cover
expandedNote.metadata.content.cover =
expandedNote.metadata?.content?.attachments?.find(
(attachment) => attachment.name === "cover",
)?.address || rendered.cover
expandedNote.metadata.content.audio = rendered.audio
expandedNote.metadata.content.frontMatter = rendered.frontMatter
+2 -1
View File
@@ -83,5 +83,6 @@
"Refreshing": "刷新中",
"Search for your interest": "搜索你感兴趣的内容",
"results": "条结果",
"My xLog": "我的 xLog"
"My xLog": "我的 xLog",
"Click to select files": "点击选择文件"
}
+2
View File
@@ -79,6 +79,8 @@
"Separate multiple tags with English commas": "多个标签请用英文逗号分隔",
"Excerpt": "摘要",
"Leave it blank to use auto-generated excerpt": "留空则使用自动生成的摘要",
"Cover Image": "封面图",
"Leave blank to use the first image in the post": "留空则使用文章中的第一张图片",
"General": "常规",
"Social Platforms": "社交平台",
"Navigation": "导航",
+13
View File
@@ -57,6 +57,10 @@ export async function createOrUpdatePage(
isPost?: boolean
externalUrl?: string
applications?: string[]
cover?: {
address?: string
mime_type?: string
}
},
customUnidata?: Unidata,
newbieToken?: string,
@@ -122,6 +126,15 @@ export async function createOrUpdatePage(
},
],
}),
attachments: input.cover?.address
? [
{
name: "cover",
address: input.cover.address,
mime_type: input.cover.mime_type,
},
]
: [],
},
{
newbieToken,