Skip to content

functional refactor & fix: remove state.role #542

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

Merged
merged 1 commit into from
Sep 13, 2023

Conversation

lihebi
Copy link
Collaborator

@lihebi lihebi commented Sep 13, 2023

This is one of the efforts to make the component more "(purely) functional" by extracting states out. States are global variables that should be avoided when possible.

Removed states:

  • state.role. Also removed all isGuest checks (replaced by a more functional state.editMode below).
  • state.user. The user is only used in Awareness and is now passed as function parameter to connectYjs action.
  • state.repoLoaded

Added states:

  • state.editMode: "edit" | "view". This could be set on-demand for web-ui when loading user authentication module.

Bug fix:

  • In Code.tsx and Rich.tsx, the Wrap didn't use correct width/height when the role was in "Guest".

@lihebi lihebi merged commit 770a9b7 into codepod-io:main Sep 13, 2023
return (
<Box sx={paneMenuStyle(props.x, props.y)}>
<MenuList className="paneContextMenu">
{!isGuest && (
{editing && (
Copy link
Collaborator

@senwang86 senwang86 Sep 13, 2023

Choose a reason for hiding this comment

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

Is it better to control the parent by editing, rather than repeating the editing check on each MenuItem ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There could be some context menu items in "view" mode as well.

edge="end"
aria-label="delete"
onClick={() =>
deleteCollaborator({
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think non-owner user can delete other collaborators. I know it must give an error message from database update operation because of no auth. But in the front-end, we should still disable it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right; the current API-auth will throw errors.

I'm trying to remove user/auth-related code from the packages/ui so that it can be better re-used across desktop-app and web-app. Things will break. But I consider this as a non-critical break.

Actually, we likely need to add more refined permission control here, e.g., collaborators should be able to add/remove (the behavior of Google Docs).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants