From 2e10484b098d7dd02684776adc93c1f278ae15be Mon Sep 17 00:00:00 2001 From: lublagg Date: Thu, 29 Aug 2024 14:45:35 -0400 Subject: [PATCH] Move functions out of constructor into renderForm() --- cypress/e2e/workspace.test.ts | 2 +- src/App.tsx | 55 +++++++++++++++++------------------ 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/cypress/e2e/workspace.test.ts b/cypress/e2e/workspace.test.ts index 443ee4c..4f22545 100644 --- a/cypress/e2e/workspace.test.ts +++ b/cypress/e2e/workspace.test.ts @@ -8,7 +8,7 @@ context("Test the overall app", () => { describe("Desktop functionalities", () => { it("renders with text", () => { - ae.getApp().invoke("text").should("include", "Allow others to join your table"); + ae.getApp().invoke("text").should("include", "Begin sharing a table"); }); }); }); diff --git a/src/App.tsx b/src/App.tsx index 4592bf4..499c810 100755 --- a/src/App.tsx +++ b/src/App.tsx @@ -22,16 +22,6 @@ let database: DB; export default class App extends Component { - constructor() { - super({}); - this.setState = this.setState.bind(this); - this.handleJoinShareIdChange = this.handleJoinShareIdChange.bind(this); - this.handleDataLabelChange = this.handleDataLabelChange.bind(this); - this.joinShare = this.joinShare.bind(this); - this.handleDataContextChange = this.handleDataContextChange.bind(this); - this.initiateShare = this.initiateShare.bind(this); - } - public state: IState = { id: "", availableDataContexts: [], @@ -90,6 +80,13 @@ export default class App extends Component { const showShareTableOptions = shareTable && !joinTable && noSelectedSubOptions; const showJoinTableOptions = !shareTable && joinTable && noSelectedSubOptions; + const setState = (state: Partial) => this.setState(state); + const handleJoinShareIdChange = (event: ChangeEvent) => this.handleJoinShareIdChange(event); + const handleDataLabelChange = (event: ChangeEvent) => this.handleDataLabelChange(event); + const joinShare = () => this.joinShare(); + const handleDataContextChange = (event: ChangeEvent) => this.handleDataContextChange(event); + const initiateShare = () => this.initiateShare(); + const availableContextOptions = availableDataContexts.map((dc: DataContext) => ); @@ -97,18 +94,18 @@ export default class App extends Component { if (showFirstStep) { return ( - + ) } else if (showJoinTableOptions) { return ( ) } else if (showShareTableOptions) { return ( ) } else if (joinAndMergeTable) { @@ -117,11 +114,11 @@ export default class App extends Component { joinShareId={this.state.joinShareId} personalDataLabel={this.state.personalDataLabel} lastPersonalDataLabel={this.state.lastPersonalDataLabel} - handleJoinShareIdChange={this.handleJoinShareIdChange} - handleDataLabelChange={this.handleDataLabelChange} - handleDataContextChange={this.handleDataContextChange} - joinShare={this.joinShare} - updateState={this.setState} + handleJoinShareIdChange={handleJoinShareIdChange} + handleDataLabelChange={handleDataLabelChange} + handleDataContextChange={handleDataContextChange} + joinShare={joinShare} + updateState={setState} selectedContextOption={selectedContextOption} availableContextOptions={availableContextOptions} /> @@ -132,10 +129,10 @@ export default class App extends Component { joinShareId={this.state.joinShareId} personalDataLabel={this.state.personalDataLabel} lastPersonalDataLabel={this.state.lastPersonalDataLabel} - handleJoinShareIdChange={this.handleJoinShareIdChange} - handleDataLabelChange={this.handleDataLabelChange} - joinShare={this.joinShare} - updateState={this.setState} + handleJoinShareIdChange={handleJoinShareIdChange} + handleDataLabelChange={handleDataLabelChange} + joinShare={joinShare} + updateState={setState} /> ) } else if (shareExistingTable) { @@ -145,21 +142,21 @@ export default class App extends Component { availableContextOptions={availableContextOptions} personalDataLabel={this.state.personalDataLabel} lastPersonalDataLabel={this.state.lastPersonalDataLabel} - handleDataContextChange={this.handleDataContextChange} - handleDataLabelChange={this.handleDataLabelChange} - initiateShare={this.initiateShare} - updateState={this.setState} + handleDataContextChange={handleDataContextChange} + handleDataLabelChange={handleDataLabelChange} + initiateShare={initiateShare} + updateState={setState} /> ) } else if (createNewTable) { return ( ) }