From b94cb78d64c48e0ec4296ccc43e0feb901dfc8aa Mon Sep 17 00:00:00 2001
From: Kalle <38327916+Sendouc@users.noreply.github.com>
Date: Mon, 9 Oct 2023 22:35:33 +0300
Subject: [PATCH] Handle note validation clientside
---
app/features/sendouq/components/GroupCard.tsx | 43 +++++++++++++------
1 file changed, 30 insertions(+), 13 deletions(-)
diff --git a/app/features/sendouq/components/GroupCard.tsx b/app/features/sendouq/components/GroupCard.tsx
index d5e9a09f1..1776a4f51 100644
--- a/app/features/sendouq/components/GroupCard.tsx
+++ b/app/features/sendouq/components/GroupCard.tsx
@@ -15,7 +15,7 @@ import { useTranslation } from "~/hooks/useTranslation";
import { useUser } from "~/modules/auth";
import { languagesUnified } from "~/modules/i18n/config";
import { SENDOUQ_LOOKING_PAGE, navIconUrl, userPage } from "~/utils/urls";
-import { FULL_GROUP_SIZE } from "../q-constants";
+import { FULL_GROUP_SIZE, SENDOUQ } from "../q-constants";
import type { LookingGroup } from "../q-types";
import { StarIcon } from "~/components/icons/Star";
import { StarFilledIcon } from "~/components/icons/StarFilled";
@@ -226,16 +226,27 @@ function MemberNote({
}) {
const fetcher = useFetcher();
const [editing, setEditing] = React.useState(false);
+ const [value, setValue] = React.useState(note ?? "");
- React.useEffect(() => {
+ const startEditing = () => setEditing(true);
+ const stopEditing = React.useCallback(() => {
setEditing(false);
+ setValue(note ?? "");
}, [note]);
+ // when note updates exit editing mode
+ React.useEffect(() => {
+ stopEditing();
+ }, [stopEditing]);
+
+ const newValueLegal = value.length <= SENDOUQ.NOTE_MAX_LENGTH;
+
if (editing) {
return (
);
@@ -268,7 +285,7 @@ function MemberNote({