Open source CapCut alternative.
TypeScript
feat(site): lucide icons in the blog editor toolbar, New post on the list only
David Lecc2a4d3d6aa7
diff --git a/site/src/app/su/blog/NewPostButton.tsx b/site/src/app/su/blog/NewPostButton.tsxindex 2cbf2c70..4afaa4a2 100644--- a/site/src/app/su/blog/NewPostButton.tsx+++ b/site/src/app/su/blog/NewPostButton.tsx@@ -1,15 +1,18 @@"use client";-import { useRouter } from "next/navigation";+import { usePathname, useRouter } from "next/navigation";import { Button } from "@/components/ui/button";import { useCreateBlogPost } from "@/queries/blog";// Makes a draft and opens it. The draft exists before a word is typed so the-// editor has a post id to upload images under.+// editor has a post id to upload images under. The button belongs to the+// list; an open post carries its own actions.export function NewPostButton() {+ const pathname = usePathname();const router = useRouter();const create = useCreateBlogPost();+ if (pathname !== "/blog") return null;return (<div className="flex items-center gap-3">{create.isError ? <span className="text-sm text-destructive">Couldn’t create the post.</span> : null}diff --git a/site/src/app/su/blog/[id]/BlogEditorInner.tsx b/site/src/app/su/blog/[id]/BlogEditorInner.tsxindex 0e27a2f3..c89d5588 100644--- a/site/src/app/su/blog/[id]/BlogEditorInner.tsx+++ b/site/src/app/su/blog/[id]/BlogEditorInner.tsx@@ -49,6 +49,7 @@ import { useEffect, useMemo, useState } from "react";import { BlogVideo } from "@/app/cut/blog/_components/BlogVideo";import { BLOG_ARTICLE_CLASS } from "@/app/cut/blog/_components/mdxComponents";import type { BlogEditorProps } from "@/app/su/blog/[id]/BlogEditor";+import { EDITOR_ICON_CLASS, editorIcon } from "@/app/su/blog/[id]/editorIcons";import { parseVideoUrl } from "@/lib/blog/video";// The article editor. The body is MDX: markdown with three named blocks the@@ -182,7 +183,7 @@ function InsertVideo() {tooltipTitle="Insert video"submitButtonTitle="Insert"dialogInputPlaceholder="YouTube, Vimeo or .mp4 address"- buttonContent={<Video className="size-5" />}+ buttonContent={<Video className={EDITOR_ICON_CLASS} />}onSubmit={(value) => {const src = value.trim();if (src) insertJsx({ name: "Video", kind: "flow", props: { src } });@@ -199,13 +200,13 @@ function InsertCtas() {title="Insert call to action banner"onClick={() => insertJsx({ name: "BlogCTA", kind: "flow", props: { variant: "banner" } })}>- <Megaphone className="size-5" />+ <Megaphone className={EDITOR_ICON_CLASS} /></ButtonWithTooltip><ButtonWithTooltiptitle="Insert inline call to action"onClick={() => insertJsx({ name: "InlineCTA", kind: "flow", props: {} })}>- <MessageSquareQuote className="size-5" />+ <MessageSquareQuote className={EDITOR_ICON_CLASS} /></ButtonWithTooltip></>);@@ -274,6 +275,7 @@ export default function BlogEditorInner({ markdown, diffMarkdown, onChange, uploif (!initialNormalize) onChange(next);}}onError={({ error }) => setParseError(error)}+ iconComponentFor={editorIcon}plugins={plugins}contentEditableClassName={`${BLOG_ARTICLE_CLASS} min-h-[60vh] px-6 py-5`}placeholder="Write the article…"diff --git a/site/src/app/su/blog/[id]/editorIcons.tsx b/site/src/app/su/blog/[id]/editorIcons.tsxnew file mode 100644index 00000000..041d4c78--- /dev/null+++ b/site/src/app/su/blog/[id]/editorIcons.tsx@@ -0,0 +1,103 @@+import type { IconKey } from "@mdxeditor/editor";+import {+ ArrowDownToLine,+ ArrowLeftToLine,+ ArrowRightToLine,+ ArrowUpToLine,+ Bold,+ Check,+ ChevronDown,+ Code,+ Columns3,+ Copy,+ Ellipsis,+ EllipsisVertical,+ ExternalLink,+ FileCode,+ FileText,+ GitCompare,+ Highlighter,+ ImagePlus,+ Info,+ Italic,+ Link2,+ List,+ ListChecks,+ ListOrdered,+ Minus,+ PenLine,+ Pencil,+ Redo2,+ Rows3,+ Settings2,+ SquareCode,+ Strikethrough,+ Subscript,+ Superscript,+ Table,+ TextAlignCenter,+ TextAlignEnd,+ TextAlignStart,+ Trash,+ Trash2,+ Underline,+ Undo2,+ Unlink,+ X,+ type LucideIcon,+} from "lucide-react";++// The editor's toolbar and popups draw the app's icon set.+const ICONS: Record<IconKey, LucideIcon> = {+ undo: Undo2,+ redo: Redo2,+ format_bold: Bold,+ format_italic: Italic,+ format_underlined: Underline,+ code: Code,+ strikeThrough: Strikethrough,+ superscript: Superscript,+ subscript: Subscript,+ format_list_bulleted: List,+ format_list_numbered: ListOrdered,+ format_list_checked: ListChecks,+ format_highlight: Highlighter,+ link: Link2,+ add_photo: ImagePlus,+ table: Table,+ horizontal_rule: Minus,+ frontmatter: FileText,+ frame_source: SquareCode,+ arrow_drop_down: ChevronDown,+ admonition: Info,+ rich_text: PenLine,+ difference: GitCompare,+ markdown: FileCode,+ open_in_new: ExternalLink,+ link_off: Unlink,+ edit: Pencil,+ content_copy: Copy,+ more_horiz: Ellipsis,+ more_vert: EllipsisVertical,+ close: X,+ settings: Settings2,+ delete_big: Trash2,+ delete_small: Trash,+ format_align_center: TextAlignCenter,+ format_align_left: TextAlignStart,+ format_align_right: TextAlignEnd,+ add_row: Rows3,+ add_column: Columns3,+ insert_col_left: ArrowLeftToLine,+ insert_row_above: ArrowUpToLine,+ insert_row_below: ArrowDownToLine,+ insert_col_right: ArrowRightToLine,+ check: Check,+};++export const EDITOR_ICON_CLASS = "size-4";++export function editorIcon(name: IconKey) {+ const Icon = ICONS[name];+ return <Icon className={EDITOR_ICON_CLASS} />;+}