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

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

Closed
2 tasks
ChrisGergler opened this issue Jun 15, 2022 · 5 comments · Fixed by #699
Closed
2 tasks

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

ChrisGergler opened this issue Jun 15, 2022 · 5 comments · Fixed by #699
Labels
bug Something isn't working

Comments

@ChrisGergler
Copy link

What happened?

Issue

Where
https://app.revolt.chat/server//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

a190a51

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 ChrisGergler added the bug Something isn't working label Jun 15, 2022
@ChrisGergler
Copy link
Author

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

@LedaThemis
Copy link
Contributor

I believe the issue is in line 375

{editing ? (
<input
value={editing}
onChange={(e) =>
setEditing(
e.currentTarget.value,
)
}
onKeyDown={(e) =>
e.key === "Enter" && save()
}
id={category.id}
/>
) : (
<span onClick={startEditing}>
{category.title}
</span>
)}

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
Copy link
Contributor

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
Copy link
Contributor

Replacing the current save() function

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

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:

if (!editing) return;

which should be changed to

if (editing === undefined) return;

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

@insertish
Copy link
Member

Closing due to rewrite, marking as potential issue in future by linking to revoltchat/frontend#134.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants