-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
Reset rotation and position on double click #119
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
src/Preview.tsx
Outdated
const onDoubleClick: React.MouseEventHandler<HTMLBodyElement> = () => { | ||
if (visible) { | ||
setScale(1); | ||
setPosition(initialPosition); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const onDoubleClick: React.MouseEventHandler<HTMLBodyElement> = () => { | |
if (visible) { | |
setScale(1); | |
setPosition(initialPosition); | |
} | |
}; | |
const onDoubleClick: React.MouseEventHandler<HTMLBodyElement> = () => { | |
if (!visible) { | |
return; | |
} | |
setScale(1); | |
setPosition(initialPosition); | |
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@afc163 Thanks for the quick review! Fixed!
Is the |
Rebase master to fix snapshot. |
07aed26
to
c385470
Compare
Done! |
Codecov Report
@@ Coverage Diff @@
## master #119 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 5 5
Lines 271 277 +6
Branches 81 84 +3
=========================================
+ Hits 271 277 +6
📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more |
src/Preview.tsx
Outdated
@@ -248,6 +256,7 @@ const Preview: React.FC<PreviewProps> = props => { | |||
passive: false, | |||
}); | |||
const onKeyDownListener = addEventListener(window, 'keydown', onKeyDown, false); | |||
const onDoubleClickLister = addEventListener(window, 'dblclick', onDoubleClick, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useEffect return 内要卸载掉这些 addEventListener。
} | ||
setScale(1); | ||
setPosition(initialPosition); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加个 useCallBack,不然每次刷新都进下面的 useEffect 了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
完毕!
@@ -317,6 +325,7 @@ const Preview: React.FC<PreviewProps> = props => { | |||
> | |||
<img | |||
onMouseDown={onMouseDown} | |||
onDoubleClick={onDoubleClick} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@afc163 What do you think about the current implementation?
src/Preview.tsx
Outdated
if (!visible) { | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!visible) { | |
return; | |
if (visible) { | |
... | |
} |
Can we use the initial approach to keep the test coverage 100%?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, pushed a commit!
@afc163 Could you take another look? |
Interesting. The coverage check complained |
27306b9
to
8c0d923
Compare
rebased on master |
I was wrong. |
@afc163 Fixed tests! |
Co-authored-by: afc163 <afc163@gmail.com>
@afc163 Any clue on why tests failed? |
Reinstall lock files and node_modules and try again. |
I forgot to pull the latest commit. |
Signed-off-by: harupy <hkawamura0130@gmail.com>
What changes are proposed in this pull request?
Reset the image rotation and position on double click.
Where does this idea come from?
This idea comes from Plotly:
https://plotly.com/python/creating-and-updating-figures/
Quick demo:
reset-on-double-click.mov