feat: conversion between posts and pages
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
"@floating-ui/react-dom-interactions": "^0.6.3",
|
||||
"@headlessui/react": "^1.6.0",
|
||||
"@heroicons/react": "^1.0.6",
|
||||
"@iconify-json/tabler": "^1.1.31",
|
||||
"@monaco-editor/react": "^4.4.5",
|
||||
"@prisma/client": "^3.14.0",
|
||||
"@proselog/jwt": "^0.1.1",
|
||||
|
||||
Generated
+8
-1
@@ -19,6 +19,7 @@ specifiers:
|
||||
'@iconify-json/carbon': ^1.1.5
|
||||
'@iconify-json/fluent': ^1.1.8
|
||||
'@iconify-json/mdi': ^1.1.19
|
||||
'@iconify-json/tabler': ^1.1.31
|
||||
'@monaco-editor/react': ^4.4.5
|
||||
'@playwright/test': ^1.22.1
|
||||
'@prisma/client': ^3.14.0
|
||||
@@ -125,6 +126,7 @@ dependencies:
|
||||
'@floating-ui/react-dom-interactions': 0.6.6_twyhzqqpkwvvgrmyeapdo6i4my
|
||||
'@headlessui/react': 1.6.5_biqbaboplfbrettd7655fr4n2y
|
||||
'@heroicons/react': 1.0.6_react@18.2.0
|
||||
'@iconify-json/tabler': 1.1.31
|
||||
'@monaco-editor/react': 4.4.5_biqbaboplfbrettd7655fr4n2y
|
||||
'@prisma/client': 3.15.2_prisma@3.15.2
|
||||
'@proselog/jwt': 0.1.1
|
||||
@@ -1457,9 +1459,14 @@ packages:
|
||||
'@iconify/types': 1.1.0
|
||||
dev: true
|
||||
|
||||
/@iconify-json/tabler/1.1.31:
|
||||
resolution: {integrity: sha512-cRc12zNuggknZkl2WKAqN1QfTJOe6J400v+3icwwXhdvQPXAgECk98fd2xEZFDcrEQlr8I6s1TqWNQ0KLg/HDg==}
|
||||
dependencies:
|
||||
'@iconify/types': 1.1.0
|
||||
dev: false
|
||||
|
||||
/@iconify/types/1.1.0:
|
||||
resolution: {integrity: sha512-Jh0llaK2LRXQoYsorIH8maClebsnzTcve+7U3rQUSnC11X4jtPnFuyatqFLvMxZ8MLG8dB4zfHsbPfuvxluONw==}
|
||||
dev: true
|
||||
|
||||
/@iconify/utils/1.0.33:
|
||||
resolution: {integrity: sha512-vGeAqo7aGPxOQmGdVoXFUOuyN+0V7Lcrx2EvaiRjxUD1x6Om0Tvq2bdm7E24l2Pz++4S0mWMCVFXe/17EtKImQ==}
|
||||
|
||||
@@ -11,9 +11,13 @@ import Link from "next/link"
|
||||
import toast from "react-hot-toast"
|
||||
import { EmptyState } from "../ui/EmptyState"
|
||||
import type { Note } from "unidata.js"
|
||||
import { useGetPagesBySite, useDeletePage } from "~/queries/page"
|
||||
import {
|
||||
useGetPagesBySite,
|
||||
useDeletePage,
|
||||
useCreateOrUpdatePage,
|
||||
} from "~/queries/page"
|
||||
import { DotsHorizontalIcon } from "@heroicons/react/solid"
|
||||
import { delStorage } from "~/lib/storage"
|
||||
import { delStorage, getStorage, setStorage } from "~/lib/storage"
|
||||
import { useQueryClient } from "@tanstack/react-query"
|
||||
import { Button } from "../ui/Button"
|
||||
|
||||
@@ -32,6 +36,7 @@ export const PagesManager: React.FC<{
|
||||
)
|
||||
|
||||
const deletePage = useDeletePage()
|
||||
const createOrUpdatePage = useCreateOrUpdatePage()
|
||||
|
||||
useEffect(() => {
|
||||
if (deletePage.isSuccess) {
|
||||
@@ -89,7 +94,7 @@ export const PagesManager: React.FC<{
|
||||
}
|
||||
|
||||
const queryClient = useQueryClient()
|
||||
const getPageMenuItems = (page: { id: string; metadata?: Object }) => {
|
||||
const getPageMenuItems = (page: Note) => {
|
||||
return [
|
||||
{
|
||||
text: "Edit",
|
||||
@@ -111,6 +116,29 @@ export const PagesManager: React.FC<{
|
||||
router.push(getPageEditLink(page))
|
||||
},
|
||||
},
|
||||
{
|
||||
text: "Convert to " + (isPost ? "Page" : "Post"),
|
||||
icon: <span className="i-tabler:transform inline-block"></span>,
|
||||
onClick() {
|
||||
if (!page.metadata) {
|
||||
const data = getStorage(`draft-${subdomain}-${page.id}`)
|
||||
data.isPost = !isPost
|
||||
setStorage(`draft-${subdomain}-${page.id}`, data)
|
||||
queryClient.invalidateQueries(["getPagesBySite", subdomain])
|
||||
queryClient.invalidateQueries(["getPage", page.id])
|
||||
} else {
|
||||
createOrUpdatePage.mutate({
|
||||
published: true,
|
||||
pageId: page.id,
|
||||
siteId: subdomain,
|
||||
tags: page.tags
|
||||
?.filter((tag) => tag !== "post" && tag !== "page")
|
||||
?.join(", "),
|
||||
isPost: !isPost,
|
||||
})
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
text: "Delete",
|
||||
icon: (
|
||||
@@ -230,7 +258,9 @@ export const PagesManager: React.FC<{
|
||||
item.onClick()
|
||||
}}
|
||||
>
|
||||
<span>{item.icon}</span>
|
||||
<span className="inline-flex">
|
||||
{item.icon}
|
||||
</span>
|
||||
<span>{item.text}</span>
|
||||
</button>
|
||||
</Menu.Item>
|
||||
|
||||
Reference in New Issue
Block a user