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

Implement clearing of drawables with mouse #321

Merged
merged 5 commits into from
Jun 29, 2024

Conversation

zackschuster
Copy link
Contributor

Removing drawables one-by-one is tedious. This affords an easy way to clear them by:

  1. Implementing a "Clear Drawings" button on the Board component
  2. Implementing a setting to clear the board on left-click, replicating e.g. Chess.com behavior

If the setting is enabled, the "Clear Drawings" button will not be rendered.

Translations for the setting were done with Google Translate.

Comment on lines -19 to +31
if (ref?.current && !api) {
if (ref?.current == null) return;
if (api) {
api?.set({
...props,
events: {
change: () => {
if (props.setBoardFen && api) {
props.setBoardFen(api.getFen());
}
},
},
});
} else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixing a nit

}

return state;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i assume this function is always supposed to return state, but this branch previously returned nothing.

Choose a reason for hiding this comment

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

The reducer can either return a new state, or simply mutate it when it's inside produce from immer. Since the state is a tree, it can be annoying to ensure immutability, so a lot of these functions are inside produce which doesn't require a return.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

shall i change it back, or is a monomorphic return type acceptable here?

<ActionIcon
variant={editingMode ? "filled" : "default"}
size="lg"
onClick={() => setShapes([])}

Choose a reason for hiding this comment

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

Instead of setShapes, there's already a clearShapes function in store.ts which also sets the dirty flag.

@franciscoBSalgueiro
Copy link
Owner

thanks!

@franciscoBSalgueiro franciscoBSalgueiro changed the title Implement fast clearing of drawables Implement clearing of drawables with mouse Jun 29, 2024
@franciscoBSalgueiro franciscoBSalgueiro merged commit 2bba1c7 into franciscoBSalgueiro:master Jun 29, 2024
2 checks passed
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.

2 participants