From 559a66e560c96f27a420033ce2f7743c718a9560 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Tue, 27 Sep 2022 20:22:30 +0100 Subject: [PATCH 01/11] fix: svg turn black --- next.config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/next.config.js b/next.config.js index b1404c3b..8d4b8c40 100644 --- a/next.config.js +++ b/next.config.js @@ -47,7 +47,8 @@ module.exports = withBundleAnalyzer( images: { dangerouslyAllowSVG: true, - contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;", + contentSecurityPolicy: + "default-src 'self'; script-src 'none'; sandbox; style-src 'unsafe-inline';", remotePatterns: [{ hostname: "**" }], }, }), From 914a8431707ddfef2b1a12491174ac7a00ec4feb Mon Sep 17 00:00:00 2001 From: DIYgod Date: Tue, 27 Sep 2022 20:31:45 +0100 Subject: [PATCH 02/11] feat: remove preview button --- src/components/ui/EditorToolbar.tsx | 31 ++++------------------ src/editor/Preview.tsx | 10 ------- src/editor/index.tsx | 3 --- src/pages/dashboard/[subdomain]/editor.tsx | 12 ++------- 4 files changed, 7 insertions(+), 49 deletions(-) delete mode 100644 src/editor/Preview.tsx diff --git a/src/components/ui/EditorToolbar.tsx b/src/components/ui/EditorToolbar.tsx index d15bb454..877238b7 100644 --- a/src/components/ui/EditorToolbar.tsx +++ b/src/components/ui/EditorToolbar.tsx @@ -7,9 +7,6 @@ import { Tooltip } from "./Tooltip" export interface EditorToolbarProps { view: EditorView | null toolbars: ICommand[] - modeToolbars: ICommand[] - previewVisible: boolean - setPreviewVisible: Dispatch> } enum ToolbarMode { @@ -17,36 +14,21 @@ enum ToolbarMode { Preview, } -export const EditorToolbar: FC = ({ - view, - toolbars, - modeToolbars, - previewVisible, - setPreviewVisible, -}) => { +export const EditorToolbar: FC = ({ view, toolbars }) => { const renderToolbar = (mode: ToolbarMode) => // eslint-disable-next-line react/display-name ({ name, icon, label, execute }: ICommand) => { - const isPreviewModeCommand = mode === ToolbarMode.Preview - const active = isPreviewModeCommand && previewVisible - const disabled = !isPreviewModeCommand && previewVisible return ( - + +
From b02a4cd55373337bb7f87dcccd5547ddee5a5315 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Thu, 29 Sep 2022 21:51:56 +0100 Subject: [PATCH 05/11] fix: image warning --- src/components/site/SiteHome.tsx | 2 -- src/components/ui/Image.tsx | 5 +---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/components/site/SiteHome.tsx b/src/components/site/SiteHome.tsx index dab6c7d7..0352faf7 100644 --- a/src/components/site/SiteHome.tsx +++ b/src/components/site/SiteHome.tsx @@ -63,8 +63,6 @@ export const SiteHome: React.FC<{ className="object-cover rounded w-24 h-24" alt="cover" layout="fill" - width={96} - height={96} src={post.cover} >
diff --git a/src/components/ui/Image.tsx b/src/components/ui/Image.tsx index 7eb36cdc..7ae09115 100644 --- a/src/components/ui/Image.tsx +++ b/src/components/ui/Image.tsx @@ -29,10 +29,7 @@ export const Image: React.FC< } > Date: Thu, 29 Sep 2022 21:52:42 +0100 Subject: [PATCH 06/11] feat: support mark any crossbell notes as xlog notes --- src/components/dashboard/PagesManager.tsx | 179 ++++++++++++--------- src/lib/types.ts | 1 + src/models/page.model.ts | 30 ++-- src/pages/dashboard/[subdomain]/editor.tsx | 1 + 4 files changed, 129 insertions(+), 82 deletions(-) diff --git a/src/components/dashboard/PagesManager.tsx b/src/components/dashboard/PagesManager.tsx index 84d00c42..2f3b0e0b 100644 --- a/src/components/dashboard/PagesManager.tsx +++ b/src/components/dashboard/PagesManager.tsx @@ -24,6 +24,7 @@ import { UniLink } from "../ui/UniLink" import { nanoid } from "nanoid" import { renderPageContent } from "~/markdown" import { Tooltip } from "../ui/Tooltip" +import { APP_NAME } from "~/lib/env" export const PagesManager: React.FC<{ isPost: boolean @@ -57,8 +58,12 @@ export const PagesManager: React.FC<{ toast.success("Converted!", { id: convertToastId, }) + } else if (createOrUpdatePage.isError) { + toast.error("Failed to convert.", { + id: convertToastId, + }) } - }, [createOrUpdatePage.isSuccess, convertToastId]) + }, [createOrUpdatePage.isSuccess, createOrUpdatePage.isError, convertToastId]) const pages = useGetPagesBySite({ type: isPost ? "post" : "page", @@ -85,6 +90,10 @@ export const PagesManager: React.FC<{ value: PageVisibilityEnum.Scheduled, text: "Scheduled", }, + { + value: PageVisibilityEnum.Crossbell, + text: "Others on Crossbell", + }, ].map((item) => ({ text: item.text, onClick: () => { @@ -111,6 +120,7 @@ export const PagesManager: React.FC<{ const queryClient = useQueryClient() const getPageMenuItems = (page: Note) => { + const isCrossbell = !page.applications?.includes("xlog") return [ { text: "Edit", @@ -133,21 +143,18 @@ export const PagesManager: React.FC<{ }, }, { - text: "Convert to " + (isPost ? "Page" : "Post"), + text: + "Convert to " + + (isCrossbell + ? `${APP_NAME} ${isPost ? "Post" : "Page"}` + : isPost + ? "Page" + : "Post"), icon: , onClick() { - if (!page.metadata) { - const toastId = toast.loading("Converting...") - 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]) - toast.success("Converted!", { - id: toastId, - }) - } else { - setConvertToastId(toast.loading("Converting...")) + const toastId = toast.loading("Converting...") + if (isCrossbell) { + setConvertToastId(toastId) createOrUpdatePage.mutate({ published: true, pageId: page.id, @@ -155,8 +162,32 @@ export const PagesManager: React.FC<{ tags: page.tags ?.filter((tag) => tag !== "post" && tag !== "page") ?.join(", "), - isPost: !isPost, + isPost: isPost, + applications: page.applications, }) + } else { + 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]) + toast.success("Converted!", { + id: toastId, + }) + } else { + setConvertToastId(toastId) + createOrUpdatePage.mutate({ + published: true, + pageId: page.id, + siteId: subdomain, + tags: page.tags + ?.filter((tag) => tag !== "post" && tag !== "page") + ?.join(", "), + isPost: !isPost, + applications: page.applications, + }) + } } }, }, @@ -199,6 +230,55 @@ export const PagesManager: React.FC<{ ] } + const importFile = () => { + const input = document.createElement("input") + input.type = "file" + input.accept = ".md" + input.addEventListener("change", async (e: any) => { + const file = e.target?.files?.[0] + const reader = new FileReader() + reader.readAsText(file, "UTF-8") + reader.onload = (evt) => { + if (evt.target?.result) { + const pageContent = renderPageContent(evt.target.result as string) + + const id = nanoid() + const key = `draft-${subdomain}-local-${id}` + const tags = + pageContent.frontMatter.tags || pageContent.frontMatter.categories + setStorage(key, { + date: +new Date(), + values: { + content: evt.target.result, + published: false, + publishedAt: ( + pageContent.frontMatter.date || + file.lastModifiedDate || + new Date() + ).toISOString(), + slug: + pageContent.frontMatter.permalink || + file.name.split(".").slice(0, -1).join("."), + tags: tags?.join?.(", ") || tags, + title: pageContent.frontMatter.title, + }, + isPost: isPost, + }) + queryClient.invalidateQueries(["getPagesBySite", subdomain]) + router.push( + `/dashboard/${subdomain}/editor?id=local-${id}&type=${ + isPost ? "post" : "page" + }`, + ) + } + } + reader.onerror = (evt) => { + toast.error("Error reading file") + } + }) + input.click() + } + const title = isPost ? "Posts" : "Pages" const description = isPost ? ( <> @@ -276,60 +356,7 @@ export const PagesManager: React.FC<{ >