Merge branch 'pr/zsakvo/304' into dev

This commit is contained in:
DIYgod
2023-04-10 00:14:31 +01:00
12 changed files with 719 additions and 258 deletions
+1
View File
@@ -108,6 +108,7 @@
"sharp": "0.32.0",
"sortablejs": "1.15.0",
"tailwind-merge": "^1.12.0",
"tailwind-scrollbar-hide": "^1.1.7",
"tailwindcss-animate": "^1.0.5",
"unidata.js": "0.7.18",
"unified": "10.1.2",
+7
View File
@@ -253,6 +253,9 @@ dependencies:
tailwind-merge:
specifier: ^1.12.0
version: 1.12.0
tailwind-scrollbar-hide:
specifier: ^1.1.7
version: 1.1.7
tailwindcss-animate:
specifier: ^1.0.5
version: 1.0.5(tailwindcss@3.3.1)
@@ -12080,6 +12083,10 @@ packages:
resolution: {integrity: sha512-Y17eDp7FtN1+JJ4OY0Bqv9OA41O+MS8c1Iyr3T6JFLnOgLg3EvcyMKZAnQ8AGyvB5Nxm3t9Xb5Mhe139m8QT/g==}
dev: false
/tailwind-scrollbar-hide@1.1.7:
resolution: {integrity: sha512-X324n9OtpTmOMqEgDUEA/RgLrNfBF/jwJdctaPZDzB3mppxJk7TLIDmOreEDm1Bq4R9LSPu4Epf8VSdovNU+iA==}
dev: false
/tailwindcss-animate@1.0.5(tailwindcss@3.3.1):
resolution: {integrity: sha512-UU3qrOJ4lFQABY+MVADmBm+0KW3xZyhMdRvejwtXqYOL7YjHYxmuREFAZdmVG5LPe5E9CAst846SLC4j5I3dcw==}
peerDependencies:
+180 -93
View File
@@ -1,6 +1,6 @@
import { cn } from "~/lib/utils"
import { useRouter } from "next/router"
import React, { useEffect } from "react"
import React, { useEffect, useState } from "react"
import { DISCORD_LINK, APP_NAME } from "~/lib/env"
import { getSiteLink } from "~/lib/helpers"
@@ -22,6 +22,8 @@ import { useTranslation } from "react-i18next"
import { Logo } from "~/components/common/Logo"
import { getStorage } from "~/lib/storage"
import { useGetPagesBySite } from "~/queries/page"
import { DashboardTopbar } from "./DashboardTopbar"
import { useMobileLayout } from "~/hooks/useMobileLayout"
export function DashboardLayout({
children,
@@ -45,6 +47,8 @@ export function DashboardLayout({
const [hasPermission, setHasPermission] = React.useState(false)
const { t } = useTranslation("dashboard")
const isMobileLayout = useMobileLayout()
useEffect(() => {
if (ssrReady) {
if (!isConnected) {
@@ -169,102 +173,185 @@ export function DashboardLayout({
/>
)}
<div className="flex h-screen">
<DashboardSidebar>
{(isOpen) => (
<>
<div className="flex-1 min-h-0 flex flex-col">
<div className="mb-2 px-5 pt-3 pb-2 text-2xl font-extrabold flex items-center">
<div className="inline-block w-9 h-9 mr-3">
<Logo
type="lottie"
width={36}
height={36}
autoplay={false}
{isMobileLayout ? (
<DashboardTopbar
userWidget={
<div className="mb-2 px-2 pt-3 pb-2">
<ConnectButton
left={true}
size="base"
hideNotification={true}
hideName={false}
/>
</div>
}
drawerWidget={(close: any) => (
<>
<div className="flex-1 min-h-0 flex flex-col h-full">
<div className="mb-2 px-5 pt-3 pb-2 text-2xl font-extrabold flex items-center">
<div className="inline-block w-9 h-9 mr-3">
<Logo
type="lottie"
width={36}
height={36}
autoplay={false}
/>
</div>
{"xLog"}
</div>
<div className="px-3 space-y-[2px] text-zinc-500 flex-1 min-h-0 overflow-y-auto">
{links.map((link) => {
const active =
link.href &&
link.isActive({
pathname: router.asPath,
href: link.href,
})
return (
<div key={link.text} onClick={() => close()}>
<UniLink
href={link.href}
className={cn(
`flex px-4 h-12 items-center rounded-md space-x-2 w-full transition-colors`,
active
? `bg-slate-200 font-medium text-accent`
: `hover:bg-slate-200 hover:bg-opacity-50`,
!true && "justify-center",
)}
onClick={link.onClick}
>
<span className={cn(link.icon, "text-xl")}></span>
<span>{t(link.text)}</span>
</UniLink>
</div>
)
})}
</div>
<div className="flex items-center px-4 flex-col pb-4">
<UniLink
href={DISCORD_LINK}
className="space-x-1 text-zinc-500 hover:text-zinc-800 flex w-full h-12 items-center justify-center transition-colors mb-2"
>
<i className="i-mingcute:question-line text-lg" />
{<span>{t("Need help?")}</span>}
</UniLink>
<UniLink
href={getSiteLink({
subdomain,
})}
className="space-x-2 border rounded-lg bg-slate-100 border-slate-200 text-accent hover:scale-105 transition-transform flex w-full h-12 items-center justify-center"
>
<span className="i-mingcute:home-1-line"></span>
{<span>{t("View Site")}</span>}
</UniLink>
</div>
</div>
</>
)}
>
{(isOpen) => <div>233</div>}
</DashboardTopbar>
) : (
<DashboardSidebar>
{(isOpen) => (
<>
<div className="flex-1 min-h-0 flex flex-col">
<div className="mb-2 px-5 pt-3 pb-2 text-2xl font-extrabold flex items-center">
<div className="inline-block w-9 h-9 mr-3">
<Logo
type="lottie"
width={36}
height={36}
autoplay={false}
/>
</div>
{isOpen && "xLog"}
</div>
{userSite.data?.[0]?.username &&
subdomain &&
userSite.data[0].username !== subdomain && (
<div className="mb-2 px-5 pt-3 pb-2 bg-orange-50 text-center">
<div className="mb-2">
{isOpen && "You are operating"}
</div>
<Avatar
images={site.data?.avatars || []}
size={isOpen ? 60 : 40}
name={site.data?.name}
/>
{isOpen && (
<span className="flex flex-col justify-center">
<span className="block">{site.data?.name}</span>
<span className="block text-sm text-zinc-400">
@{site.data?.username}
</span>
</span>
)}
</div>
)}
<div className="mb-2 px-2 pt-3 pb-2">
<ConnectButton
left={true}
size="base"
hideNotification={true}
hideName={!isOpen}
/>
</div>
{isOpen && "xLog"}
</div>
{userSite.data?.[0]?.username &&
subdomain &&
userSite.data[0].username !== subdomain && (
<div className="mb-2 px-5 pt-3 pb-2 bg-orange-50 text-center">
<div className="mb-2">
{isOpen && "You are operating"}
</div>
<Avatar
images={site.data?.avatars || []}
size={isOpen ? 60 : 40}
name={site.data?.name}
/>
{isOpen && (
<span className="flex flex-col justify-center">
<span className="block">{site.data?.name}</span>
<span className="block text-sm text-zinc-400">
@{site.data?.username}
</span>
</span>
)}
</div>
)}
<div className="mb-2 px-2 pt-3 pb-2">
<ConnectButton
left={true}
size="base"
hideNotification={true}
hideName={!isOpen}
/>
</div>
<div className="px-3 space-y-[2px] text-zinc-500 flex-1 min-h-0 overflow-y-auto">
{links.map((link) => {
const active =
link.href &&
link.isActive({
pathname: router.asPath,
href: link.href,
})
return (
<UniLink
href={link.href}
key={link.text}
className={cn(
`flex px-4 h-12 items-center rounded-md space-x-2 w-full transition-colors`,
active
? `bg-slate-200 font-medium text-accent`
: `hover:bg-slate-200 hover:bg-opacity-50`,
!isOpen && "justify-center",
)}
onClick={link.onClick}
>
<span className={cn(link.icon, "text-xl")}></span>
{isOpen && <span>{t(link.text)}</span>}
</UniLink>
)
})}
<div className="px-3 space-y-[2px] text-zinc-500 flex-1 min-h-0 overflow-y-auto">
{links.map((link) => {
const active =
link.href &&
link.isActive({
pathname: router.asPath,
href: link.href,
})
return (
<UniLink
href={link.href}
key={link.text}
className={cn(
`flex px-4 h-12 items-center rounded-md space-x-2 w-full transition-colors`,
active
? `bg-slate-200 font-medium text-accent`
: `hover:bg-slate-200 hover:bg-opacity-50`,
!isOpen && "justify-center",
)}
onClick={link.onClick}
>
<span className={cn(link.icon, "text-xl")}></span>
{isOpen && <span>{t(link.text)}</span>}
</UniLink>
)
})}
</div>
</div>
</div>
<div className="flex items-center px-4 flex-col pb-4">
<UniLink
href={DISCORD_LINK}
className="space-x-1 text-zinc-500 hover:text-zinc-800 flex w-full h-12 items-center justify-center transition-colors mb-2"
>
<i className="i-mingcute:question-line text-lg" />
{isOpen && <span>{t("Need help?")}</span>}
</UniLink>
<UniLink
href={getSiteLink({
subdomain,
})}
className="space-x-2 border rounded-lg bg-slate-100 border-slate-200 text-accent hover:scale-105 transition-transform flex w-full h-12 items-center justify-center"
>
<span className="i-mingcute:home-1-line"></span>
{isOpen && <span>{t("View Site")}</span>}
</UniLink>
</div>
</>
)}
</DashboardSidebar>
{children}
<div className="flex items-center px-4 flex-col pb-4">
<UniLink
href={DISCORD_LINK}
className="space-x-1 text-zinc-500 hover:text-zinc-800 flex w-full h-12 items-center justify-center transition-colors mb-2"
>
<i className="i-mingcute:question-line text-lg" />
{isOpen && <span>{t("Need help?")}</span>}
</UniLink>
<UniLink
href={getSiteLink({
subdomain,
})}
className="space-x-2 border rounded-lg bg-slate-100 border-slate-200 text-accent hover:scale-105 transition-transform flex w-full h-12 items-center justify-center"
>
<span className="i-mingcute:home-1-line"></span>
{isOpen && <span>{t("View Site")}</span>}
</UniLink>
</div>
</>
)}
</DashboardSidebar>
)}
<div className={`${isMobileLayout ? "pt-16" : "flex-1"}`}>
{children}
</div>
</div>
</>
) : (
+4 -3
View File
@@ -1,5 +1,6 @@
import { cn } from "~/lib/utils"
import { useTranslation } from "next-i18next"
import { useMobileLayout } from "~/hooks/useMobileLayout"
export const DashboardMain: React.FC<{
children: React.ReactNode
@@ -8,15 +9,15 @@ export const DashboardMain: React.FC<{
className?: string
}> = ({ children, fullWidth, title, className }) => {
const { t } = useTranslation("dashboard")
const isMobileLayout = useMobileLayout()
return (
<div className="flex-1 overflow-scroll">
<div
className={cn(
fullWidth
? "relative"
: "max-w-screen-2xl min-w-[270px] relative px-5 py-5 md:px-10",
fullWidth ? "relative" : "min-w-[270px] relative px-5 py-5 md:px-10",
className,
isMobileLayout ? "max-w-[100vw]" : "",
)}
>
{title && <p className="text-2xl font-bold mb-8">{t(title)}</p>}
@@ -0,0 +1,70 @@
import { useState, useEffect, useMemo, Fragment } from "react"
import { setStorage, getStorage } from "~/lib/storage"
import { Bars3Icon, ChevronDownIcon } from "@heroicons/react/24/outline"
import { Logo } from "../common/Logo"
import { Popover, Transition } from "@headlessui/react"
export const DashboardTopbar: React.FC<{
children: (open: boolean) => React.ReactNode
userWidget: React.ReactNode
drawerWidget: (close: any) => React.ReactNode
}> = ({ children, userWidget, drawerWidget }) => {
const [isOpen, setIsOpen] = useState(false)
return (
<div className="w-full top-0 h-16 bg-slate-50 z-20 transition-all flex flex-row fixed px-5 md:px-10 items-center">
<Popover className="relative">
{({ open, close }) => (
<div className="h-6">
<Transition
as={Fragment}
enter="transition ease-out duration-200"
enterFrom="opacity-0"
enterTo="opacity-10"
leave="transition ease-in duration-150"
leaveFrom="opacity-10"
leaveTo="opacity-0"
>
<Popover.Overlay className="fixed inset-0 bg-black opacity-10" />
</Transition>
<Popover.Button
className={`
group inline-flex items-center rounded-md text-base font-medium hover:text-opacity-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75`}
onClick={() => {
setIsOpen(true)
}}
>
<Bars3Icon className="h-6 w-6" />
</Popover.Button>
<Transition
as={Fragment}
enter="transition ease-out duration-200"
enterFrom="opacity-0 transform -translate-x-full"
enterTo="opacity-100 transform translate-x-0"
leave="transition ease-in duration-150"
leaveFrom="opacity-100 transform translate-x-0"
leaveTo="opacity-0 transform -translate-x-full"
>
<Popover.Panel className="fixed bg-slate-50 h-full left-0 top-0 z-20 w-sidebar transform sm:px-0 lg:max-w-3xl">
<div className="overflow-hidden rounded-lg shadow-lg ring-1 ring-black ring-opacity-5 h-full">
{drawerWidget(close)}
</div>
</Popover.Panel>
</Transition>
</div>
)}
</Popover>
<div className="mb-2 px-5 pt-3 pb-2 text-2xl font-extrabold flex items-center">
<div className="inline-block w-9 h-9 mr-3">
<Logo type="lottie" width={36} height={36} autoplay={false} />
</div>
xLog
</div>
<div className="flex-1"></div>
{userWidget}
<div className="w-[1px] bg-border absolute top-0 right-0 bottom-0"></div>
</div>
)
}
+161
View File
@@ -0,0 +1,161 @@
import { Menu, Popover, Transition } from "@headlessui/react"
import { Dispatch, Fragment, SetStateAction, useState } from "react"
import { useTranslation } from "react-i18next"
import { PageVisibilityEnum } from "~/lib/types"
import { cn } from "~/lib/utils"
export const OptionsButton: React.FC<{
visibility: PageVisibilityEnum | undefined
previewPage: () => void
renderPage: Dispatch<SetStateAction<boolean>>
savePage: (published: boolean) => any
propertiesWidget: React.ReactNode
isRendering: boolean
published: boolean
}> = ({
visibility,
previewPage,
savePage,
isRendering,
renderPage,
published,
propertiesWidget,
}) => {
const { t } = useTranslation("dashboard")
return (
<>
<div
className="bg-accent rounded-full cursor-pointer text-white w-6 h-6 flex justify-center items-center"
onClick={() => renderPage(!isRendering)}
>
{isRendering ? (
<i className="i-mingcute:eye-close-line text-xl inline-block w-6 h-6" />
) : (
<i className="i-mingcute:eye2-line text-xl inline-block w-6 h-6" />
)}
</div>
<Menu as="div" className="relative inline-block text-left h-6">
{({ open, close }) => {
return (
<>
<Menu.Button>
<div className="bg-accent rounded-full cursor-pointer text-white w-6 h-6">
{open ? (
<i className="i-mingcute:up-line text-2xl inline-block w-6 h-6" />
) : (
<i className="i-mingcute:down-line text-2xl inline-block w-6 h-6" />
)}
</div>
</Menu.Button>
<Transition
as={Fragment}
enter="transition ease-out duration-100"
enterFrom="transform opacity-0 scale-95"
enterTo="transform opacity-100 scale-100"
leave="transition ease-in duration-75"
leaveFrom="transform opacity-100 scale-100"
leaveTo="transform opacity-0 scale-95"
>
<Menu.Items className="absolute right-0 mt-2 z-30 w-56 origin-top-right divide-y divide-gray-100 rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none">
<div className="px-1 py-1 ">
<Menu.Item disabled>
{({ active }) => (
<button
className={`${cn(
`text-sm capitalize`,
visibility === PageVisibilityEnum.Draft
? `text-zinc-300`
: visibility === PageVisibilityEnum.Modified
? "text-orange-600"
: "text-green-600",
)} group flex w-full items-center rounded-md px-2 py-2 text-sm`}
>
{t(visibility as string)}
</button>
)}
</Menu.Item>
</div>
<div className="px-1 py-1 ">
<Menu.Item>
{({ active }) => (
<button
className={`${
active ? "bg-accent text-white" : "text-gray-900"
} group flex w-full items-center rounded-md px-2 py-2 text-sm`}
onClick={previewPage}
>
{t("Preview")}
</button>
)}
</Menu.Item>
<Menu.Item>
{({ active }) => (
<button
className={`${
active ? "bg-accent text-white" : "text-gray-900"
} group flex w-full items-center rounded-md px-2 py-2 text-sm`}
onClick={() => savePage(true)}
>
{t(published ? "Update" : "Publish")}
</button>
)}
</Menu.Item>
<Menu.Item>
{({ active }) => (
<button
className={`${
active
? "bg-red-600 text-white"
: "text-red-600 bg-white"
} group flex w-full items-center rounded-md px-2 py-2 text-sm`}
onClick={() => savePage(false)}
>
{t("Delete")}
</button>
)}
</Menu.Item>
</div>
</Menu.Items>
</Transition>
</>
)
}}
</Menu>
<Popover className="relative">
{({ open, close }) => (
<div className="h-6">
<Popover.Button
className={`
group inline-flex items-center rounded-md text-base font-medium hover:text-opacity-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75`}
// onClick={() => {
// setIsOpen(true)
// }}
>
<div className="bg-accent rounded-full cursor-pointer text-white w-6 h-6 flex justify-center items-center">
<i className="i-mingcute:attachment-2-line text-xl inline-block w-6 h-6" />
</div>
</Popover.Button>
<Transition
as={Fragment}
enter="transition ease-out duration-200"
enterFrom="opacity-0 transform -translate-x-full"
enterTo="opacity-100 transform translate-x-0"
leave="transition ease-in duration-150"
leaveFrom="opacity-100 transform translate-x-0"
leaveTo="opacity-0 transform -translate-x-full"
>
<Popover.Panel className="fixed bg-slate-50 h-full left-0 top-0 z-30 transform sm:px-0 lg:max-w-3xl">
<div className="overflow-hidden rounded-lg shadow-lg ring-1 ring-black ring-opacity-5 h-full">
{propertiesWidget}
</div>
</Popover.Panel>
</Transition>
</div>
)}
</Popover>
</>
)
}
@@ -19,6 +19,7 @@ import { Tooltip } from "../ui/Tooltip"
import { Trans, useTranslation } from "next-i18next"
import { readFiles } from "~/lib/read-files"
import { PagesManagerMenu } from "./PagesManagerMenu"
import { useMobileLayout } from "~/hooks/useMobileLayout"
export const PagesManager: React.FC<{
isPost: boolean
@@ -37,6 +38,8 @@ export const PagesManager: React.FC<{
const { t } = useTranslation(["dashboard", "site"])
const date = useDate()
const isMobileLayout = useMobileLayout()
const pages = useGetPagesBySite({
type: isPost ? "post" : "page",
site: subdomain!,
+6 -1
View File
@@ -5,6 +5,7 @@ import { scroll } from "@uiw/codemirror-extensions-events"
import type { EditorState } from "@codemirror/state"
import { useState, useEffect, useMemo } from "react"
import { useTranslation } from "next-i18next"
import { useMobileLayout } from "~/hooks/useMobileLayout"
export const Editor: React.FC<{
value: string
@@ -25,6 +26,7 @@ export const Editor: React.FC<{
}) => {
const { t } = useTranslation("dashboard")
const [extensions, setExtensions] = useState<any>([])
const isMobileLayout = useMobileLayout()
useEffect(() => {
setExtensions([
markdown(),
@@ -34,6 +36,7 @@ export const Editor: React.FC<{
fontSize: "1rem",
overflow: "auto",
height: "100%",
padding: isMobileLayout ? "0 1.25rem" : "unset",
},
".cm-content": {
paddingBottom: "600px",
@@ -85,7 +88,9 @@ export const Editor: React.FC<{
return useMemo(
() => (
<CodeMirror
className="px-5 h-full border-r w-1/2"
className={`h-full ${
isMobileLayout ? "w-full" : "border-r w-1/2 px-5"
}`}
value={value}
extensions={extensions}
onCreateEditor={onCreateEditor}
+4 -1
View File
@@ -21,7 +21,10 @@ export const Tabs: React.FC<{ items: TabItem[]; className?: string }> = ({
return (
<div
className={cn(className, "flex border-b space-x-5 mb-8 overflow-x-auto")}
className={cn(
className,
"flex border-b space-x-5 mb-8 overflow-x-auto scrollbar-hide",
)}
>
{items.map((item) => {
if (item.hidden) return null
+24
View File
@@ -0,0 +1,24 @@
import { useCallback, useEffect, useState } from "react"
const mobileWidth = 1024
export function useMobileLayout() {
const [isMobile, setIsMobile] = useState(false)
const onResize = useCallback(() => {
setIsMobile(window.innerWidth < mobileWidth)
}, [])
useEffect(() => {
window.addEventListener("resize", onResize)
return () => {
window.removeEventListener("resize", onResize)
}
}, [onResize])
useEffect(() => {
setIsMobile(window.innerWidth < mobileWidth)
}, [])
return isMobile
}
+258 -159
View File
@@ -42,6 +42,8 @@ import { getServerSideProps as getLayoutServerSideProps } from "~/components/das
import { GetServerSideProps } from "next"
import { serverSidePropsHandler } from "~/lib/server-side-props"
import { getDefaultSlug } from "~/lib/helpers"
import { useMobileLayout } from "~/hooks/useMobileLayout"
import { OptionsButton } from "~/components/dashboard/OptionsButton"
export const getServerSideProps: GetServerSideProps = serverSidePropsHandler(
async (ctx) => {
@@ -163,6 +165,9 @@ export default function SubdomainEditor() {
const createOrUpdatePage = useCreateOrUpdatePage()
const isMobileLayout = useMobileLayout()
const [isRendering, setIsRendering] = useState(false)
const savePage = async (published: boolean) => {
const check = await checkPageSlug({
slug: values.slug || defaultSlug,
@@ -192,6 +197,96 @@ export default function SubdomainEditor() {
const [isCheersOpen, setIsCheersOpen] = useState(false)
const ExtraProperties = (
<div className="h-full overflow-auto flex-shrink-0 w-[280px] border-l bg-zinc-50 p-5 space-y-5">
<div>
<Input
type="datetime-local"
label={t("Publish at") || ""}
isBlock
name="publishAt"
id="publishAt"
value={getInputDatetimeValue(values.publishedAt, date.dayjs)}
onChange={(e: ChangeEvent<HTMLInputElement>) => {
try {
const value = date.inLocalTimezone(e.target.value).toISOString()
updateValue("publishedAt", value)
} catch (error) {}
}}
help={t(
`This ${
isPost ? "post" : "page"
} will be accessible from this time`,
)}
/>
</div>
<div>
<Input
name="slug"
value={values.slug}
placeholder={defaultSlug}
label={t(`${isPost ? "Post" : "Page"} slug`) || ""}
id="slug"
isBlock
onChange={(e: ChangeEvent<HTMLInputElement>) =>
updateValue("slug", e.target.value)
}
help={
<>
{(values.slug || defaultSlug) && (
<>
{t(`This ${isPost ? "post" : "page"} will be accessible at`)}{" "}
<UniLink
href={`${getSiteLink({
subdomain,
domain: site.data?.custom_domain,
})}/${encodeURIComponent(values.slug || defaultSlug)}`}
className="hover:underline"
>
{getSiteLink({
subdomain,
domain: site.data?.custom_domain,
noProtocol: true,
})}
/{encodeURIComponent(values.slug || defaultSlug)}
</UniLink>
</>
)}
</>
}
/>
</div>
<div>
<Input
name="tags"
value={values.tags}
label={t("Tags") || ""}
id="tags"
isBlock
onChange={(e: ChangeEvent<HTMLInputElement>) =>
updateValue("tags", e.target.value)
}
help={t("Separate multiple tags with English commas") + ` ","`}
/>
</div>
<div>
<Input
label={t("Excerpt") || ""}
isBlock
name="excerpt"
id="excerpt"
value={values.excerpt}
multiline
rows={5}
onChange={(e: ChangeEvent<HTMLTextAreaElement>) => {
updateValue("excerpt", e.target.value)
}}
help={t("Leave it blank to use auto-generated excerpt")}
/>
</div>
</div>
)
useEffect(() => {
if (createOrUpdatePage.isSuccess) {
if (createOrUpdatePage.data?.code === 0) {
@@ -406,8 +501,18 @@ export default function SubdomainEditor() {
</div>
) : (
<>
<header className="flex justify-between absolute top-0 left-0 right-0 z-10 px-5 h-14 border-b items-center text-sm">
<div className="flex items-center">
<header
className={`flex justify-between absolute top-0 left-0 right-0 z-25 px-5 h-14 border-b items-center text-sm ${
isMobileLayout ? "w-screen" : undefined
}`}
>
<div
className={`flex items-center ${
isMobileLayout
? "flex-1 overflow-x-auto scrollbar-hide"
: undefined
}`}
>
<EditorToolbar view={view} toolbars={toolbars}></EditorToolbar>
<UniLink
className="ml-7 align-middle hidden xl:block"
@@ -418,44 +523,105 @@ export default function SubdomainEditor() {
{t("Tip: xLog Flavored Markdown")}
</UniLink>
</div>
<div className="flex items-center space-x-3">
<span
className={cn(
`text-sm capitalize`,
visibility === PageVisibilityEnum.Draft
? `text-zinc-300`
: visibility === PageVisibilityEnum.Modified
? "text-orange-600"
: "text-green-600",
)}
>
{t(visibility as string)}
</span>
<Button
isAutoWidth
onClick={() => {
window.open(
`/_site/${subdomain}/preview/${draftKey.replace(
`draft-${subdomain}-`,
"",
)}`,
)
}}
>
{t("Preview")}
</Button>
<PublishButton
save={savePage}
published={visibility !== PageVisibilityEnum.Draft}
isSaving={createOrUpdatePage.isLoading}
isDisabled={
visibility !== PageVisibilityEnum.Modified &&
visibility !== PageVisibilityEnum.Draft
}
/>
</div>
{isMobileLayout ? (
<div className="flex items-center space-x-3 w-auto inline-block pl-5">
{/* <span
className={cn(
`text-sm capitalize`,
visibility === PageVisibilityEnum.Draft
? `text-zinc-300`
: visibility === PageVisibilityEnum.Modified
? "text-orange-600"
: "text-green-600",
)}
>
{t(visibility as string)}
</span> */}
{/* <Button
isAutoWidth
onClick={() => {
window.open(
`/_site/${subdomain}/preview/${draftKey.replace(
`draft-${subdomain}-`,
"",
)}`,
)
}}
>
{t("Preview")}
</Button> */}
{/* <PublishButton
save={savePage}
published={visibility !== PageVisibilityEnum.Draft}
isSaving={createOrUpdatePage.isLoading}
isDisabled={
visibility !== PageVisibilityEnum.Modified &&
visibility !== PageVisibilityEnum.Draft
}
/> */}
<OptionsButton
visibility={visibility}
savePage={savePage}
published={visibility !== PageVisibilityEnum.Draft}
isRendering={isRendering}
renderPage={setIsRendering}
propertiesWidget={ExtraProperties}
previewPage={() => {
window.open(
`/_site/${subdomain}/preview/${draftKey.replace(
`draft-${subdomain}-`,
"",
)}`,
)
}}
/>
</div>
) : (
<div className="flex items-center space-x-3">
<span
className={cn(
`text-sm capitalize`,
visibility === PageVisibilityEnum.Draft
? `text-zinc-300`
: visibility === PageVisibilityEnum.Modified
? "text-orange-600"
: "text-green-600",
)}
>
{t(visibility as string)}
</span>
<Button
isAutoWidth
onClick={() => {
window.open(
`/_site/${subdomain}/preview/${draftKey.replace(
`draft-${subdomain}-`,
"",
)}`,
)
}}
>
{t("Preview")}
</Button>
<PublishButton
save={savePage}
published={visibility !== PageVisibilityEnum.Draft}
isSaving={createOrUpdatePage.isLoading}
isDisabled={
visibility !== PageVisibilityEnum.Modified &&
visibility !== PageVisibilityEnum.Draft
}
/>
</div>
)}
</header>
<div className="h-screen pt-14 flex w-full min-w-[840px]">
<div
className={`pt-14 flex w-full ${
isMobileLayout
? "w-screen h-[calc(100vh-4rem)]"
: "min-w-[840px] h-screen "
}`}
>
<div className="h-full overflow-auto w-full">
<div className="h-full mx-auto pt-5 flex flex-col">
<div className="px-5 h-12">
@@ -474,129 +640,62 @@ export default function SubdomainEditor() {
/>
</div>
<div className="mt-5 flex-1 flex overflow-hidden">
<Editor
value={values.content}
onChange={onChange}
handleDropFile={handleDropFile}
onScroll={onEditorScroll}
// onUpdate={onUpdate}
onCreateEditor={onCreateEditor}
onMouseEnter={() => {
setCurrentScrollArea("editor")
}}
/>
<PageContent
className="px-5 w-1/2 overflow-scroll pb-[200px]"
parsedContent={parsedContent}
inputRef={previewRef}
onScroll={onPreviewScroll}
onMouseEnter={() => {
setCurrentScrollArea("preview")
}}
></PageContent>
{isMobileLayout ? (
!isRendering ? (
<Editor
value={values.content}
onChange={onChange}
handleDropFile={handleDropFile}
onScroll={onEditorScroll}
// onUpdate={onUpdate}
onCreateEditor={onCreateEditor}
onMouseEnter={() => {
setCurrentScrollArea("editor")
}}
/>
) : (
<PageContent
className={`px-5 overflow-scroll pb-[200px] ${
isMobileLayout ? "" : "w-1/2 "
}`}
parsedContent={parsedContent}
inputRef={previewRef}
onScroll={onPreviewScroll}
onMouseEnter={() => {
setCurrentScrollArea("preview")
}}
></PageContent>
)
) : (
<>
<Editor
value={values.content}
onChange={onChange}
handleDropFile={handleDropFile}
onScroll={onEditorScroll}
// onUpdate={onUpdate}
onCreateEditor={onCreateEditor}
onMouseEnter={() => {
setCurrentScrollArea("editor")
}}
/>
<PageContent
className={`px-5 overflow-scroll pb-[200px] ${
isMobileLayout ? "" : "w-1/2 "
}`}
parsedContent={parsedContent}
inputRef={previewRef}
onScroll={onPreviewScroll}
onMouseEnter={() => {
setCurrentScrollArea("preview")
}}
></PageContent>
</>
)}
</div>
</div>
</div>
<div className="h-full overflow-auto flex-shrink-0 w-[280px] border-l bg-zinc-50 p-5 space-y-5">
<div>
<Input
type="datetime-local"
label={t("Publish at") || ""}
isBlock
name="publishAt"
id="publishAt"
value={getInputDatetimeValue(
values.publishedAt,
date.dayjs,
)}
onChange={(e: ChangeEvent<HTMLInputElement>) => {
try {
const value = date
.inLocalTimezone(e.target.value)
.toISOString()
updateValue("publishedAt", value)
} catch (error) {}
}}
help={t(
`This ${
isPost ? "post" : "page"
} will be accessible from this time`,
)}
/>
</div>
<div>
<Input
name="slug"
value={values.slug}
placeholder={defaultSlug}
label={t(`${isPost ? "Post" : "Page"} slug`) || ""}
id="slug"
isBlock
onChange={(e: ChangeEvent<HTMLInputElement>) =>
updateValue("slug", e.target.value)
}
help={
<>
{(values.slug || defaultSlug) && (
<>
{t(
`This ${
isPost ? "post" : "page"
} will be accessible at`,
)}{" "}
<UniLink
href={`${getSiteLink({
subdomain,
domain: site.data?.custom_domain,
})}/${encodeURIComponent(
values.slug || defaultSlug,
)}`}
className="hover:underline"
>
{getSiteLink({
subdomain,
domain: site.data?.custom_domain,
noProtocol: true,
})}
/{encodeURIComponent(values.slug || defaultSlug)}
</UniLink>
</>
)}
</>
}
/>
</div>
<div>
<Input
name="tags"
value={values.tags}
label={t("Tags") || ""}
id="tags"
isBlock
onChange={(e: ChangeEvent<HTMLInputElement>) =>
updateValue("tags", e.target.value)
}
help={
t("Separate multiple tags with English commas") + ` ","`
}
/>
</div>
<div>
<Input
label={t("Excerpt") || ""}
isBlock
name="excerpt"
id="excerpt"
value={values.excerpt}
multiline
rows={5}
onChange={(e: ChangeEvent<HTMLTextAreaElement>) => {
updateValue("excerpt", e.target.value)
}}
help={t("Leave it blank to use auto-generated excerpt")}
/>
</div>
</div>
{!isMobileLayout && ExtraProperties}
</div>
</>
)}
+1 -1
View File
@@ -60,5 +60,5 @@ module.exports = {
},
},
variants: {},
plugins: [require("tailwindcss-animate")],
plugins: [require("tailwindcss-animate"), require("tailwind-scrollbar-hide")],
}