revite icon indicating copy to clipboard operation
revite copied to clipboard

bug: Server/Settings/Categories - Empty Category Title exits text input

Open ChrisGergler opened this issue 3 years ago • 4 comments

What happened?

Issue

Where https://app.revolt.chat/server/<ServerID>/settings/categories

When on Firefox and Edge, Adding Categories text input cancels with an empty string during category creation.

How to recreate Click the + for a new Category Erase all text from input State changes out of editing

--- Version a190a51 (master)Nightly 0.5.3-7API: 0.5.3-7revolt.js: 6.0.2

Branch

Production (app.revolt.chat)

Commit hash

a190a51d0b597370e66de96f7c94592debb7705c

What browsers are you seeing the problem on?

Firefox, Microsoft Edge

Relevant log output

No response

Desktop

  • [ ] Yes, this bug is specific to Revolt Desktop and is not an issue with Revolt Desktop itself.

PWA

  • [ ] Yes, this bug is specific to the PWA.

ChrisGergler avatar Jun 15 '22 16:06 ChrisGergler

I believe that this is happening under the /src/pages/settings/server/Categories.tsx

At line 334 setTitle?: (title: string) => void; Does not permit a nullable string at any point. My guess is that once the edited value reaches empty, it exits the function for editing without saving and returns to the previous state.

If this is the case, then it should be possible to prevent the state from changing to saved if null, but allow it if !null

ChrisGergler avatar Jun 15 '22 16:06 ChrisGergler

I believe the issue is in line 375 https://github.com/revoltchat/revite/blob/a190a51d0b597370e66de96f7c94592debb7705c/src/pages/settings/server/Categories.tsx#L375-L392 where the input element goes back to a span if editing (which holds the current category title) is falsy, and an empty string is falsy

LedaThemis avatar Jun 15 '22 16:06 LedaThemis

Changing line 375 from editing ? to editing !== undefined ? solves the issue, but it makes it possible to submit an empty string as a category name which is invalid.

LedaThemis avatar Jun 15 '22 17:06 LedaThemis

Replacing the current save() function https://github.com/revoltchat/revite/blob/a190a51d0b597370e66de96f7c94592debb7705c/src/pages/settings/server/Categories.tsx#L345-L348 with the following:

const save = useCallback(() => {
    setEditing(undefined);
    if (editing !== "") {
        setTitle!(editing!);
    }
}, [editing, setTitle]);

solves the empty string submission issue.

an alternative would be:

const save = useCallback(() => {
    setEditing(undefined);
    if (editing) {
        setTitle!(editing);
    }
}, [editing, setTitle]);

but I believe the first one is clearer.


Another bug is that entering any category name then switching to edit another category name does save() the name, except if the name is empty, then the UI keeps the category name as empty but it never submits it, and that's because of the following: https://github.com/revoltchat/revite/blob/a190a51d0b597370e66de96f7c94592debb7705c/src/pages/settings/server/Categories.tsx#L351 which should be changed to

if (editing === undefined) return;

Preview: image previewing an empty category name while editing another category name

LedaThemis avatar Jun 15 '22 17:06 LedaThemis

Closing due to rewrite, marking as potential issue in future by linking to https://github.com/revoltchat/frontend/issues/134.

insertish avatar Jan 24 '23 17:01 insertish