feat: use crossbell kit to delete page
This commit is contained in:
@@ -235,15 +235,22 @@ export default function SubdomainEditor() {
|
||||
delStorage(`draft-${page.data.characterId}-${page.data.draftKey}`)
|
||||
} else {
|
||||
// Is Note
|
||||
return deleteP.mutateAsync({
|
||||
site: subdomain,
|
||||
id: `${page.data.characterId}-${page.data.noteId}`,
|
||||
return deleteP.mutate({
|
||||
noteId: page.data.noteId,
|
||||
characterId: page.data.characterId,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (deleteP.isSuccess) {
|
||||
toast.success(t("Deleted!"))
|
||||
deleteP.reset()
|
||||
router.push(`/dashboard/${subdomain}/${searchParams?.get("type")}s`)
|
||||
}
|
||||
}, [deleteP.isSuccess])
|
||||
|
||||
const [isCheersOpen, setIsCheersOpen] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -561,7 +568,8 @@ export default function SubdomainEditor() {
|
||||
{t("Preview")}
|
||||
</Button>
|
||||
<PublishButton
|
||||
save={savePage}
|
||||
savePage={savePage}
|
||||
deletePage={deletePage}
|
||||
twitterShareUrl={
|
||||
page.data && site.data
|
||||
? getTwitterShareUrl({
|
||||
@@ -572,7 +580,11 @@ export default function SubdomainEditor() {
|
||||
: ""
|
||||
}
|
||||
published={visibility !== PageVisibilityEnum.Draft}
|
||||
isSaving={createPage.isLoading || updatePage.isLoading}
|
||||
isSaving={
|
||||
createPage.isLoading ||
|
||||
updatePage.isLoading ||
|
||||
deleteP.isLoading
|
||||
}
|
||||
isDisabled={
|
||||
visibility !== PageVisibilityEnum.Modified &&
|
||||
visibility !== PageVisibilityEnum.Draft
|
||||
|
||||
@@ -152,9 +152,8 @@ export const PagesManagerBatchSelectActionTab = ({
|
||||
delStorage(`draft-${page?.characterId}-${page.draftKey}`)
|
||||
} else {
|
||||
// Is Note
|
||||
return deletePage.mutateAsync({
|
||||
site: subdomain,
|
||||
id: `${page.characterId}-${page.noteId}`,
|
||||
return deletePage.mutate({
|
||||
noteId: page.noteId,
|
||||
characterId: page.characterId,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -193,8 +193,7 @@ export const PagesManagerMenu = ({
|
||||
} else {
|
||||
setDeleteToastId(toast.loading("Deleting..."))
|
||||
deletePage.mutate({
|
||||
site: subdomain,
|
||||
id: `${page.characterId}-${page.noteId}`,
|
||||
noteId: page.noteId,
|
||||
characterId: page.characterId,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ import { Button, ButtonGroup } from "../ui/Button"
|
||||
import { DeleteConfirmationModal } from "./DeleteConfirmationModal"
|
||||
|
||||
export const PublishButton = ({
|
||||
save,
|
||||
savePage,
|
||||
deletePage,
|
||||
discardChanges,
|
||||
published,
|
||||
isSaving,
|
||||
@@ -16,7 +17,8 @@ export const PublishButton = ({
|
||||
twitterShareUrl,
|
||||
isPost,
|
||||
}: {
|
||||
save: (published: boolean) => void
|
||||
savePage: () => void
|
||||
deletePage: () => void
|
||||
published: boolean
|
||||
isSaving: boolean
|
||||
isDisabled: boolean
|
||||
@@ -50,7 +52,7 @@ export const PublishButton = ({
|
||||
<Button
|
||||
isAutoWidth
|
||||
style={{ padding: "0 15px" }}
|
||||
onClick={() => save(true)}
|
||||
onClick={() => savePage()}
|
||||
isLoading={isSaving}
|
||||
isDisabled={isDisabled}
|
||||
>
|
||||
@@ -110,7 +112,7 @@ export const PublishButton = ({
|
||||
open={deleteConfirmModalOpen}
|
||||
setOpen={setDeleteConfirmModalOpen}
|
||||
onConfirm={() => {
|
||||
save(false)
|
||||
deletePage()
|
||||
}}
|
||||
isPost={isPost}
|
||||
/>
|
||||
|
||||
@@ -6,7 +6,6 @@ import type {
|
||||
NoteEntity,
|
||||
NoteMetadata,
|
||||
} from "crossbell"
|
||||
import type Unidata from "unidata.js"
|
||||
import type { Address } from "viem"
|
||||
|
||||
import { GeneralAccount } from "@crossbell/connect-kit"
|
||||
@@ -464,29 +463,6 @@ export async function reportStats(input: {
|
||||
return await indexer.note.get(input.characterId, input.noteId)
|
||||
}
|
||||
|
||||
export async function deletePage(
|
||||
{ site, id }: { site: string; id: string },
|
||||
customUnidata?: Unidata,
|
||||
newbieToken?: string,
|
||||
) {
|
||||
const { default: unidata } = await import("~/queries/unidata.server")
|
||||
|
||||
return await (customUnidata || unidata).notes.set(
|
||||
{
|
||||
source: "Crossbell Note",
|
||||
identity: site,
|
||||
platform: "Crossbell",
|
||||
action: "remove",
|
||||
},
|
||||
{
|
||||
id,
|
||||
},
|
||||
{
|
||||
newbieToken,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
export async function getLikes({
|
||||
characterId,
|
||||
noteId,
|
||||
|
||||
+29
-17
@@ -5,6 +5,7 @@ import { nanoid } from "nanoid"
|
||||
|
||||
import {
|
||||
useAccountState,
|
||||
useDeleteNote,
|
||||
useIsNoteLiked,
|
||||
useMintNote,
|
||||
useNoteLikeCount,
|
||||
@@ -25,8 +26,6 @@ import {
|
||||
|
||||
import * as pageModel from "~/models/page.model"
|
||||
|
||||
import { useUnidata } from "./unidata"
|
||||
|
||||
export const useGetPagesBySiteLite = (
|
||||
input: Parameters<typeof pageModel.getPagesBySite>[0],
|
||||
) => {
|
||||
@@ -431,24 +430,37 @@ export function usePostNotes() {
|
||||
}
|
||||
|
||||
export function useDeletePage() {
|
||||
const newbieToken = useAccountState((s) => s.email?.token)
|
||||
const unidata = useUnidata()
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation(
|
||||
async (
|
||||
input: Parameters<typeof pageModel.deletePage>[0] & {
|
||||
characterId?: number
|
||||
},
|
||||
) => {
|
||||
return pageModel.deletePage(input, unidata, newbieToken)
|
||||
},
|
||||
{
|
||||
onSuccess: (data, variables) => {
|
||||
queryClient.invalidateQueries(["getPagesBySite", variables.characterId])
|
||||
queryClient.invalidateQueries(["getPage", variables.characterId])
|
||||
},
|
||||
const { mutateAsync: _, ...deleteNote } = useDeleteNote()
|
||||
|
||||
const mutate = useRefCallback(
|
||||
(input: { noteId?: number; characterId?: number }) => {
|
||||
if (!input.characterId || !input.noteId) {
|
||||
throw new Error("characterId and noteId are required")
|
||||
}
|
||||
|
||||
return deleteNote.mutate(
|
||||
{
|
||||
characterId: input.characterId,
|
||||
noteId: input.noteId,
|
||||
},
|
||||
{
|
||||
onSuccess: (data, variables) => {
|
||||
queryClient.invalidateQueries([
|
||||
"getPagesBySite",
|
||||
variables.characterId,
|
||||
])
|
||||
queryClient.invalidateQueries(["getPage", variables.characterId])
|
||||
},
|
||||
},
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
return {
|
||||
...deleteNote,
|
||||
mutate,
|
||||
}
|
||||
}
|
||||
|
||||
export const useToggleLikePage = useToggleLikeNote
|
||||
|
||||
Reference in New Issue
Block a user