From 110077e8e83727c6604607d6665dffadcc865304 Mon Sep 17 00:00:00 2001 From: picklesrus Date: Fri, 11 Dec 2020 08:14:15 -0500 Subject: [PATCH] Rename state's muteExpiresAt to muteExpiresAtMs so units are explicit. Also, fix isMuted so it doesn't do an extra unit conversion. --- src/views/preview/comment/compose-comment.jsx | 14 +++++++------- test/unit/components/compose-comment.test.jsx | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/views/preview/comment/compose-comment.jsx b/src/views/preview/comment/compose-comment.jsx index 099911da2..f322b874f 100644 --- a/src/views/preview/comment/compose-comment.jsx +++ b/src/views/preview/comment/compose-comment.jsx @@ -48,7 +48,7 @@ class ComposeComment extends React.Component { error: null, appealId: null, muteOpen: false, - muteExpiresAt: this.props.muteStatus.muteExpiresAt * 1000 // convert to ms + muteExpiresAtMs: this.props.muteStatus.muteExpiresAt * 1000 // convert to ms }; } handleInput (event) { @@ -78,10 +78,10 @@ class ComposeComment extends React.Component { } if (body.rejected && this.state.status === ComposeStatus.SUBMITTING) { let muteOpen = false; - let muteExpiresAt = 0; + let muteExpiresAtMs = 0; let rejectedStatus = ComposeStatus.REJECTED; if (body.status && body.status.mute_status) { - muteExpiresAt = body.status.mute_status.muteExpiresAt * 1000; // convert to ms + muteExpiresAtMs = body.status.mute_status.muteExpiresAt * 1000; // convert to ms rejectedStatus = ComposeStatus.REJECTED_MUTE; if (this.shouldShowMuteModal(body.status.mute_status.offenses)) { muteOpen = true; @@ -93,7 +93,7 @@ class ComposeComment extends React.Component { error: body.rejected, appealId: body.appealId, muteOpen: muteOpen, - muteExpiresAt: muteExpiresAt + muteExpiresAtMs: muteExpiresAtMs }); return; } @@ -118,7 +118,7 @@ class ComposeComment extends React.Component { } isMuted () { - return this.state.muteExpiresAt * 1000 > Date.now(); + return this.state.muteExpiresAtMs > Date.now(); } handleMuteClose () { @@ -174,7 +174,7 @@ class ComposeComment extends React.Component {

Scratch thinks your comment was disrespectful.

You will be able to comment - again {formatTime.formatRelativeTime(this.state.muteExpiresAt, window._locale)}. + again {formatTime.formatRelativeTime(this.state.muteExpiresAtMs, window._locale)}. Your account has been paused from commenting until then.

@@ -263,7 +263,7 @@ class ComposeComment extends React.Component { useStandardSizes className="mod-mute" shouldCloseOnOverlayClick={false} - timeMuted={formatTime.formatRelativeTime(this.state.muteExpiresAt, window._locale)} + timeMuted={formatTime.formatRelativeTime(this.state.muteExpiresAtMs, window._locale)} onRequestClose={this.handleMuteClose} /> ) : null} diff --git a/test/unit/components/compose-comment.test.jsx b/test/unit/components/compose-comment.test.jsx index f13d42168..163db76c4 100644 --- a/test/unit/components/compose-comment.test.jsx +++ b/test/unit/components/compose-comment.test.jsx @@ -81,7 +81,7 @@ describe('Compose Comment test', () => { global.Date.now = () => 0; const component = getComposeCommentWrapper({}); const commentInstance = component.instance(); - commentInstance.setState({muteExpiresAt: 100}); + commentInstance.setState({muteExpiresAtMs: 100}); component.update(); // Compose box should be hidden if muted unless they got muted due to a comment they just posted. expect(component.find('FlexRow.compose-comment').exists()).toEqual(false); @@ -96,7 +96,7 @@ describe('Compose Comment test', () => { const commentInstance = component.instance(); commentInstance.setState({ status: 'REJECTED_MUTE', - muteExpiresAt: 100 + muteExpiresAtMs: 100 }); component.update(); expect(component.find('FlexRow.compose-comment').exists()).toEqual(true); @@ -196,7 +196,7 @@ describe('Compose Comment test', () => { global.Date.now = () => 0; // Set "now" to 0 for easier testing. const commentInstance = getComposeCommentWrapper({}).instance(); - commentInstance.setState({muteExpiresAt: 100}); + commentInstance.setState({muteExpiresAtMs: 100}); expect(commentInstance.isMuted()).toBe(true); global.Date.now = realDateNow; }); @@ -206,7 +206,7 @@ describe('Compose Comment test', () => { global.Date.now = () => 0; const commentInstance = getComposeCommentWrapper({}).instance(); - commentInstance.setState({muteExpiresAt: -100}); + commentInstance.setState({muteExpiresAtMs: -100}); expect(commentInstance.isMuted()).toBe(false); global.Date.now = realDateNow; });