From 71a78c5dba5993a344597136ef0f032649ab7613 Mon Sep 17 00:00:00 2001 From: Pouria Delfanazari Date: Tue, 12 Dec 2023 22:07:47 -0800 Subject: [PATCH 1/2] Fix issue where newlines aren't added to char count --- src/components/inputs/editor/BottomEditorBar.tsx | 10 +++++++--- src/components/inputs/editor/Editor.tsx | 4 ++-- src/lib/hooks/bsky/feed/usePublishPost.tsx | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/components/inputs/editor/BottomEditorBar.tsx b/src/components/inputs/editor/BottomEditorBar.tsx index 8a503824..e05a4f47 100644 --- a/src/components/inputs/editor/BottomEditorBar.tsx +++ b/src/components/inputs/editor/BottomEditorBar.tsx @@ -1,5 +1,5 @@ import EmojiPicker from "./EmojiPicker"; -import type { Editor } from "@tiptap/react"; +import type { Editor, JSONContent } from "@tiptap/react"; import AdultContentPicker from "./AdultContentPicker"; import ImagePicker from "./ImagePicker"; import CharacterCount from "./CharacterCount"; @@ -8,10 +8,12 @@ import { useState } from "react"; import { useDropzone } from "react-dropzone"; import { Icon } from "@iconify/react/dist/iconify.js"; import UploadPreview from "./UploadPreview"; +import { RichText } from "@atproto/api"; +import { jsonToText } from "@/lib/utils/text"; interface Props { editor: Editor; - charCount: number; + text: JSONContent; label: string; languages: Language[]; images?: UploadImage[]; @@ -25,7 +27,7 @@ interface Props { export default function BottomEditorBar(props: Props) { const { editor, - charCount, + text, label, languages, images, @@ -35,6 +37,8 @@ export default function BottomEditorBar(props: Props) { } = props; const [showDropzone, setShowDropzone] = useState(false); + const richText = new RichText({ text: jsonToText(text) }); + const charCount = richText.graphemeLength; const { getRootProps, getInputProps, isDragActive, isDragReject } = useDropzone({ diff --git a/src/components/inputs/editor/Editor.tsx b/src/components/inputs/editor/Editor.tsx index 1bd3f360..58eaa240 100644 --- a/src/components/inputs/editor/Editor.tsx +++ b/src/components/inputs/editor/Editor.tsx @@ -60,7 +60,7 @@ export default function Editor(props: Props) { listItem: false, }), CharacterCount.configure({ - limit: 600, + limit: 600, }), Placeholder.configure({ placeholder: placeholderText, @@ -153,7 +153,7 @@ export default function Editor(props: Props) { editor={editor} label={label} onSelectLabel={setLabel} - charCount={editor?.storage.characterCount.characters()} + text={editor.getJSON()} languages={languages} onSelectLanguages={setLanguages} images={images} diff --git a/src/lib/hooks/bsky/feed/usePublishPost.tsx b/src/lib/hooks/bsky/feed/usePublishPost.tsx index 51dae154..54bc3823 100644 --- a/src/lib/hooks/bsky/feed/usePublishPost.tsx +++ b/src/lib/hooks/bsky/feed/usePublishPost.tsx @@ -37,7 +37,7 @@ export default function usePublishPost(props: Props) { return useMutation({ mutationKey: ["publishPost"], mutationFn: async () => { - const richText = new RichText({ text: jsonToText(text).trimEnd() }); + const richText = new RichText({ text: jsonToText(text)}); await richText.detectFacets(agent); if (richText.graphemeLength > MAX_POST_LENGTH) { From 62bfd1448f00d50523a69859e18aeda27c47fcec Mon Sep 17 00:00:00 2001 From: Pouria Delfanazari Date: Tue, 12 Dec 2023 22:19:49 -0800 Subject: [PATCH 2/2] Disable image optimization --- next.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/next.config.js b/next.config.js index 7d3afb7c..2d68dcb4 100644 --- a/next.config.js +++ b/next.config.js @@ -1,6 +1,7 @@ /** @type {import('next').NextConfig} */ const nextConfig = { images: { + unoptimized: true, remotePatterns: [ { protocol: "https",