feat: prohibit multiple imports of mirror
This commit is contained in:
parent
b24b4d409d
commit
baa6aa127c
|
|
@ -175,5 +175,6 @@
|
|||
"Join xLog's Discord channel": "加入 xLog 的 Discord 频道",
|
||||
"Participate in the development of xLog": "参与 xLog 的开发",
|
||||
"Follow xLog's Twitter": "关注 xLog 的 Twitter",
|
||||
"Check out the updates of other bloggers": "查看其他博主的更新"
|
||||
"Check out the updates of other bloggers": "查看其他博主的更新",
|
||||
"You have already imported them, please enter the post page to create a new post!": "您已经导入了它们,请进入文章页面创建新的文章吧。"
|
||||
}
|
||||
|
|
@ -639,3 +639,14 @@ export async function getSummary({
|
|||
await fetch(`/api/summary?cid=${cid}&lang=${lang || "en"}`)
|
||||
).text()
|
||||
}
|
||||
|
||||
export async function checkMirror(characterId: string) {
|
||||
const notes = await indexer.getNotes({
|
||||
characterId,
|
||||
sources: ["xlog"],
|
||||
tags: ["post", "Mirror.xyz"],
|
||||
limit: 0,
|
||||
})
|
||||
|
||||
return notes.count === 0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import type { NoteMetadata } from "crossbell.js"
|
|||
import { ImportPreview } from "~/components/dashboard/ImportPreview"
|
||||
import { usePostNotes } from "~/queries/page"
|
||||
import { toast } from "react-hot-toast"
|
||||
import { useGetMirrorXyz } from "~/queries/page"
|
||||
import { useGetMirrorXyz, useCheckMirror } from "~/queries/page"
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = serverSidePropsHandler(
|
||||
async (ctx) => {
|
||||
|
|
@ -42,6 +42,7 @@ export default function ImportMarkdownPage() {
|
|||
const mirrorXyz = useGetMirrorXyz({
|
||||
address: site.data?.metadata?.owner,
|
||||
})
|
||||
const checkeMirror = useCheckMirror(site.data?.metadata?.proof)
|
||||
|
||||
const notes = mirrorXyz?.data?.map((note) => ({
|
||||
title: note.title,
|
||||
|
|
@ -83,34 +84,42 @@ export default function ImportMarkdownPage() {
|
|||
|
||||
return (
|
||||
<DashboardMain title="Import from Mirror.xyz">
|
||||
<form onSubmit={handleSubmit}>
|
||||
<div className="min-w-[270px] max-w-screen-lg flex flex-col space-y-4">
|
||||
<div>
|
||||
<div className="form-label">
|
||||
{t("Preview your Mirror.xyz entries")}
|
||||
{checkeMirror?.data ? (
|
||||
<form onSubmit={handleSubmit}>
|
||||
<div className="min-w-[270px] max-w-screen-lg flex flex-col space-y-4">
|
||||
<div>
|
||||
<div className="form-label">
|
||||
{t("Preview your Mirror.xyz entries")}
|
||||
</div>
|
||||
{notes?.length ? (
|
||||
notes?.map((note: NoteMetadata) => (
|
||||
<ImportPreview key={note.title} note={note} />
|
||||
))
|
||||
) : (
|
||||
<div className="text-gray-500">{t("No entries")}</div>
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<Button
|
||||
isAutoWidth={true}
|
||||
type="submit"
|
||||
isLoading={
|
||||
site.isLoading || mirrorXyz.isLoading || postNotes.isLoading
|
||||
}
|
||||
disabled={!notes?.length}
|
||||
>
|
||||
{t("Import")}
|
||||
</Button>
|
||||
</div>
|
||||
{notes?.length ? (
|
||||
notes?.map((note: NoteMetadata) => (
|
||||
<ImportPreview key={note.title} note={note} />
|
||||
))
|
||||
) : (
|
||||
<div className="text-gray-500">{t("No entries")}</div>
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<Button
|
||||
isAutoWidth={true}
|
||||
type="submit"
|
||||
isLoading={
|
||||
site.isLoading || mirrorXyz.isLoading || postNotes.isLoading
|
||||
}
|
||||
disabled={!notes?.length}
|
||||
>
|
||||
{t("Import")}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
) : (
|
||||
<div className="text-gray-500">
|
||||
{t(
|
||||
"You have already imported them, please enter the post page to create a new post!",
|
||||
)}
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
</DashboardMain>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -293,3 +293,12 @@ export function useGetMirrorXyz(input: { address: string }) {
|
|||
}[]
|
||||
})
|
||||
}
|
||||
|
||||
export function useCheckMirror(characterId?: string) {
|
||||
return useQuery(["checkMirror", characterId], async () => {
|
||||
if (!characterId) {
|
||||
return
|
||||
}
|
||||
return pageModel.checkMirror(characterId)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue