feat: replace isPost with the note type
This commit is contained in:
@@ -52,7 +52,7 @@ import { getSiteLink, getTwitterShareUrl } from "~/lib/helpers"
|
||||
import { useTranslation } from "~/lib/i18n/client"
|
||||
import { getPageVisibility } from "~/lib/page-helpers"
|
||||
import { delStorage, setStorage } from "~/lib/storage"
|
||||
import { ExpandedNote, PageVisibilityEnum } from "~/lib/types"
|
||||
import { ExpandedNote, NoteType, PageVisibilityEnum } from "~/lib/types"
|
||||
import { cn, pick } from "~/lib/utils"
|
||||
import { Rendered, renderPageContent } from "~/markdown"
|
||||
import { checkPageSlug } from "~/models/page.model"
|
||||
@@ -98,7 +98,7 @@ export default function SubdomainEditor() {
|
||||
const searchParams = useSearchParams()
|
||||
|
||||
let pageId = searchParams?.get("id") as string | undefined
|
||||
const isPost = searchParams?.get("type") === "post"
|
||||
const type = (searchParams?.get("type") || "post") as NoteType
|
||||
const defaultTag = searchParams?.get("tag")
|
||||
|
||||
const site = useGetSite(subdomain)
|
||||
@@ -206,7 +206,7 @@ export default function SubdomainEditor() {
|
||||
setStorage(draftKey, {
|
||||
date: +new Date(),
|
||||
values: newValues,
|
||||
isPost: isPost,
|
||||
type,
|
||||
})
|
||||
queryClient.invalidateQueries([
|
||||
"getPagesBySite",
|
||||
@@ -215,7 +215,7 @@ export default function SubdomainEditor() {
|
||||
}
|
||||
useEditorState.setState(newValues)
|
||||
},
|
||||
[isPost, queryClient, subdomain, visibility],
|
||||
[type, queryClient, subdomain, visibility],
|
||||
)
|
||||
|
||||
const createPage = useCreatePage()
|
||||
@@ -246,7 +246,7 @@ export default function SubdomainEditor() {
|
||||
if (visibility === PageVisibilityEnum.Draft) {
|
||||
createPage.mutate({
|
||||
...baseValues,
|
||||
isPost: isPost,
|
||||
type,
|
||||
})
|
||||
} else {
|
||||
updatePage.mutate({
|
||||
@@ -545,12 +545,12 @@ export default function SubdomainEditor() {
|
||||
)
|
||||
}, [draftKey, subdomain, site.data?.characterId])
|
||||
|
||||
const presentAdvancedModal = useEditorAdvancedModal({ isPost })
|
||||
const presentAdvancedModal = useEditorAdvancedModal({ type })
|
||||
const extraProperties = (
|
||||
<EditorExtraProperties
|
||||
defaultSlug={defaultSlug}
|
||||
updateValue={updateValue}
|
||||
isPost={isPost}
|
||||
type={type}
|
||||
subdomain={subdomain}
|
||||
userTags={userTags.data?.list || []}
|
||||
openAdvancedOptions={presentAdvancedModal}
|
||||
@@ -610,7 +610,7 @@ export default function SubdomainEditor() {
|
||||
renderPage={setIsRendering}
|
||||
propertiesWidget={extraProperties}
|
||||
previewPage={onPreviewButtonClick}
|
||||
isPost={isPost}
|
||||
type={type}
|
||||
isModified={visibility === PageVisibilityEnum.Modified}
|
||||
discardChanges={discardChanges}
|
||||
/>
|
||||
@@ -654,7 +654,7 @@ export default function SubdomainEditor() {
|
||||
visibility !== PageVisibilityEnum.Modified &&
|
||||
visibility !== PageVisibilityEnum.Draft
|
||||
}
|
||||
isPost={isPost}
|
||||
type={type}
|
||||
isModified={visibility === PageVisibilityEnum.Modified}
|
||||
discardChanges={discardChanges}
|
||||
/>
|
||||
@@ -736,7 +736,7 @@ export default function SubdomainEditor() {
|
||||
<EditorExtraProperties
|
||||
defaultSlug={defaultSlug}
|
||||
updateValue={updateValue}
|
||||
isPost={isPost}
|
||||
type={type}
|
||||
userTags={userTags.data?.list || []}
|
||||
subdomain={subdomain}
|
||||
openAdvancedOptions={presentAdvancedModal}
|
||||
@@ -752,7 +752,7 @@ export default function SubdomainEditor() {
|
||||
|
||||
const EditorExtraProperties = memo(
|
||||
({
|
||||
isPost,
|
||||
type,
|
||||
updateValue,
|
||||
subdomain,
|
||||
defaultSlug,
|
||||
@@ -760,7 +760,7 @@ const EditorExtraProperties = memo(
|
||||
openAdvancedOptions,
|
||||
}: {
|
||||
updateValue: <K extends keyof Values>(key: K, value: Values[K]) => void
|
||||
isPost: boolean
|
||||
type: NoteType
|
||||
|
||||
subdomain: string
|
||||
defaultSlug: string
|
||||
@@ -823,7 +823,9 @@ const EditorExtraProperties = memo(
|
||||
name="slug"
|
||||
value={values.slug}
|
||||
placeholder={defaultSlug}
|
||||
label={t(`${isPost ? "Post" : "Page"} slug`) || ""}
|
||||
label={
|
||||
t(`${type.charAt(0).toUpperCase() + type.slice(1)} slug`) || ""
|
||||
}
|
||||
id="slug"
|
||||
isBlock
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>) =>
|
||||
@@ -833,9 +835,7 @@ const EditorExtraProperties = memo(
|
||||
<>
|
||||
{(values.slug || defaultSlug) && (
|
||||
<>
|
||||
{t(
|
||||
`This ${isPost ? "post" : "page"} will be accessible at`,
|
||||
)}{" "}
|
||||
{t(`This ${type} will be accessible at`)}{" "}
|
||||
<UniLink
|
||||
href={`${getSiteLink({
|
||||
subdomain,
|
||||
@@ -892,7 +892,7 @@ const EditorExtraProperties = memo(
|
||||
|
||||
EditorExtraProperties.displayName = "EditorExtraProperties"
|
||||
|
||||
const useEditorAdvancedModal = ({ isPost }: { isPost: boolean }) => {
|
||||
const useEditorAdvancedModal = ({ type }: { type: NoteType }) => {
|
||||
const { t } = useTranslation("dashboard")
|
||||
|
||||
const { present } = useModalStack()
|
||||
@@ -900,7 +900,7 @@ const useEditorAdvancedModal = ({ isPost }: { isPost: boolean }) => {
|
||||
return () => {
|
||||
present({
|
||||
title: t("Advanced Settings"),
|
||||
content: () => <EditorAdvancedModal isPost={isPost} />,
|
||||
content: () => <EditorAdvancedModal type={type} />,
|
||||
modalProps: {
|
||||
withConfirm: true,
|
||||
},
|
||||
@@ -909,8 +909,8 @@ const useEditorAdvancedModal = ({ isPost }: { isPost: boolean }) => {
|
||||
}
|
||||
|
||||
const EditorAdvancedModal: FC<{
|
||||
isPost: boolean
|
||||
}> = ({ isPost }) => {
|
||||
type: NoteType
|
||||
}> = ({ type }) => {
|
||||
const { t } = useTranslation("dashboard")
|
||||
|
||||
const values = useEditorState(
|
||||
@@ -971,9 +971,7 @@ const EditorAdvancedModal: FC<{
|
||||
/>
|
||||
<div className="text-xs text-gray-400 mt-1">
|
||||
{t(
|
||||
`This ${
|
||||
isPost ? "post" : "page"
|
||||
} will be accessible from this time. Leave blank to use the current time.`,
|
||||
`This ${type} will be accessible from this time. Leave blank to use the current time.`,
|
||||
)}
|
||||
</div>
|
||||
{values.publishedAt > new Date().toISOString() && (
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { PagesManager } from "~/components/dashboard/PagesManager"
|
||||
|
||||
export default function SubdomainPages() {
|
||||
return <PagesManager isPost={false} />
|
||||
return <PagesManager type="page" />
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { PagesManager } from "~/components/dashboard/PagesManager"
|
||||
|
||||
export default function SubdomainPosts() {
|
||||
return <PagesManager isPost={true} />
|
||||
return <PagesManager type="post" />
|
||||
}
|
||||
|
||||
@@ -7,19 +7,19 @@ export const DeleteConfirmationModal = ({
|
||||
open,
|
||||
setOpen,
|
||||
onConfirm,
|
||||
isPost,
|
||||
type,
|
||||
}: {
|
||||
open: boolean
|
||||
setOpen: (open: boolean) => void
|
||||
onConfirm: () => void
|
||||
isPost?: boolean
|
||||
type?: string
|
||||
}) => {
|
||||
const { t } = useTranslation("dashboard")
|
||||
|
||||
return (
|
||||
<Modal open={open} setOpen={setOpen}>
|
||||
<div className="px-5 py-4 space-y-4">
|
||||
<p>{t("delete_confirmation", { context: isPost ? "post" : "page" })}</p>
|
||||
<p>{t("delete_confirmation", { context: type })}</p>
|
||||
<div className="flex justify-end space-x-2">
|
||||
<Button variant="secondary" onClick={() => setOpen(false)}>
|
||||
<span className="truncate">{t("Cancel")}</span>
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useTranslation } from "react-i18next"
|
||||
|
||||
import { Menu, Popover, Transition } from "@headlessui/react"
|
||||
|
||||
import { PageVisibilityEnum } from "~/lib/types"
|
||||
import { NoteType, PageVisibilityEnum } from "~/lib/types"
|
||||
import { cn } from "~/lib/utils"
|
||||
|
||||
import { DeleteConfirmationModal } from "./DeleteConfirmationModal"
|
||||
@@ -17,7 +17,7 @@ export const OptionsButton = ({
|
||||
renderPage,
|
||||
published,
|
||||
propertiesWidget,
|
||||
isPost,
|
||||
type,
|
||||
isModified,
|
||||
discardChanges,
|
||||
}: {
|
||||
@@ -29,7 +29,7 @@ export const OptionsButton = ({
|
||||
propertiesWidget: React.ReactNode
|
||||
isRendering: boolean
|
||||
published: boolean
|
||||
isPost: boolean
|
||||
type: NoteType
|
||||
isModified: boolean
|
||||
discardChanges: () => void
|
||||
}) => {
|
||||
@@ -188,7 +188,7 @@ export const OptionsButton = ({
|
||||
onConfirm={() => {
|
||||
deletePage()
|
||||
}}
|
||||
isPost={isPost}
|
||||
type={type}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -19,7 +19,7 @@ import { Trans, useTranslation } from "~/lib/i18n/client"
|
||||
import { getPageVisibility } from "~/lib/page-helpers"
|
||||
import { readFiles } from "~/lib/read-files"
|
||||
import { setStorage } from "~/lib/storage"
|
||||
import { ExpandedNote, PageVisibilityEnum } from "~/lib/types"
|
||||
import { ExpandedNote, NoteType, PageVisibilityEnum } from "~/lib/types"
|
||||
import { cn } from "~/lib/utils"
|
||||
import { useGetPagesBySite, usePinnedPage } from "~/queries/page"
|
||||
import { useGetSite } from "~/queries/site"
|
||||
@@ -33,7 +33,7 @@ import { DashboardMain } from "./DashboardMain"
|
||||
import { PagesManagerBatchSelectActionTab } from "./PagesManagerBatchSelectActionTab"
|
||||
import { PagesManagerMenu } from "./PagesManagerMenu"
|
||||
|
||||
export const PagesManager = ({ isPost }: { isPost: boolean }) => {
|
||||
export const PagesManager = ({ type }: { type: NoteType }) => {
|
||||
const params = useParams()
|
||||
const subdomain = params?.subdomain as string
|
||||
const site = useGetSite(subdomain)
|
||||
@@ -55,7 +55,7 @@ export const PagesManager = ({ isPost }: { isPost: boolean }) => {
|
||||
const date = useDate()
|
||||
|
||||
const pages = useGetPagesBySite({
|
||||
type: isPost ? "post" : "page",
|
||||
type,
|
||||
characterId: site.data?.characterId,
|
||||
limit: 20,
|
||||
visibility,
|
||||
@@ -69,7 +69,7 @@ export const PagesManager = ({ isPost }: { isPost: boolean }) => {
|
||||
const tabItems: TabItem[] = [
|
||||
{
|
||||
value: PageVisibilityEnum.All,
|
||||
text: `All ${isPost ? "Posts" : "Pages"}`,
|
||||
text: `All ${type.charAt(0).toUpperCase() + type.slice(1)}s`,
|
||||
},
|
||||
{
|
||||
value: PageVisibilityEnum.Published,
|
||||
@@ -101,7 +101,7 @@ export const PagesManager = ({ isPost }: { isPost: boolean }) => {
|
||||
const getPageEditLink = (page: ExpandedNote) => {
|
||||
return `/dashboard/${subdomain}/editor?id=${
|
||||
page.noteId || page.draftKey
|
||||
}&type=${isPost ? "post" : "page"}`
|
||||
}&type=${type}`
|
||||
}
|
||||
|
||||
const queryClient = useQueryClient()
|
||||
@@ -125,65 +125,70 @@ export const PagesManager = ({ isPost }: { isPost: boolean }) => {
|
||||
tags: file.tags?.join?.(", "),
|
||||
title: file.title,
|
||||
},
|
||||
isPost: isPost,
|
||||
type,
|
||||
})
|
||||
queryClient.invalidateQueries([
|
||||
"getPagesBySite",
|
||||
site.data?.characterId,
|
||||
])
|
||||
router.push(
|
||||
`/dashboard/${subdomain}/editor?id=!local-${id}&type=${
|
||||
isPost ? "post" : "page"
|
||||
}`,
|
||||
`/dashboard/${subdomain}/editor?id=!local-${id}&type=${type}`,
|
||||
)
|
||||
}
|
||||
})
|
||||
input.click()
|
||||
}
|
||||
|
||||
const title = isPost ? "Posts" : "Pages"
|
||||
const description = isPost ? (
|
||||
<>
|
||||
<p>
|
||||
<Trans i18n={i18n} i18nKey="posts description" ns="dashboard">
|
||||
Posts are entries listed in reverse chronological order on your site.
|
||||
Think of them as articles or updates that you share to offer up new
|
||||
content to your readers.{" "}
|
||||
<UniLink className="underline" href={t("link post-vs-page") || ""}>
|
||||
Post vs. Page
|
||||
</UniLink>
|
||||
</Trans>
|
||||
</p>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<p>
|
||||
<Trans i18n={i18n} i18nKey="pages description" ns="dashboard">
|
||||
Pages are static and are not affected by date. Think of them as more
|
||||
permanent fixtures of your site — an About page, and a Contact page
|
||||
are great examples of this.{" "}
|
||||
<UniLink
|
||||
className="underline"
|
||||
href="https://wordpress.com/support/post-vs-page/"
|
||||
>
|
||||
Post vs. Page
|
||||
</UniLink>
|
||||
</Trans>
|
||||
</p>
|
||||
<p>
|
||||
<Trans i18n={i18n} i18nKey="pages add" ns="dashboard">
|
||||
After you create a page, you can{" "}
|
||||
<UniLink
|
||||
className="underline"
|
||||
href={`/dashboard/${subdomain}/settings/navigation`}
|
||||
>
|
||||
add it to your site's navigation menu
|
||||
</UniLink>{" "}
|
||||
so your visitors can find it.
|
||||
</Trans>
|
||||
</p>
|
||||
</>
|
||||
)
|
||||
let description = null
|
||||
switch (type) {
|
||||
case "post":
|
||||
description = (
|
||||
<p>
|
||||
<Trans i18n={i18n} i18nKey="posts description" ns="dashboard">
|
||||
Posts are entries listed in reverse chronological order on your
|
||||
site. Think of them as articles or updates that you share to offer
|
||||
up new content to your readers.{" "}
|
||||
<UniLink className="underline" href={t("link post-vs-page") || ""}>
|
||||
Post vs. Page
|
||||
</UniLink>
|
||||
</Trans>
|
||||
</p>
|
||||
)
|
||||
break
|
||||
case "page":
|
||||
description = (
|
||||
<>
|
||||
<p>
|
||||
<Trans i18n={i18n} i18nKey="pages description" ns="dashboard">
|
||||
Pages are static and are not affected by date. Think of them as
|
||||
more permanent fixtures of your site — an About page, and a
|
||||
Contact page are great examples of this.{" "}
|
||||
<UniLink
|
||||
className="underline"
|
||||
href="https://wordpress.com/support/post-vs-page/"
|
||||
>
|
||||
Post vs. Page
|
||||
</UniLink>
|
||||
</Trans>
|
||||
</p>
|
||||
<p>
|
||||
<Trans i18n={i18n} i18nKey="pages add" ns="dashboard">
|
||||
After you create a page, you can{" "}
|
||||
<UniLink
|
||||
className="underline"
|
||||
href={`/dashboard/${subdomain}/settings/navigation`}
|
||||
>
|
||||
add it to your site's navigation menu
|
||||
</UniLink>{" "}
|
||||
so your visitors can find it.
|
||||
</Trans>
|
||||
</p>
|
||||
</>
|
||||
)
|
||||
break
|
||||
case "portfolio": // TODO
|
||||
description = <></>
|
||||
}
|
||||
|
||||
let currentLength = 0
|
||||
|
||||
@@ -191,21 +196,21 @@ export const PagesManager = ({ isPost }: { isPost: boolean }) => {
|
||||
<DashboardMain className="max-w-screen-lg">
|
||||
<header className="mb-4 space-y-4">
|
||||
<div className="flex justify-between items-center">
|
||||
<h2 className="text-2xl font-bold">{t(title)}</h2>
|
||||
<h2 className="text-2xl font-bold">
|
||||
{t(`${type.charAt(0).toUpperCase() + type.slice(1)}s`)}
|
||||
</h2>
|
||||
</div>
|
||||
<div className="space-x-4">
|
||||
<Button
|
||||
className={cn(`space-x-2 inline-flex`)}
|
||||
onClick={() =>
|
||||
router.push(
|
||||
`/dashboard/${subdomain}/editor?type=${
|
||||
isPost ? "post" : "page"
|
||||
}`,
|
||||
)
|
||||
router.push(`/dashboard/${subdomain}/editor?type=${type}`)
|
||||
}
|
||||
>
|
||||
<span className="icon-[mingcute--add-line] inline-block"></span>
|
||||
<span>{t(`New ${isPost ? "Post" : "Page"}`)}</span>
|
||||
<span>
|
||||
{t(`New ${type.charAt(0).toUpperCase() + type.slice(1)}`)}
|
||||
</span>
|
||||
</Button>
|
||||
<span className="hidden sm:inline-flex">
|
||||
<Tooltip
|
||||
@@ -226,7 +231,7 @@ export const PagesManager = ({ isPost }: { isPost: boolean }) => {
|
||||
|
||||
{batchSelected.length > 0 ? (
|
||||
<PagesManagerBatchSelectActionTab
|
||||
isPost={isPost}
|
||||
type={type}
|
||||
pages={pages.data}
|
||||
batchSelected={batchSelected}
|
||||
setBatchSelected={setBatchSelected}
|
||||
@@ -238,7 +243,7 @@ export const PagesManager = ({ isPost }: { isPost: boolean }) => {
|
||||
<div className="-mt-3">
|
||||
{pages.isLoading && <p className="py-4 px-3">{t("Loading")}...</p>}
|
||||
{!pages.isLoading && !pages.data?.pages?.[0].count && (
|
||||
<EmptyState resource={isPost ? "posts" : "pages"} />
|
||||
<EmptyState resource={type} />
|
||||
)}
|
||||
|
||||
{pages.data?.pages.map(
|
||||
@@ -381,7 +386,7 @@ export const PagesManager = ({ isPost }: { isPost: boolean }) => {
|
||||
</Menu.Button>
|
||||
|
||||
<PagesManagerMenu
|
||||
isPost={isPost}
|
||||
type={type}
|
||||
page={page}
|
||||
onClick={close}
|
||||
/>
|
||||
@@ -403,12 +408,10 @@ export const PagesManager = ({ isPost }: { isPost: boolean }) => {
|
||||
>
|
||||
{siteT("load more", {
|
||||
name: t(
|
||||
isPost
|
||||
? "post"
|
||||
: "page" +
|
||||
((pages.data?.pages?.[0].count || 0) - currentLength > 1
|
||||
? "s"
|
||||
: ""),
|
||||
type +
|
||||
((pages.data?.pages?.[0].count || 0) - currentLength > 1
|
||||
? "s"
|
||||
: ""),
|
||||
),
|
||||
count: (pages.data?.pages?.[0].count || 0) - currentLength,
|
||||
})}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { useParams } from "next/navigation"
|
||||
import React, { useState } from "react"
|
||||
import toast from "react-hot-toast"
|
||||
|
||||
@@ -8,7 +7,7 @@ import { useQueryClient } from "@tanstack/react-query"
|
||||
import { type TabItem, Tabs } from "~/components/ui/Tabs"
|
||||
import { useTranslation } from "~/lib/i18n/client"
|
||||
import { delStorage, getStorage, setStorage } from "~/lib/storage"
|
||||
import { ExpandedNote } from "~/lib/types"
|
||||
import { ExpandedNote, NoteType } from "~/lib/types"
|
||||
import { useDeletePage, useUpdatePage } from "~/queries/page"
|
||||
|
||||
import { DeleteConfirmationModal } from "./DeleteConfirmationModal"
|
||||
@@ -18,12 +17,12 @@ function getPageId(page: ExpandedNote) {
|
||||
}
|
||||
|
||||
export const PagesManagerBatchSelectActionTab = ({
|
||||
isPost,
|
||||
type,
|
||||
pages,
|
||||
batchSelected,
|
||||
setBatchSelected,
|
||||
}: {
|
||||
isPost: boolean
|
||||
type: NoteType
|
||||
pages?: InfiniteData<{
|
||||
list: ExpandedNote[]
|
||||
}>
|
||||
@@ -32,9 +31,6 @@ export const PagesManagerBatchSelectActionTab = ({
|
||||
}) => {
|
||||
const { t } = useTranslation("dashboard")
|
||||
|
||||
const params = useParams()
|
||||
const subdomain = params?.subdomain as string
|
||||
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
// Convert or Delete page
|
||||
@@ -63,7 +59,7 @@ export const PagesManagerBatchSelectActionTab = ({
|
||||
},
|
||||
},
|
||||
{
|
||||
text: "Convert to " + (isPost ? "Page" : "Post"),
|
||||
text: "Convert to " + (type === "post" ? "Page" : "Post"),
|
||||
onClick: async () => {
|
||||
// Start message
|
||||
const toastId = toast.loading("Converting...")
|
||||
@@ -87,14 +83,14 @@ export const PagesManagerBatchSelectActionTab = ({
|
||||
// Is draft
|
||||
const key = `draft-${page?.characterId}-${page.draftKey}`
|
||||
const data = getStorage(key)
|
||||
data.isPost = !isPost
|
||||
data.type = data.type === "post" ? "page" : "post"
|
||||
setStorage(key, data)
|
||||
} else {
|
||||
// IsNote
|
||||
return updatePage.mutate({
|
||||
characterId: page.characterId,
|
||||
noteId: page.noteId,
|
||||
isPost: !isPost, // Change type
|
||||
type: type === "post" ? "page" : "post",
|
||||
})
|
||||
}
|
||||
}),
|
||||
@@ -195,7 +191,7 @@ export const PagesManagerBatchSelectActionTab = ({
|
||||
open={deleteConfirmModalOpen}
|
||||
setOpen={setDeleteConfirmModalOpen}
|
||||
onConfirm={onDelete}
|
||||
isPost={isPost}
|
||||
type={type}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -9,19 +9,17 @@ import { useGetState } from "~/hooks/useGetState"
|
||||
import { getNoteSlugFromNote, getTwitterShareUrl } from "~/lib/helpers"
|
||||
import { useTranslation } from "~/lib/i18n/client"
|
||||
import { delStorage, getStorage, setStorage } from "~/lib/storage"
|
||||
import { ExpandedNote } from "~/lib/types"
|
||||
import { ExpandedNote, NoteType } from "~/lib/types"
|
||||
import { useDeletePage, usePinPage, useUpdatePage } from "~/queries/page"
|
||||
import { useGetSite } from "~/queries/site"
|
||||
|
||||
import { DeleteConfirmationModal } from "./DeleteConfirmationModal"
|
||||
|
||||
const usePageEditLink = (page: ExpandedNote, isPost: boolean) => {
|
||||
const usePageEditLink = (page: ExpandedNote, type: NoteType) => {
|
||||
const params = useParams()
|
||||
const subdomain = params?.subdomain as string
|
||||
|
||||
return `/dashboard/${subdomain}/editor?id=${page.noteId}&type=${
|
||||
isPost ? "post" : "page"
|
||||
}`
|
||||
return `/dashboard/${subdomain}/editor?id=${page.noteId}&type=${type}`
|
||||
}
|
||||
|
||||
interface Item {
|
||||
@@ -30,11 +28,11 @@ interface Item {
|
||||
onClick: () => void
|
||||
}
|
||||
export const PagesManagerMenu = ({
|
||||
isPost,
|
||||
type,
|
||||
page,
|
||||
onClick: onClose,
|
||||
}: {
|
||||
isPost: boolean
|
||||
type: NoteType
|
||||
page: ExpandedNote
|
||||
onClick: () => void
|
||||
}) => {
|
||||
@@ -45,7 +43,7 @@ export const PagesManagerMenu = ({
|
||||
const subdomain = params?.subdomain as string
|
||||
const updatePage = useUpdatePage()
|
||||
|
||||
const editLink = usePageEditLink(page, isPost)
|
||||
const editLink = usePageEditLink(page, type)
|
||||
const queryClient = useQueryClient()
|
||||
const deletePage = useDeletePage()
|
||||
const pinPage = usePinPage(page)
|
||||
@@ -105,7 +103,7 @@ export const PagesManagerMenu = ({
|
||||
onClick: pinPage.togglePin,
|
||||
},
|
||||
{
|
||||
text: "Convert to " + (isPost ? "Page" : "Post"),
|
||||
text: "Convert to " + (type === "post" ? "Page" : "Post"),
|
||||
icon: (
|
||||
<span className="icon-[mingcute--transfer-3-line] inline-block"></span>
|
||||
),
|
||||
@@ -116,7 +114,7 @@ export const PagesManagerMenu = ({
|
||||
const data = getStorage(
|
||||
`draft-${site.data?.characterId}-${page.draftKey}`,
|
||||
)
|
||||
data.isPost = !isPost
|
||||
data.type = data.type === "post" ? "page" : "post"
|
||||
setStorage(`draft-${site.data?.characterId}-${page.draftKey}`, data)
|
||||
queryClient.invalidateQueries([
|
||||
"getPagesBySite",
|
||||
@@ -129,7 +127,7 @@ export const PagesManagerMenu = ({
|
||||
} else {
|
||||
setConvertToastId(toastId)
|
||||
updatePage.mutate({
|
||||
isPost: !isPost,
|
||||
type,
|
||||
characterId: page.characterId,
|
||||
noteId: page.noteId,
|
||||
})
|
||||
@@ -231,7 +229,7 @@ export const PagesManagerMenu = ({
|
||||
open={deleteConfirmModalOpen}
|
||||
setOpen={setDeleteConfirmModalOpen}
|
||||
onConfirm={onDelete}
|
||||
isPost={isPost}
|
||||
type={type}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from "react"
|
||||
import useOnClickOutside from "use-onclickoutside"
|
||||
|
||||
import { useTranslation } from "~/lib/i18n/client"
|
||||
import { NoteType } from "~/lib/types"
|
||||
|
||||
import { Button, ButtonGroup } from "../ui/Button"
|
||||
import { DeleteConfirmationModal } from "./DeleteConfirmationModal"
|
||||
@@ -15,7 +16,7 @@ export const PublishButton = ({
|
||||
isDisabled,
|
||||
isModified,
|
||||
twitterShareUrl,
|
||||
isPost,
|
||||
type,
|
||||
}: {
|
||||
savePage: () => void
|
||||
deletePage: () => void
|
||||
@@ -23,7 +24,7 @@ export const PublishButton = ({
|
||||
isSaving: boolean
|
||||
isDisabled: boolean
|
||||
twitterShareUrl?: string
|
||||
isPost: boolean
|
||||
type: NoteType
|
||||
isModified: boolean
|
||||
discardChanges: () => void
|
||||
}) => {
|
||||
@@ -114,7 +115,7 @@ export const PublishButton = ({
|
||||
onConfirm={() => {
|
||||
deletePage()
|
||||
}}
|
||||
isPost={isPost}
|
||||
type={type}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -6,15 +6,16 @@ import { UniLink } from "~/components/ui/UniLink"
|
||||
import { useUserRole } from "~/hooks/useUserRole"
|
||||
import { SITE_URL } from "~/lib/env"
|
||||
import { useTranslation } from "~/lib/i18n/client"
|
||||
import { NoteType } from "~/lib/types"
|
||||
|
||||
export const EditButton = ({
|
||||
handle,
|
||||
noteId,
|
||||
isPost,
|
||||
type,
|
||||
}: {
|
||||
handle?: string
|
||||
noteId?: number
|
||||
isPost?: boolean
|
||||
type?: NoteType
|
||||
}) => {
|
||||
const { t } = useTranslation("common")
|
||||
const [showEdit, setShowEdit] = useState(false)
|
||||
@@ -30,9 +31,7 @@ export const EditButton = ({
|
||||
{showEdit && (
|
||||
<UniLink
|
||||
className="xlog-post-editor inline-flex items-center"
|
||||
href={`${SITE_URL}/dashboard/${handle}/editor?id=${noteId}&type=${
|
||||
isPost ? "post" : "page"
|
||||
}`}
|
||||
href={`${SITE_URL}/dashboard/${handle}/editor?id=${noteId}&type=${type}`}
|
||||
>
|
||||
<i className="icon-[mingcute--edit-line] mx-1" /> {t("Edit")}
|
||||
</UniLink>
|
||||
|
||||
@@ -4,7 +4,7 @@ import { EditButton } from "~/components/site/EditButton"
|
||||
import PostTag from "~/components/site/PostTag"
|
||||
import { UniLink } from "~/components/ui/UniLink"
|
||||
import { CSB_SCAN } from "~/lib/env"
|
||||
import { ExpandedCharacter, ExpandedNote } from "~/lib/types"
|
||||
import { ExpandedCharacter, ExpandedNote, NoteType } from "~/lib/types"
|
||||
|
||||
export default function PostMeta({
|
||||
page,
|
||||
@@ -47,7 +47,7 @@ export default function PostMeta({
|
||||
<EditButton
|
||||
handle={site?.handle}
|
||||
noteId={page.noteId}
|
||||
isPost={page.metadata?.content?.tags?.includes("post")}
|
||||
type={page.metadata?.content?.tags?.[0] as NoteType}
|
||||
/>
|
||||
</div>
|
||||
{summary && (
|
||||
|
||||
@@ -4,7 +4,7 @@ export const EmptyState = ({ resource }: { resource?: string }) => {
|
||||
<span className="icon-[mingcute--ghost-line] text-5xl mb-2"></span>
|
||||
<div className="">
|
||||
{" "}
|
||||
No <span className="capitalize">{resource || "posts"}</span> Yet.
|
||||
No <span className="capitalize">{resource || "post"}</span> Yet.
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
{
|
||||
"Dashboard": "仪表盘",
|
||||
"Publishing": "发布",
|
||||
"Posts": "文章",
|
||||
"Pages": "页面",
|
||||
"Portfolios": "作品集",
|
||||
"Notifications": "通知",
|
||||
"Unread notifications": "未读通知",
|
||||
"Settings": "设置",
|
||||
@@ -20,6 +22,7 @@
|
||||
"Failed to convert.": "转换失败。",
|
||||
"All Posts": "所有文章",
|
||||
"All Pages": "所有页面",
|
||||
"All Portfolios": "所有作品集",
|
||||
"Published": "已发布",
|
||||
"published": "已发布",
|
||||
"Draft": "草稿",
|
||||
@@ -33,6 +36,7 @@
|
||||
"pages add": "创建页面后,你可以将其<2>添加到你网站的导航菜单中</2>,以便访问者可以找到它。",
|
||||
"New Post": "新建文章",
|
||||
"New Page": "新建页面",
|
||||
"New Portfolio": "新建作品",
|
||||
"Import": "导入",
|
||||
"Import markdown file with front matter supported": "导入 Markdown 文件(支持 Front Matter)",
|
||||
"View Site": "查看站点",
|
||||
@@ -69,6 +73,7 @@
|
||||
"Publish at": "发布时间",
|
||||
"This post will be accessible from this time. Leave blank to use the current time.": "此文章将从此时间开始可访问。留空则使用当前时间。",
|
||||
"This page will be accessible from this time. Leave blank to use the current time.": "此页面将从此时间开始可访问。留空则使用当前时间。",
|
||||
"This portfolio will be accessible from this time. Leave blank to use the current time.": "此作品将从此时间开始可访问。留空则使用当前时间。",
|
||||
"The post is currently not public as its publication date has been scheduled for a future time.": "此文章当前没有公开,因为它的发布日期已被定为将来的某个时间。",
|
||||
"Post slug": "文章短链接",
|
||||
"Page slug": "页面短链接",
|
||||
@@ -198,6 +203,7 @@
|
||||
"Confirm Deletion?": "确认删除?",
|
||||
"delete_confirmation_post": "你确定要删除这篇文章吗?",
|
||||
"delete_confirmation_page": "你确定要删除这个页面吗?",
|
||||
"delete_confirmation_portfolio": "你确定要删除这个作品吗?",
|
||||
"Confirm": "确认",
|
||||
"Cancel": "取消",
|
||||
"Published a new post on my blockchain blog: {{title}}. Check it out now!": "在我的区块链博客发布了一篇新文章《{{title}}》,快来看看吧!",
|
||||
|
||||
@@ -113,3 +113,5 @@ export type ExpandedCharacter = CharacterEntity & {
|
||||
}
|
||||
|
||||
export type ColorScheme = "dark" | "light"
|
||||
|
||||
export type NoteType = "post" | "page" | "portfolio"
|
||||
|
||||
@@ -18,7 +18,7 @@ import { filterCommentCharacter } from "~/lib/filter-character"
|
||||
import { getNoteSlug } from "~/lib/helpers"
|
||||
import { checkSlugReservedWords } from "~/lib/slug-reserved-words"
|
||||
import { getKeys, getStorage } from "~/lib/storage"
|
||||
import { ExpandedNote, PageVisibilityEnum } from "~/lib/types"
|
||||
import { ExpandedNote, NoteType, PageVisibilityEnum } from "~/lib/types"
|
||||
import { client } from "~/queries/graphql"
|
||||
|
||||
export const PINNED_PAGE_KEY = "xlog_pinned_page"
|
||||
@@ -65,14 +65,19 @@ export async function postNotes(
|
||||
|
||||
const getLocalPages = (input: {
|
||||
characterId: number
|
||||
isPost?: boolean
|
||||
isPost?: boolean // In order to be compatible with old drafts
|
||||
type?: NoteType
|
||||
handle?: string
|
||||
}) => {
|
||||
const pages: ExpandedNote[] = []
|
||||
getKeys([`draft-${input.characterId}-`, `draft-${input.handle}-`]).forEach(
|
||||
(key) => {
|
||||
const page = getStorage(key)
|
||||
if (input.isPost === undefined || page.isPost === input.isPost) {
|
||||
if (
|
||||
page.isPost === input.isPost ||
|
||||
page.type === input.type ||
|
||||
input.type === undefined
|
||||
) {
|
||||
const note: ExpandedNote = {
|
||||
characterId: input.characterId,
|
||||
noteId: 0,
|
||||
@@ -113,7 +118,7 @@ const getLocalPages = (input: {
|
||||
date_published: page.values?.publishedAt,
|
||||
summary: page.values?.excerpt,
|
||||
tags: [
|
||||
page.isPost ? "post" : "page",
|
||||
input.type,
|
||||
...(page.values?.tags
|
||||
?.split(",")
|
||||
.map((tag: string) => tag.trim())
|
||||
@@ -135,7 +140,7 @@ const getLocalPages = (input: {
|
||||
|
||||
export async function getPagesBySite(input: {
|
||||
characterId?: number
|
||||
type: "post" | "page"
|
||||
type: NoteType
|
||||
visibility?: PageVisibilityEnum
|
||||
limit?: number
|
||||
cursor?: string
|
||||
@@ -211,7 +216,8 @@ export async function getPagesBySite(input: {
|
||||
|
||||
const local = getLocalPages({
|
||||
characterId: input.characterId,
|
||||
isPost: input.type === "post",
|
||||
isPost: input.type === "post", // In order to be compatible with old drafts
|
||||
type: input.type,
|
||||
handle: input.handle,
|
||||
})
|
||||
|
||||
|
||||
+6
-5
@@ -25,6 +25,7 @@ import {
|
||||
useQueryClient,
|
||||
} from "@tanstack/react-query"
|
||||
|
||||
import { NoteType } from "~/lib/types"
|
||||
import * as pageModel from "~/models/page.model"
|
||||
|
||||
export const useGetPagesBySiteLite = (
|
||||
@@ -220,7 +221,7 @@ export function useCreatePage() {
|
||||
content?: string
|
||||
publishedAt?: string
|
||||
excerpt?: string
|
||||
isPost?: boolean
|
||||
type?: NoteType
|
||||
cover?: {
|
||||
address?: string
|
||||
mime_type?: string
|
||||
@@ -240,7 +241,7 @@ export function useCreatePage() {
|
||||
date_published: input.publishedAt || new Date().toISOString(),
|
||||
summary: input.excerpt,
|
||||
tags: [
|
||||
input.isPost ? "post" : "page",
|
||||
input.type,
|
||||
...(input.tags
|
||||
?.split(",")
|
||||
.map((tag) => tag.trim())
|
||||
@@ -306,7 +307,7 @@ export function useUpdatePage() {
|
||||
content?: string
|
||||
publishedAt?: string
|
||||
excerpt?: string
|
||||
isPost?: boolean
|
||||
type?: NoteType
|
||||
cover?: {
|
||||
address?: string
|
||||
mime_type?: string
|
||||
@@ -341,8 +342,8 @@ export function useUpdatePage() {
|
||||
if (!metadataDraft.tags) {
|
||||
metadataDraft.tags = []
|
||||
}
|
||||
if (input.isPost !== undefined) {
|
||||
metadataDraft.tags[0] = input.isPost ? "post" : "page"
|
||||
if (input.type !== undefined) {
|
||||
metadataDraft.tags[0] = input.type
|
||||
}
|
||||
if (input.tags !== undefined) {
|
||||
metadataDraft.tags = [
|
||||
|
||||
Reference in New Issue
Block a user