From f7d277b68837cede7fd6bfd64a52a1b15bf6550a Mon Sep 17 00:00:00 2001 From: Nikolay Bonev Date: Tue, 3 Sep 2024 12:31:43 +0300 Subject: [PATCH 1/2] fixes: - fixing production:dev and staging:dev commands to work properly with the new react-router-hono-server package - removing markdown editor atom and replacing it with local state - reworking how state is handled in notes.new to better control the state with local react state --- .../assets/custom-fields-inputs.tsx | 3 +- app/components/assets/notes/new.tsx | 28 ++++++++++++------- app/components/markdown/markdown-editor.tsx | 13 ++------- package.json | 4 +-- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/app/components/assets/custom-fields-inputs.tsx b/app/components/assets/custom-fields-inputs.tsx index 389b80772..3b5ad0175 100644 --- a/app/components/assets/custom-fields-inputs.tsx +++ b/app/components/assets/custom-fields-inputs.tsx @@ -176,6 +176,7 @@ export default function AssetCustomFields({ const value = customFieldsValues?.find( (cfv) => cfv.customFieldId === field.id )?.value?.raw; + const error = zo.errors[`cf-${field.id}`]()?.message; return ( @@ -183,7 +184,7 @@ export default function AssetCustomFields({ (null); const wrapperRef = useRef(null); - const [, clearMarkdown] = useAtom(clearMarkdownAtom); const isDone = fetcher.state === "idle" && fetcher.data != null; + /** Controls whether actions are disabled */ + const [disabled, setDisabled] = useState(false); + + function handleSubmit() { + /** Disabled the input and buttons while form is submitting */ + setDisabled(true); + } + const handelBlur = ( e: ChangeEvent & FocusEvent ) => { @@ -65,15 +69,17 @@ export const NewNote = ({ [fetcher] ); + /** Focus the input when we are in edit mode */ useEffect(() => { if (isEditing) { editorRef?.current?.focus(); } }, [isEditing]); + /** When submitting is done, set isEditing to false to close the editor */ useEffect(() => { - clearMarkdown(); - }, [isDone, clearMarkdown]); + setIsEditing(false); + }, [isDone, setIsEditing]); return (
@@ -81,7 +87,7 @@ export const NewNote = ({ action={`/assets/${params.assetId}/note`} method="post" ref={zo.ref} - onSubmit={clearMarkdown} + onSubmit={handleSubmit} > {isEditing ? (
@@ -90,10 +96,11 @@ export const NewNote = ({ variant="secondary" size="sm" onClick={() => setIsEditing(false)} + disabled={disabled} > Cancel -
@@ -107,6 +114,7 @@ export const NewNote = ({ className="rounded-b-none" onBlur={handelBlur} onKeyDown={handleKeyDown} + disabled={disabled} />
) : ( diff --git a/app/components/markdown/markdown-editor.tsx b/app/components/markdown/markdown-editor.tsx index 0bffa0aff..06bc33303 100644 --- a/app/components/markdown/markdown-editor.tsx +++ b/app/components/markdown/markdown-editor.tsx @@ -1,7 +1,6 @@ -import { useEffect, forwardRef } from "react"; +import { useEffect, forwardRef, useState } from "react"; import type { TextareaHTMLAttributes, ChangeEvent } from "react"; import { Link, useFetcher } from "@remix-run/react"; -import { atom, useAtom } from "jotai"; import type { action } from "~/routes/api+/utils.parse-markdown"; import { tw } from "~/utils/tw"; import { MarkdownViewer } from "./markdown-viewer"; @@ -17,11 +16,6 @@ interface Props extends TextareaHTMLAttributes { className?: string; } -export const markdownAtom = atom(""); -export const clearMarkdownAtom = atom(null, (_get, set) => - set(markdownAtom, "") -); - export const MarkdownEditor = forwardRef(function MarkdownEditor( { label, @@ -37,7 +31,7 @@ export const MarkdownEditor = forwardRef(function MarkdownEditor( ) { const fetcher = useFetcher(); const content = fetcher.data?.error ? "" : fetcher.data?.content; - const [markdown, setMarkdown] = useAtom(markdownAtom); + const [markdown, setMarkdown] = useState(""); const handleChange = (e: ChangeEvent) => { const content = e.currentTarget.value; @@ -55,8 +49,7 @@ export const MarkdownEditor = forwardRef(function MarkdownEditor( useEffect(() => { setMarkdown(defaultValue); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [defaultValue]); return ( Date: Tue, 3 Sep 2024 12:37:52 +0300 Subject: [PATCH 2/2] fixing issue with 1px overflow on fake checkbox svg --- app/components/list/bulk-actions/bulk-list-item-checkbox.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/components/list/bulk-actions/bulk-list-item-checkbox.tsx b/app/components/list/bulk-actions/bulk-list-item-checkbox.tsx index 47afeb815..09d42819c 100644 --- a/app/components/list/bulk-actions/bulk-list-item-checkbox.tsx +++ b/app/components/list/bulk-actions/bulk-list-item-checkbox.tsx @@ -29,7 +29,10 @@ export default function BulkListItemCheckbox({ return (