mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix: allow edit modal saves after delete toggles
This commit is contained in:
@@ -284,11 +284,9 @@ describe('EditMenu', () => {
|
||||
|
||||
const saveButton = Array.from(container.querySelectorAll('button')).find((candidate) => candidate.textContent === 'save');
|
||||
expect(saveButton).not.toBeNull();
|
||||
expect((saveButton as HTMLButtonElement).disabled).toBe(true);
|
||||
|
||||
await click(getCheckbox('deleted'));
|
||||
expect((saveButton as HTMLButtonElement).disabled).toBe(false);
|
||||
|
||||
await click(getCheckbox('deleted'));
|
||||
await clickButton('save');
|
||||
|
||||
expect(testState.publishAuthorEditMock).toHaveBeenCalledOnce();
|
||||
@@ -304,6 +302,35 @@ describe('EditMenu', () => {
|
||||
expect(testState.authorOptions).not.toHaveProperty('signer');
|
||||
});
|
||||
|
||||
it('lets pseudonymous delete-only users undo an existing deletion', async () => {
|
||||
testState.pseudonymityMode = 'per-post';
|
||||
testState.privileges = {
|
||||
isAccountCommentAuthor: false,
|
||||
isAccountMod: false,
|
||||
isCommentAuthorMod: false,
|
||||
};
|
||||
|
||||
await renderMenu({
|
||||
...basePost,
|
||||
deleted: true,
|
||||
});
|
||||
await openMenu();
|
||||
|
||||
const deletedCheckbox = getCheckbox('deleted');
|
||||
expect(deletedCheckbox?.checked).toBe(true);
|
||||
|
||||
await click(deletedCheckbox);
|
||||
await clickButton('save');
|
||||
|
||||
expect(testState.publishAuthorEditMock).toHaveBeenCalledOnce();
|
||||
expect(testState.publishCommentModerationMock).not.toHaveBeenCalled();
|
||||
expect(testState.authorOptions).toMatchObject({
|
||||
commentCid: 'comment-1',
|
||||
communityAddress: 'music-posting.eth',
|
||||
deleted: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("does not allow delete-only access when pseudonymity mode is 'none'", async () => {
|
||||
testState.pseudonymityMode = 'none';
|
||||
testState.privileges = {
|
||||
|
||||
@@ -55,7 +55,6 @@ const EditMenu = ({ post }: { post: Comment }) => {
|
||||
const allowsPseudonymousDelete = pseudonymityMode !== undefined && pseudonymityMode !== 'none';
|
||||
const canAttemptAuthorDelete = isAccountCommentAuthor || allowsPseudonymousDelete;
|
||||
const canOpenEditMenu = isAccountMod || canAttemptAuthorDelete;
|
||||
const requiresDeleteSelection = canAttemptAuthorDelete && !isAccountCommentAuthor && !isAccountMod;
|
||||
const signer = isAccountCommentAuthor ? account?.signer : undefined;
|
||||
const latestPostRef = useRef(resolvedPost);
|
||||
useEffect(() => {
|
||||
@@ -259,14 +258,10 @@ const EditMenu = ({ post }: { post: Comment }) => {
|
||||
const { getReferenceProps, getFloatingProps } = useInteractions([click, dismiss, role]);
|
||||
|
||||
const headingId = useId();
|
||||
const canSave = !requiresDeleteSelection || publishCommentEditOptions.deleted === true;
|
||||
const hasDeleteStateChanged = (deleted ?? false) !== (publishCommentEditOptions.deleted ?? false);
|
||||
|
||||
const _publishCommentEdit = async () => {
|
||||
if (!canSave) {
|
||||
return;
|
||||
}
|
||||
|
||||
const shouldPublishAuthorEdit = isAccountCommentAuthor || (canAttemptAuthorDelete && publishCommentEditOptions.deleted === true);
|
||||
const shouldPublishAuthorEdit = isAccountCommentAuthor || (canAttemptAuthorDelete && hasDeleteStateChanged);
|
||||
|
||||
try {
|
||||
if (shouldPublishAuthorEdit && isAccountMod) {
|
||||
@@ -433,7 +428,7 @@ const EditMenu = ({ post }: { post: Comment }) => {
|
||||
</>
|
||||
)}
|
||||
<div className={styles.bottom}>
|
||||
<button className={isMobile ? 'button' : ''} onClick={_publishCommentEdit} disabled={!canSave}>
|
||||
<button className={isMobile ? 'button' : ''} onClick={_publishCommentEdit}>
|
||||
{t('save')}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user