From 1b817fb9dc966ff0698021cf0ff0f63a52ab3661 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Tue, 1 Nov 2022 18:56:36 +0000 Subject: [PATCH] fix: repeated page modification --- src/pages/dashboard/[subdomain]/editor.tsx | 360 +++++++++++---------- 1 file changed, 190 insertions(+), 170 deletions(-) diff --git a/src/pages/dashboard/[subdomain]/editor.tsx b/src/pages/dashboard/[subdomain]/editor.tsx index 3771cba5..b426c92d 100644 --- a/src/pages/dashboard/[subdomain]/editor.tsx +++ b/src/pages/dashboard/[subdomain]/editor.tsx @@ -74,9 +74,15 @@ export default function SubdomainEditor() { render: false, }) - const [visibility, setVisibility] = useState( - page.data ? getPageVisibility(page.data) : PageVisibilityEnum.Draft, - ) + const [visibility, setVisibility] = useState() + + useEffect(() => { + if (page.isSuccess) { + setVisibility( + page.data ? getPageVisibility(page.data) : PageVisibilityEnum.Draft, + ) + } + }, [page.isSuccess]) const uploadFile = useUploadFile() @@ -340,178 +346,192 @@ export default function SubdomainEditor() { <> -
-
- - - Tip: xLog Flavored Markdown - + {page.isLoading ? ( +
+ Loading...
-
- - {visibility.toLowerCase()} - - - -
-
-
-
-
-
- { - if (e.key === "Enter") { - view?.focus() + ) : ( + <> +
+
+ + + Tip: xLog Flavored Markdown + +
+
+ + {visibility?.toLowerCase()} + + + +
+
+
+
+
+
+ { + if (e.key === "Enter") { + view?.focus() + } + }} + onChange={(e) => updateValue("title", e.target.value)} + className="h-12 ml-1 inline-flex items-center border-none text-3xl font-bold w-full focus:outline-none" + placeholder="Title goes here.." + /> +
+
+ { + setCurrentScrollArea("editor") + }} + /> + { + setCurrentScrollArea("preview") + }} + > +
+
+
+
+
+ ) => { + const value = inLocalTimezone( + e.target.value, + ).toISOString() + updateValue("publishedAt", value) + }} + help={`This ${ + isPost ? "post" : "page" + } will be accessible from this time`} + /> +
+
+ ) => + updateValue("slug", e.target.value) } - }} - onChange={(e) => updateValue("title", e.target.value)} - className="h-12 ml-1 inline-flex items-center border-none text-3xl font-bold w-full focus:outline-none" - placeholder="Title goes here.." - /> -
-
- { - setCurrentScrollArea("editor") - }} - /> - { - setCurrentScrollArea("preview") - }} - > -
-
-
-
-
- ) => { - const value = inLocalTimezone(e.target.value).toISOString() - updateValue("publishedAt", value) - }} - help={`This ${ - isPost ? "post" : "page" - } will be accessible from this time`} - /> -
-
- ) => - updateValue("slug", e.target.value) - } - help={ - <> - {(values.slug || defaultSlug) && ( + help={ <> - This {isPost ? "post" : "page"} will be accessible at{" "} - - {getSiteLink({ - subdomain, - domain: site.data?.custom_domain, - noProtocol: true, - })} - /{values.slug || defaultSlug} - + {(values.slug || defaultSlug) && ( + <> + This {isPost ? "post" : "page"} will be accessible + at{" "} + + {getSiteLink({ + subdomain, + domain: site.data?.custom_domain, + noProtocol: true, + })} + /{values.slug || defaultSlug} + + + )} - )} - - } - /> + } + /> +
+
+ ) => + updateValue("tags", e.target.value) + } + help='Separate multiple tags with English commas ","' + /> +
+
+ ) => { + updateValue("excerpt", e.target.value) + }} + help="Leave it blank to use auto-generated excerpt" + /> +
+
-
- ) => - updateValue("tags", e.target.value) - } - help='Separate multiple tags with English commas ","' - /> -
-
- ) => { - updateValue("excerpt", e.target.value) - }} - help="Leave it blank to use auto-generated excerpt" - /> -
-
-
+ + )}