From 1aca0be7520cf7e6efac235f8d12b1100d8c72da Mon Sep 17 00:00:00 2001 From: albert-ong-wei-jun Date: Fri, 27 Oct 2023 00:49:46 -0700 Subject: [PATCH 1/2] Fix word count and paragraph count in Filler/index.js * enable word count to decrement below 500 * fix bug where website crashes when delete counts input --- src/components/Filler/index.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/components/Filler/index.js b/src/components/Filler/index.js index 7a565fd..5f2865c 100644 --- a/src/components/Filler/index.js +++ b/src/components/Filler/index.js @@ -8,11 +8,14 @@ export class Filler extends React.PureComponent { super(props); this.state = { paragraphCount: 3, + paragraphText: "3", wordcount: 500, + wordText: "500", copied: false }; this.textareaRef = React.createRef(); this.updateWordcount = this.updateWordcount.bind(this); + this.updateParagraphcount = this.updateParagraphcount.bind(this); } generateText() { @@ -44,7 +47,23 @@ export class Filler extends React.PureComponent { } updateWordcount(wordcount) { - this.setState({ wordcount: wordcount > 99 ? parseInt(wordcount) : 500, copied: true }, () => { + this.setState({ + wordText: wordcount && /^\d+$/.test(wordcount) && wordcount.charAt(0) !== "0" ? wordcount : "", + wordcount: wordcount && /^\d+$/.test(wordcount) && wordcount >= 0 ? parseInt(wordcount) : 0, // check for integer values >= 0 + copied: true + }, () => { + this.textareaRef.current.select(); + document.execCommand("copy"); + this.textareaRef.current.focus(); + }) + } + + updateParagraphcount(paragraphCount) { + this.setState({ + paragraphText: paragraphCount && /^\d+$/.test(paragraphCount) && paragraphCount.charAt(0) !== "0" ? paragraphCount : "", + paragraphCount: paragraphCount && /^\d+$/.test(paragraphCount) && paragraphCount >= 1 ? parseInt(paragraphCount) : 1, // check for integer values >= 1 + copied: true + }, () => { this.textareaRef.current.select(); document.execCommand("copy"); this.textareaRef.current.focus(); @@ -59,17 +78,13 @@ export class Filler extends React.PureComponent {
- this.updateWordcount(e.target.value)} value={this.state.wordcount} step="100" type="number" name="wordcount" min="0" /> + this.updateWordcount(e.target.value)} value={this.state.wordText} step="100" type="number" name="wordcount" min="0" /> this.updateWordcount(Math.ceil((this.state.wordcount + 99) / 100) * 100)}>↑ this.updateWordcount(Math.round((this.state.wordcount - 99) / 100) * 100)}>↓
- this.setState({ paragraphCount: parseInt(e.target.value), copied: true }, () => { - this.textareaRef.current.select(); - document.execCommand("copy"); - this.textareaRef.current.focus(); - })} value={this.state.paragraphCount} type="number" name="paragraphs" min="1" /> + this.updateParagraphcount(e.target.value)} value={this.state.paragraphText} type="number" name="paragraphs" min="1" />
{this.state.copied && }
From 0ee9459800b1f8735196371191ed1fb654ffe5df Mon Sep 17 00:00:00 2001 From: Matthew Yu <56417255+matthewyu01@users.noreply.github.com> Date: Sat, 11 Nov 2023 11:41:22 -0800 Subject: [PATCH 2/2] Fix charAt error when clicking black arrows --- src/components/Filler/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/Filler/index.js b/src/components/Filler/index.js index 5f2865c..43eb84d 100644 --- a/src/components/Filler/index.js +++ b/src/components/Filler/index.js @@ -47,6 +47,7 @@ export class Filler extends React.PureComponent { } updateWordcount(wordcount) { + wordcount = wordcount?.toString(); this.setState({ wordText: wordcount && /^\d+$/.test(wordcount) && wordcount.charAt(0) !== "0" ? wordcount : "", wordcount: wordcount && /^\d+$/.test(wordcount) && wordcount >= 0 ? parseInt(wordcount) : 0, // check for integer values >= 0