From 1c5d288691b800da7b4e8014ac75dc4dc9437614 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Wed, 26 May 2021 02:44:00 -0400 Subject: [PATCH] cleanup/wip --- vocodes/src/App.tsx | 3 +- vocodes/src/migration/MigrationTopNav.tsx | 5 - .../src/migration/MigrationTopNav_Session.tsx | 25 +-- vocodes/src/v2/NewTopNav.tsx | 3 +- vocodes/src/v2/NewVocodesContainer.tsx | 8 + .../v2/profile_data/ProfileDataComponent.tsx | 160 ++++++++++++++++++ 6 files changed, 184 insertions(+), 20 deletions(-) create mode 100644 vocodes/src/v2/profile_data/ProfileDataComponent.tsx diff --git a/vocodes/src/App.tsx b/vocodes/src/App.tsx index 7c66db66fd..1b46b77816 100644 --- a/vocodes/src/App.tsx +++ b/vocodes/src/App.tsx @@ -117,10 +117,9 @@ class App extends React.Component {
+ diff --git a/vocodes/src/migration/MigrationTopNav.tsx b/vocodes/src/migration/MigrationTopNav.tsx index d4343e16b9..b598de6f97 100644 --- a/vocodes/src/migration/MigrationTopNav.tsx +++ b/vocodes/src/migration/MigrationTopNav.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import { MigrationMode } from '../App' import { MigrationTopNav_Session } from './MigrationTopNav_Session'; import { MigrationTopNav_VersionSwitch } from './MigrationTopNav_VersionSwitch'; import { SessionWrapper } from '../session/SessionWrapper'; @@ -7,8 +6,6 @@ import { SessionWrapper } from '../session/SessionWrapper'; interface Props { sessionWrapper: SessionWrapper, enableAlpha: boolean, - migrationMode: MigrationMode, - setMigrationModeCallback: (mode: MigrationMode) => void, } function MigrationTopNav(props: Props) { @@ -24,8 +21,6 @@ function MigrationTopNav(props: Props) { ) diff --git a/vocodes/src/migration/MigrationTopNav_Session.tsx b/vocodes/src/migration/MigrationTopNav_Session.tsx index d24984bc9a..3efedccdc9 100644 --- a/vocodes/src/migration/MigrationTopNav_Session.tsx +++ b/vocodes/src/migration/MigrationTopNav_Session.tsx @@ -1,13 +1,10 @@ import React from 'react'; -import { MigrationMode } from '../App' import { SessionWrapper } from '../session/SessionWrapper'; import { Link } from 'react-router-dom'; interface Props { sessionWrapper: SessionWrapper, enableAlpha: boolean, - migrationMode: MigrationMode, - setMigrationModeCallback: (mode: MigrationMode) => void, } function MigrationTopNav_Session(props: Props) { @@ -25,16 +22,20 @@ function MigrationTopNav_Session(props: Props) { let sessionLink =

; if (loggedIn) { - sessionLink = + let url = `/profile/${displayName}`; + sessionLink = ( + {displayName} + ); } else { - sessionLink = props.setMigrationModeCallback(MigrationMode.OLD_VOCODES)} - >Sign Up / Login + sessionLink = ( + Sign Up / Login + ); } return sessionLink; diff --git a/vocodes/src/v2/NewTopNav.tsx b/vocodes/src/v2/NewTopNav.tsx index 8516cc0ca4..8801a1e70f 100644 --- a/vocodes/src/v2/NewTopNav.tsx +++ b/vocodes/src/v2/NewTopNav.tsx @@ -96,6 +96,7 @@ function NewTopNav(props: Props) { ); } + let myDataLink = `/profile/${displayName}/data`; return (

- My Data
diff --git a/vocodes/src/v2/NewVocodesContainer.tsx b/vocodes/src/v2/NewVocodesContainer.tsx index 675653505a..e4465e8c59 100644 --- a/vocodes/src/v2/NewVocodesContainer.tsx +++ b/vocodes/src/v2/NewVocodesContainer.tsx @@ -9,6 +9,7 @@ import { FirehoseComponent } from './firehose/FirehoseComponent'; import { ProfileComponent } from './profile/ProfileComponent'; import { TtsModelListComponent } from './tts_model/TtsModelListComponent'; import { W2lTemplateListComponent } from './w2l_template_list/W2lTemplateListComponent'; +import { ProfileDataComponent } from './profile_data/ProfileDataComponent'; interface Props { sessionWrapper: SessionWrapper, @@ -54,6 +55,13 @@ class NewVocodesContainer extends React.Component { /> + + {}} + sessionWrapper={this.props.sessionWrapper} + /> + + {}} diff --git a/vocodes/src/v2/profile_data/ProfileDataComponent.tsx b/vocodes/src/v2/profile_data/ProfileDataComponent.tsx new file mode 100644 index 0000000000..e858395c02 --- /dev/null +++ b/vocodes/src/v2/profile_data/ProfileDataComponent.tsx @@ -0,0 +1,160 @@ +import React from 'react'; +import { ApiConfig } from '../../v1/api/ApiConfig'; +import { Mode } from '../../AppMode'; +import { SessionWrapper } from '../../session/SessionWrapper'; + +enum FieldTriState { + EMPTY_FALSE, + FALSE, + TRUE, +} + +interface Props { + sessionWrapper: SessionWrapper, + querySessionCallback : () => void, + switchModeCallback?: (mode: Mode) => void, +} + +interface State { + usernameOrEmail: string, + usernameOrEmailValid: FieldTriState, + usernameOrEmailInvalidReason: string, + + password: string, + passwordValid: FieldTriState, + passwordInvalidReason: string, +} + +class ProfileDataComponent extends React.Component { + + constructor(props: Props) { + super(props); + this.state = { + usernameOrEmail: "", + usernameOrEmailValid: FieldTriState.EMPTY_FALSE, + usernameOrEmailInvalidReason: "", + + password: "", + passwordValid: FieldTriState.EMPTY_FALSE, + passwordInvalidReason: "", + }; + } + + handleUsernameOrEmailChange = (ev: React.FormEvent) => { + ev.preventDefault(); + + const usernameOrEmail = (ev.target as HTMLInputElement).value; + + this.setState({ + usernameOrEmail: usernameOrEmail, + }) + + return false; + } + + handlePasswordChange = (ev: React.FormEvent) => { + ev.preventDefault(); + + const password = (ev.target as HTMLInputElement).value; + + this.setState({ + password: password, + }) + + return false; + } + + handleFormSubmit = (ev: React.FormEvent) : boolean => { + ev.preventDefault(); + + const api = new ApiConfig(); + const endpointUrl = api.login(); + + const request = { + username_or_email: this.state.usernameOrEmail, + password: this.state.password, + } + + fetch(endpointUrl, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + credentials: 'include', + body: JSON.stringify(request), + }) + .then(res => res.json()) + .then(res => { + console.log('login response', res) + if (res.success) { + console.log('querying new session'); + this.props.querySessionCallback(); + + if (this.props.switchModeCallback !== undefined) { + this.props.switchModeCallback(Mode.SPEAK_MODE); + } + return; + } + }) + .catch(e => { + //this.props.onSpeakErrorCallback(); + }); + + return false; + } + + public render() { + if (this.props.sessionWrapper.isLoggedIn()) { + return
Invalid view for logged in users.
; + } + + return ( +
+

Login

+ +

+ +
+
+ +
+ + + + + + + +
+ {/*

*/} +
+ +
+ +
+ + + + + + + +
+ {/*

*/} +
+ +
+ +
+
+ +
+
+
+
+ ) + } +} + +export { ProfileDataComponent }; \ No newline at end of file