Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imprv: Show unsaved warning when comment not posted #7603

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions apps/app/src/components/PageComment/CommentEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ import {
useCurrentUser, useIsSlackConfigured,
useIsUploadableFile, useIsUploadableImage,
} from '~/stores/context';
import { useSWRxSlackChannels, useIsSlackEnabled } from '~/stores/editor';
import { useSWRxSlackChannels, useIsSlackEnabled, useIsEnabledUnsavedWarning } from '~/stores/editor';
import { useCurrentPagePath } from '~/stores/page';

import { CustomNavTab } from '../CustomNavigation/CustomNav';
import { NotAvailableForGuest } from '../NotAvailableForGuest';
import Editor from '../PageEditor/Editor';


import { CommentPreview } from './CommentPreview';

import styles from './CommentEditor.module.scss';
Expand Down Expand Up @@ -70,6 +69,7 @@ export const CommentEditor = (props: CommentEditorProps): JSX.Element => {
const { data: isSlackConfigured } = useIsSlackConfigured();
const { data: isUploadableFile } = useIsUploadableFile();
const { data: isUploadableImage } = useIsUploadableImage();
const { mutate: mutateIsEnabledUnsavedWarning } = useIsEnabledUnsavedWarning();

const [isReadyToUse, setIsReadyToUse] = useState(!isForNewComment);
const [comment, setComment] = useState(commentBody ?? '');
Expand Down Expand Up @@ -237,7 +237,10 @@ export const CommentEditor = (props: CommentEditorProps): JSX.Element => {
);
}, []);

const onChangeHandler = useCallback((newValue: string) => setComment(newValue), []);
const onChangeHandler = useCallback((newValue: string, isClean: boolean) => {
setComment(newValue);
mutateIsEnabledUnsavedWarning(!isClean);
}, [mutateIsEnabledUnsavedWarning]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • post しても引き続き browser warning がでます。ご確認お願いします。
    comment post 後に渡る値を見てみると newValue は ですが, isClean は false でわたってくるようです。

  • Reply と Add Comment の CommentEditor が同時に呼ばれる場合があるのでどちらかに not posted な値があるときは browser warning を出すようにしてください。(両方に入力してから片方 post したら warning されない気がする。)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

対応しました。


const renderReady = () => {
const commentPreview = getCommentHtml();
Expand Down