diff --git a/package.json b/package.json index 8b9c0df4..3ed8fdff 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7f50f8ba..bf025af7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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: diff --git a/src/components/dashboard/DashboardLayout.tsx b/src/components/dashboard/DashboardLayout.tsx index 3b3a5b86..4f36dc0e 100644 --- a/src/components/dashboard/DashboardLayout.tsx +++ b/src/components/dashboard/DashboardLayout.tsx @@ -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({ /> )}
- - {(isOpen) => ( - <> -
-
-
- + +
+ } + drawerWidget={(close: any) => ( + <> +
+
+
+ +
+ {"xLog"} +
+
+ {links.map((link) => { + const active = + link.href && + link.isActive({ + pathname: router.asPath, + href: link.href, + }) + return ( +
close()}> + + + {t(link.text)} + +
+ ) + })} +
+
+ + + {{t("Need help?")}} + + + + {{t("View Site")}} + +
+
+ + )} + > + {(isOpen) =>
233
} + + ) : ( + + {(isOpen) => ( + <> +
+
+
+ +
+ {isOpen && "xLog"} +
+ {userSite.data?.[0]?.username && + subdomain && + userSite.data[0].username !== subdomain && ( +
+
+ {isOpen && "You are operating"} +
+ + {isOpen && ( + + {site.data?.name} + + @{site.data?.username} + + + )} +
+ )} +
+
- {isOpen && "xLog"} -
- {userSite.data?.[0]?.username && - subdomain && - userSite.data[0].username !== subdomain && ( -
-
- {isOpen && "You are operating"} -
- - {isOpen && ( - - {site.data?.name} - - @{site.data?.username} - - - )} -
- )} -
- -
-
- {links.map((link) => { - const active = - link.href && - link.isActive({ - pathname: router.asPath, - href: link.href, - }) - return ( - - - {isOpen && {t(link.text)}} - - ) - })} +
+ {links.map((link) => { + const active = + link.href && + link.isActive({ + pathname: router.asPath, + href: link.href, + }) + return ( + + + {isOpen && {t(link.text)}} + + ) + })} +
-
-
- - - {isOpen && {t("Need help?")}} - - - - {isOpen && {t("View Site")}} - -
- - )} - - {children} +
+ + + {isOpen && {t("Need help?")}} + + + + {isOpen && {t("View Site")}} + +
+ + )} + + )} + +
+ {children} +
) : ( diff --git a/src/components/dashboard/DashboardMain.tsx b/src/components/dashboard/DashboardMain.tsx index 82ef7561..e194930e 100644 --- a/src/components/dashboard/DashboardMain.tsx +++ b/src/components/dashboard/DashboardMain.tsx @@ -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 (
{title &&

{t(title)}

} diff --git a/src/components/dashboard/DashboardTopbar.tsx b/src/components/dashboard/DashboardTopbar.tsx new file mode 100644 index 00000000..1fecffe4 --- /dev/null +++ b/src/components/dashboard/DashboardTopbar.tsx @@ -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 ( +
+ + {({ open, close }) => ( +
+ + + + { + setIsOpen(true) + }} + > + + + + +
+ {drawerWidget(close)} +
+
+
+
+ )} +
+ +
+
+ +
+ xLog +
+
+ {userWidget} +
+
+ ) +} diff --git a/src/components/dashboard/OptionsButton.tsx b/src/components/dashboard/OptionsButton.tsx new file mode 100644 index 00000000..6dba8324 --- /dev/null +++ b/src/components/dashboard/OptionsButton.tsx @@ -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> + savePage: (published: boolean) => any + propertiesWidget: React.ReactNode + isRendering: boolean + published: boolean +}> = ({ + visibility, + previewPage, + savePage, + isRendering, + renderPage, + published, + propertiesWidget, +}) => { + const { t } = useTranslation("dashboard") + + return ( + <> +
renderPage(!isRendering)} + > + {isRendering ? ( + + ) : ( + + )} +
+ + {({ open, close }) => { + return ( + <> + +
+ {open ? ( + + ) : ( + + )} +
+
+ + + +
+ + {({ active }) => ( + + )} + +
+
+ + {({ active }) => ( + + )} + + + {({ active }) => ( + + )} + + + {({ active }) => ( + + )} + +
+
+
+ + ) + }} +
+ + + {({ open, close }) => ( +
+ { + // setIsOpen(true) + // }} + > +
+ +
+
+ + +
+ {propertiesWidget} +
+
+
+
+ )} +
+ + ) +} diff --git a/src/components/dashboard/PagesManager.tsx b/src/components/dashboard/PagesManager.tsx index 3dd6ab76..f7302543 100644 --- a/src/components/dashboard/PagesManager.tsx +++ b/src/components/dashboard/PagesManager.tsx @@ -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!, diff --git a/src/components/ui/Editor.tsx b/src/components/ui/Editor.tsx index f617b0f0..b67a7236 100644 --- a/src/components/ui/Editor.tsx +++ b/src/components/ui/Editor.tsx @@ -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([]) + 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( () => ( = ({ return (
{items.map((item) => { if (item.hidden) return null diff --git a/src/hooks/useMobileLayout.ts b/src/hooks/useMobileLayout.ts new file mode 100644 index 00000000..b0f19acd --- /dev/null +++ b/src/hooks/useMobileLayout.ts @@ -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 +} diff --git a/src/pages/dashboard/[subdomain]/editor.tsx b/src/pages/dashboard/[subdomain]/editor.tsx index 9bd31ede..5a07be1f 100644 --- a/src/pages/dashboard/[subdomain]/editor.tsx +++ b/src/pages/dashboard/[subdomain]/editor.tsx @@ -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 = ( +
+
+ ) => { + 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`, + )} + /> +
+
+ ) => + updateValue("slug", e.target.value) + } + help={ + <> + {(values.slug || defaultSlug) && ( + <> + {t(`This ${isPost ? "post" : "page"} will be accessible at`)}{" "} + + {getSiteLink({ + subdomain, + domain: site.data?.custom_domain, + noProtocol: true, + })} + /{encodeURIComponent(values.slug || defaultSlug)} + + + )} + + } + /> +
+
+ ) => + updateValue("tags", e.target.value) + } + help={t("Separate multiple tags with English commas") + ` ","`} + /> +
+
+ ) => { + updateValue("excerpt", e.target.value) + }} + help={t("Leave it blank to use auto-generated excerpt")} + /> +
+
+ ) + useEffect(() => { if (createOrUpdatePage.isSuccess) { if (createOrUpdatePage.data?.code === 0) { @@ -406,8 +501,18 @@ export default function SubdomainEditor() {
) : ( <> -
-
+
+
-
- - {t(visibility as string)} - - - -
+ {isMobileLayout ? ( +
+ {/* + {t(visibility as string)} + */} + {/* */} + {/* */} + { + window.open( + `/_site/${subdomain}/preview/${draftKey.replace( + `draft-${subdomain}-`, + "", + )}`, + ) + }} + /> +
+ ) : ( +
+ + {t(visibility as string)} + + + +
+ )}
-
+
@@ -474,129 +640,62 @@ export default function SubdomainEditor() { />
- { - setCurrentScrollArea("editor") - }} - /> - { - setCurrentScrollArea("preview") - }} - > + {isMobileLayout ? ( + !isRendering ? ( + { + setCurrentScrollArea("editor") + }} + /> + ) : ( + { + setCurrentScrollArea("preview") + }} + > + ) + ) : ( + <> + { + setCurrentScrollArea("editor") + }} + /> + { + setCurrentScrollArea("preview") + }} + > + + )}
-
-
- ) => { - 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`, - )} - /> -
-
- ) => - updateValue("slug", e.target.value) - } - help={ - <> - {(values.slug || defaultSlug) && ( - <> - {t( - `This ${ - isPost ? "post" : "page" - } will be accessible at`, - )}{" "} - - {getSiteLink({ - subdomain, - domain: site.data?.custom_domain, - noProtocol: true, - })} - /{encodeURIComponent(values.slug || defaultSlug)} - - - )} - - } - /> -
-
- ) => - updateValue("tags", e.target.value) - } - help={ - t("Separate multiple tags with English commas") + ` ","` - } - /> -
-
- ) => { - updateValue("excerpt", e.target.value) - }} - help={t("Leave it blank to use auto-generated excerpt")} - /> -
-
+ {!isMobileLayout && ExtraProperties}
)} diff --git a/tailwind.config.js b/tailwind.config.js index cc5e112d..f29ade6a 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -60,5 +60,5 @@ module.exports = { }, }, variants: {}, - plugins: [require("tailwindcss-animate")], + plugins: [require("tailwindcss-animate"), require("tailwind-scrollbar-hide")], }