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 undo/redo example with tldraw #695

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/react-tldraw/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"unique-names-generator": "^4.7.1",
"yorkie-js-sdk": "^0.4.7"
"yorkie-js-sdk": "^0.4.9"
},
"devDependencies": {
"@types/lodash": "^4.14.198",
Expand Down
21 changes: 18 additions & 3 deletions examples/react-tldraw/src/hooks/useMultiplayerState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ export function useMultiplayerState(roomId: string) {
false,
);

const onUndo = () => {
if (doc.history.canUndo()) {
doc.history.undo();
}
}

const onRedo = () => {
if (doc.history.canRedo()) {
doc.history.redo();
}
}

// Document Changes --------

useEffect(() => {
Expand Down Expand Up @@ -253,7 +265,8 @@ export function useMultiplayerState(roomId: string) {

// 04. Subscribe document event and handle changes.
doc.subscribe((event) => {
if (event.type === 'remote-change') {
const acceptTypeList = ['remote-change', 'local-change']
if (acceptTypeList.includes(event.type)) {
handleChanges();
}
});
Expand Down Expand Up @@ -292,7 +305,9 @@ export function useMultiplayerState(roomId: string) {
return {
onMount,
onChangePage,
loading,
onChangePresence,
onUndo,
onRedo,
loading,
};
}
}
Copy link
Member

Choose a reason for hiding this comment

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

As always, file newline here.

12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading