From bba03d0eab34e29ec4f9fdb2d6dca4f82ddc1225 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Thu, 9 May 2019 13:03:39 -0400 Subject: [PATCH] Show when response was sent (Closes #1488) --- .../dropdowns/response-history-dropdown.js | 7 ++++--- .../app/ui/components/time-from-now.js | 21 +++++++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/insomnia-app/app/ui/components/dropdowns/response-history-dropdown.js b/packages/insomnia-app/app/ui/components/dropdowns/response-history-dropdown.js index 44d7319325..e6422d8b8b 100644 --- a/packages/insomnia-app/app/ui/components/dropdowns/response-history-dropdown.js +++ b/packages/insomnia-app/app/ui/components/dropdowns/response-history-dropdown.js @@ -10,6 +10,7 @@ import TimeTag from '../tags/time-tag'; import SizeTag from '../tags/size-tag'; import { executeHotKey } from '../../../common/hotkeys-listener'; import { hotKeyRefs } from '../../../common/hotkeys'; +import TimeFromNow from '../time-from-now'; @autobind class ResponseHistoryDropdown extends PureComponent { @@ -86,12 +87,12 @@ class ResponseHistoryDropdown extends PureComponent { key={activeResponse ? activeResponse._id : 'n/a'} {...extraProps}> + {activeResponse && } {!isLatestResponseActive ? ( - + ) : ( - + )} - Response History diff --git a/packages/insomnia-app/app/ui/components/time-from-now.js b/packages/insomnia-app/app/ui/components/time-from-now.js index d08cc75da7..7f9007a3d8 100644 --- a/packages/insomnia-app/app/ui/components/time-from-now.js +++ b/packages/insomnia-app/app/ui/components/time-from-now.js @@ -7,6 +7,7 @@ type Props = { timestamp: number | Date | string, intervalSeconds?: number, className?: string, + capitalize?: boolean, }; type State = { @@ -26,8 +27,23 @@ class TimeFromNow extends React.PureComponent { } _update() { - const { timestamp } = this.props; - this.setState({ text: moment(timestamp).fromNow() }); + const { timestamp, capitalize } = this.props; + + let text = moment(timestamp).fromNow(); + + // Shorten default case + if (text === 'a few seconds ago') { + text = 'just now'; + } + + // Capitalize if needed + if (capitalize) { + text = text.replace(/\w\S*/g, function(txt) { + return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); + }); + } + + this.setState({ text }); } componentDidMount() { @@ -43,6 +59,7 @@ class TimeFromNow extends React.PureComponent { render() { const { className, timestamp } = this.props; const { text } = this.state; + return ( {text}