From 618f8a52f72850534ce2b2f1ff9af8a067dcda76 Mon Sep 17 00:00:00 2001 From: opl- Date: Fri, 6 Nov 2020 13:21:39 +0100 Subject: [PATCH 1/2] Use formatted time inputs for segment editing Additionally, removes unused util functions and saves the edits on changes to update the preview immediately --- public/content.css | 8 +-- src/components/SponsorTimeEditComponent.tsx | 76 +++++++-------------- src/utils.ts | 26 +++---- 3 files changed, 40 insertions(+), 70 deletions(-) diff --git a/public/content.css b/public/content.css index 651136fd..62420f2c 100644 --- a/public/content.css +++ b/public/content.css @@ -372,12 +372,8 @@ input::-webkit-inner-spin-button { -moz-appearance: textfield; } -.sponsorTimeEditMinutes { - width: 30px; -} - -.sponsorTimeEditSeconds { - width: 60px; +.sponsorTimeEditInput { + width: 90px; } .sponsorNowButton { diff --git a/src/components/SponsorTimeEditComponent.tsx b/src/components/SponsorTimeEditComponent.tsx index 0f608027..a99a96e7 100644 --- a/src/components/SponsorTimeEditComponent.tsx +++ b/src/components/SponsorTimeEditComponent.tsx @@ -20,7 +20,7 @@ export interface SponsorTimeEditProps { export interface SponsorTimeEditState { editing: boolean; - sponsorTimeEdits: string[][]; + sponsorTimeEdits: [string, string]; } class SponsorTimeEditComponent extends React.Component { @@ -40,7 +40,7 @@ class SponsorTimeEditComponent extends React.Component - { let sponsorTimeEdits = this.state.sponsorTimeEdits; - sponsorTimeEdits[0][0] = e.target.value; + sponsorTimeEdits[0] = e.target.value; this.setState({sponsorTimeEdits}); - }}> - - { - let sponsorTimeEdits = this.state.sponsorTimeEdits; - sponsorTimeEdits[0][1] = e.target.value; - - this.setState({sponsorTimeEdits}); + this.saveEditTimes(); }}> @@ -126,29 +115,18 @@ class SponsorTimeEditComponent extends React.Component - { let sponsorTimeEdits = this.state.sponsorTimeEdits; - sponsorTimeEdits[1][0] = e.target.value; + sponsorTimeEdits[1] = e.target.value; this.setState({sponsorTimeEdits}); - }}> - - { - let sponsorTimeEdits = this.state.sponsorTimeEdits; - sponsorTimeEdits[1][1] = e.target.value; - - this.setState({sponsorTimeEdits}); + this.saveEditTimes(); }}> @@ -318,19 +296,23 @@ class SponsorTimeEditComponent extends React.Component Date: Sun, 8 Nov 2020 06:13:09 +0100 Subject: [PATCH 2/2] Add support for commas in the time editor Makes numpad input easier on some locales. --- src/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index eb7d09f8..38f8688d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -349,7 +349,7 @@ class Utils { } getFormattedTimeToSeconds(formatted: string): number | null { - const fragments = /^(?:(?:(\d+):)?(\d+):)?(\d*(?:\.\d+)?)$/.exec(formatted); + const fragments = /^(?:(?:(\d+):)?(\d+):)?(\d*(?:[.,]\d+)?)$/.exec(formatted); if (fragments === null) { return null; @@ -357,7 +357,7 @@ class Utils { const hours = fragments[1] ? parseInt(fragments[1]) : 0; const minutes = fragments[2] ? parseInt(fragments[2] || '0') : 0; - const seconds = fragments[3] ? parseFloat(fragments[3]) : 0; + const seconds = fragments[3] ? parseFloat(fragments[3].replace(',', '.')) : 0; return hours * 3600 + minutes * 60 + seconds; }