diff --git a/vocodes/src/v1/OldVocodesContainer.tsx b/vocodes/src/v1/OldVocodesContainer.tsx index 32e6227de5..8b38e3207b 100644 --- a/vocodes/src/v1/OldVocodesContainer.tsx +++ b/vocodes/src/v1/OldVocodesContainer.tsx @@ -19,7 +19,7 @@ import { SignupComponent } from '../v2/signup/SignupComponent'; import { ApiConfig } from './api/ApiConfig'; import { SessionStateResponse } from './api/SessionState'; import { LoginComponent } from '../v2/login/LoginComponent'; -import { UploadComponent } from './modes/upload/UploadComponent'; +import { UploadComponent } from '../v2/upload/UploadComponent'; interface Props { // Certan browsers (iPhone) have pitiful support for drawing APIs. Worse yet, @@ -415,28 +415,6 @@ class OldVocodesContainer extends React.Component { case Mode.TERMS_MODE: component = ; break; - - case Mode.SIGNUP_MODE: - component = - break; - case Mode.LOGIN_MODE: - component = - break; - case Mode.UPLOAD_MODE: - component = - break; } return (
diff --git a/vocodes/src/v1/modes/login/LoginComponent.tsx b/vocodes/src/v1/modes/login/LoginComponent.tsx deleted file mode 100644 index e8bef3da6e..0000000000 --- a/vocodes/src/v1/modes/login/LoginComponent.tsx +++ /dev/null @@ -1,159 +0,0 @@ -import React from 'react'; -import { ApiConfig } from '../../v1/api/ApiConfig'; -import { Mode } from '../../AppMode'; - -enum FieldTriState { - EMPTY_FALSE, - FALSE, - TRUE, -} - -interface Props { - loggedIn: boolean, - querySessionCallback : () => void, - switchModeCallback?: (mode: Mode) => void, -} - -interface State { - usernameOrEmail: string, - usernameOrEmailValid: FieldTriState, - usernameOrEmailInvalidReason: string, - - password: string, - passwordValid: FieldTriState, - passwordInvalidReason: string, -} - -class LoginComponent 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.loggedIn) { - return
Invalid view for logged in users.
; - } - - return ( -
-

Login

- -

- -
-
- -
- - - - - - - -
- {/*

*/} -
- -
- -
- - - - - - - -
- {/*

*/} -
- -
- -
-
- -
-
-
-
- ) - } -} - -export { LoginComponent }; \ No newline at end of file diff --git a/vocodes/src/v1/modes/signup/SignupComponent.tsx b/vocodes/src/v1/modes/signup/SignupComponent.tsx deleted file mode 100644 index f2e4875708..0000000000 --- a/vocodes/src/v1/modes/signup/SignupComponent.tsx +++ /dev/null @@ -1,381 +0,0 @@ -import React from 'react'; -import { ApiConfig } from '../../v1/api/ApiConfig'; -import { Mode } from '../../AppMode'; - -enum FieldTriState { - EMPTY_FALSE, - FALSE, - TRUE, -} - -interface Props { - loggedIn: boolean, - querySessionCallback : () => void, - switchModeCallback?: (mode: Mode) => void, -} - -interface State { - username: string, - usernameValid: FieldTriState, - usernameInvalidReason: string, - - email: string, - emailValid: FieldTriState, - emailInvalidReason: string, - - password: string, - passwordValid: FieldTriState, - passwordInvalidReason: string, - - passwordConfirmation: string, - passwordConfirmationValid: FieldTriState, - passwordConfirmationInvalidReason: string, -} - -class SignupComponent extends React.Component { - - constructor(props: Props) { - super(props); - this.state = { - username: "", - usernameValid: FieldTriState.EMPTY_FALSE, - usernameInvalidReason: "", - - email: "", - emailValid: FieldTriState.EMPTY_FALSE, - emailInvalidReason: "", - - password: "", - passwordValid: FieldTriState.EMPTY_FALSE, - passwordInvalidReason: "", - - passwordConfirmation: "", - passwordConfirmationValid: FieldTriState.EMPTY_FALSE, - passwordConfirmationInvalidReason: "", - }; - } - - handleUsernameChange = (ev: React.FormEvent) => { - ev.preventDefault(); - - const username = (ev.target as HTMLInputElement).value; - - let usernameValid = FieldTriState.EMPTY_FALSE; - let usernameInvalidReason = ""; - - if (username.length > 1) { - if (username.length < 3) { - usernameValid = FieldTriState.FALSE; - usernameInvalidReason = "username is too short"; - } else if (username.length > 15) { - usernameValid = FieldTriState.FALSE; - usernameInvalidReason = "username is too long"; - } else { - usernameValid = FieldTriState.TRUE; - } - } - - this.setState({ - username: username, - usernameValid: usernameValid, - usernameInvalidReason: usernameInvalidReason, - }) - - return false; - } - - handleEmailChange = (ev: React.FormEvent) => { - ev.preventDefault(); - - const email = (ev.target as HTMLInputElement).value; - - let emailValid = FieldTriState.EMPTY_FALSE; - let emailInvalidReason = ""; - - if (email.length > 1) { - if (email.length < 3) { - emailValid = FieldTriState.FALSE; - emailInvalidReason = "email is too short"; - } else if (!email.includes("@")) { - emailValid = FieldTriState.FALSE; - emailInvalidReason = "email is invalid"; - } else { - emailValid = FieldTriState.TRUE; - } - } - - this.setState({ - email: email, - emailValid: emailValid, - emailInvalidReason: emailInvalidReason, - }) - - return false; - } - - handlePasswordChange = (ev: React.FormEvent) => { - ev.preventDefault(); - - const password = (ev.target as HTMLInputElement).value; - - let passwordValid = FieldTriState.EMPTY_FALSE; - let passwordInvalidReason = ""; - let passwordConfirmationValid = FieldTriState.EMPTY_FALSE; - let passwordConfirmationInvalidReason = ""; - - if (password.length > 1) { - if (password.length < 5) { - passwordValid = FieldTriState.FALSE; - passwordInvalidReason = "password is too short"; - } else { - passwordValid = FieldTriState.TRUE; - } - - if (password !== this.state.passwordConfirmation) { - passwordConfirmationValid = FieldTriState.FALSE; - passwordConfirmationInvalidReason = "passwords do not match"; - } else { - passwordConfirmationValid = FieldTriState.TRUE; - passwordConfirmationInvalidReason = ""; - - } - } - - this.setState({ - password: password, - passwordValid: passwordValid, - passwordInvalidReason: passwordInvalidReason, - passwordConfirmationValid: passwordConfirmationValid, - passwordConfirmationInvalidReason: passwordConfirmationInvalidReason, - }) - - return false; - } - - - handlePasswordConfirmationChange = (ev: React.FormEvent) => { - ev.preventDefault(); - - const passwordConfirmation = (ev.target as HTMLInputElement).value; - - let passwordConfirmationValid = FieldTriState.EMPTY_FALSE; - let passwordConfirmationInvalidReason = ""; - - if (passwordConfirmation.length > 1) { - - if (passwordConfirmation !== this.state.password) { - passwordConfirmationValid = FieldTriState.FALSE; - passwordConfirmationInvalidReason = "passwords do not match"; - } else { - passwordConfirmationValid = FieldTriState.TRUE; - passwordConfirmationInvalidReason = ""; - - } - } - - this.setState({ - passwordConfirmation: passwordConfirmation, - passwordConfirmationValid: passwordConfirmationValid, - passwordConfirmationInvalidReason: passwordConfirmationInvalidReason, - }) - - return false; - } - - handleFormSubmit = (ev: React.FormEvent) : boolean => { - ev.preventDefault(); - - if (!this.state.usernameValid || - !this.state.emailValid || - !this.state.passwordValid || - !this.state.passwordConfirmationValid) { - return false; - } - - const api = new ApiConfig(); - const endpointUrl = api.createAccount(); - - const request = { - username: this.state.username, - email_address: this.state.email, - password: this.state.password, - password_confirmation: this.state.passwordConfirmation, - } - - 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('create account 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.loggedIn) { - return
Invalid view for logged in users.
; - } - - let usernameInputClass = "input"; - let usernameHelpClass = "help"; - switch (this.state.usernameValid) { - case FieldTriState.EMPTY_FALSE: - break; - case FieldTriState.FALSE: - usernameInputClass += " is-danger"; - usernameHelpClass += " is-danger"; - break; - case FieldTriState.TRUE: - usernameInputClass += " is-success"; - usernameHelpClass += " is-success"; - break; - } - - let emailInputClass = "input"; - let emailHelpClass = "help"; - switch (this.state.emailValid) { - case FieldTriState.EMPTY_FALSE: - break; - case FieldTriState.FALSE: - emailInputClass += " is-danger"; - emailHelpClass += " is-danger"; - break; - case FieldTriState.TRUE: - emailInputClass += " is-success"; - emailHelpClass += " is-success"; - break; - } - - let passwordInputClass = "input"; - let passwordHelpClass = "help"; - switch (this.state.passwordValid) { - case FieldTriState.EMPTY_FALSE: - break; - case FieldTriState.FALSE: - passwordInputClass += " is-danger"; - passwordHelpClass += " is-danger"; - break; - case FieldTriState.TRUE: - passwordInputClass += " is-success"; - passwordHelpClass += " is-success"; - break; - } - - let passwordConfirmationInputClass = "input"; - let passwordConfirmationHelpClass = "help"; - switch (this.state.passwordConfirmationValid) { - case FieldTriState.EMPTY_FALSE: - break; - case FieldTriState.FALSE: - passwordConfirmationInputClass += " is-danger"; - passwordConfirmationHelpClass += " is-danger"; - break; - case FieldTriState.TRUE: - passwordConfirmationInputClass += " is-success"; - passwordConfirmationHelpClass += " is-success"; - break; - } - - return ( -
-

Sign Up

- -
-
- -
- - - - - - - -
-

{this.state.usernameInvalidReason}

-
- -
- -
- - - - - - - -
-

{this.state.emailInvalidReason}

-
- -
- -
- - - - - - - -
-

{this.state.passwordInvalidReason}

-
- -
- -
- - - - - - - -
-

{this.state.passwordConfirmationInvalidReason}

-
- -
- -
- Remember your password! We don't have password reset currently, and it'll be a - few more weeks before it's added (there are more important features to work on). If you lose your - password, please let us know in Discord. -
- -
-
- -
-
- -
- -
- ) - } -} - -export { SignupComponent }; \ No newline at end of file diff --git a/vocodes/src/v1/modes/upload/UploadComponent.tsx b/vocodes/src/v1/modes/upload/UploadComponent.tsx deleted file mode 100644 index ff688ed934..0000000000 --- a/vocodes/src/v1/modes/upload/UploadComponent.tsx +++ /dev/null @@ -1,251 +0,0 @@ -import React from 'react'; -import { ApiConfig } from '../../api/ApiConfig'; -import { Mode } from '../../../AppMode'; -import { v4 } from 'uuid'; - -enum UploadType { - TTS_MODEL, - W2L_TEMPLATE, -} - -enum FieldTriState { - EMPTY_FALSE, - FALSE, - TRUE, -} - -interface Props { - loggedIn: boolean, - querySessionCallback : () => void, - switchModeCallback: (mode: Mode) => void, -} - -interface State { - uploadType: UploadType, - - title: string, - titleValid: FieldTriState, - titleInvalidReason: string, - - downloadUrl: string, - downloadUrlValid: FieldTriState, - downloadUrlInvalidReason: string, - - idempotencyToken: string, -} - -class UploadComponent extends React.Component { - - constructor(props: Props) { - super(props); - this.state = { - uploadType: UploadType.TTS_MODEL, - - title: "", - titleValid: FieldTriState.EMPTY_FALSE, - titleInvalidReason: "", - - downloadUrl: "", - downloadUrlValid: FieldTriState.EMPTY_FALSE, - downloadUrlInvalidReason: "", - - idempotencyToken: "", - }; - } - - handleTitleChange = (ev: React.FormEvent) => { - ev.preventDefault(); - - const title = (ev.target as HTMLInputElement).value; - - this.setState({ - title: title, - }); - - return false; - } - - handleDownloadUrlChange = (ev: React.FormEvent) => { - ev.preventDefault(); - - const downloadUrl = (ev.target as HTMLInputElement).value; - - this.setState({ - downloadUrl: downloadUrl, - }); - - return false; - } - - handleFormSubmit = (ev: React.FormEvent) : boolean => { - ev.preventDefault(); - - const api = new ApiConfig(); - let endpointUrl = ""; - - switch (this.state.uploadType) { - case UploadType.TTS_MODEL: - endpointUrl = api.uploadTts(); - break; - case UploadType.W2L_TEMPLATE: - endpointUrl = api.uploadW2l(); - break; - } - - let idempotency_token = this.state.idempotencyToken; - - idempotency_token = v4(); - - const request = { - idempotency_token: idempotency_token, - title: this.state.title, - download_url: this.state.downloadUrl, - } - - 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('upload response', res) - if (res.success) { - this.props.switchModeCallback(Mode.SPEAK_MODE); - return; - } - }) - .catch(e => { - //this.props.onSpeakErrorCallback(); - }); - - return false; - } - - setTts = () => { - this.setState({ - uploadType: UploadType.TTS_MODEL, - }) - } - - setW2l = () => { - this.setState({ - uploadType: UploadType.W2L_TEMPLATE, - }) - } - - public render() { - if (!this.props.loggedIn) { - return ( -
-

You must be logged in to upload!

- Invalid view for logged out users. -
- ); - } - - let extra =
; - - if (this.state.uploadType === UploadType.TTS_MODEL) { - extra = ( -
- Over $500 in prizes! -

You can help vo.codes grow by uploading Tacotron2 models. - The person that uploads the most models will get $100, - the person that uploads the most popular model will get $100, - and a number of other lucky winners will be chosen at random to - recieve cash prizes.

-
- ); - } - - let title = ""; - let ttsClasses = ""; - let w2lClasses = ""; - - switch (this.state.uploadType) { - case UploadType.TTS_MODEL: - title = "Upload Tacotron 2 Model"; - ttsClasses = "button is-primary is-large is-light"; - w2lClasses = "button is-primary is-large"; - break; - case UploadType.W2L_TEMPLATE: - title = "Upload W2L Video or Image Template"; - ttsClasses = "button is-primary is-large"; - w2lClasses = "button is-primary is-large is-light"; - break; - } - - return ( -
-

{title}

- -
-
- -
-
- -
-
- - {extra} - -
-
- -
- - - - - - - -
-

{this.state.titleInvalidReason}

-
- - {/* - https://drive.google.com/file/d/{TOKEN}/view?usp=sharing - */} -
- -
- - - - - - - -
-

{this.state.downloadUrlInvalidReason}

-
- -
- -
-
- -
-
-
-
- ) - } -} - -export { UploadComponent }; \ No newline at end of file diff --git a/vocodes/src/v2/NewTopNav.tsx b/vocodes/src/v2/NewTopNav.tsx index bf7f9316e2..33e6829658 100644 --- a/vocodes/src/v2/NewTopNav.tsx +++ b/vocodes/src/v2/NewTopNav.tsx @@ -113,17 +113,17 @@ function NewTopNav(props: Props) {
- Upload TTS ⬆
- Upload Video ⬆
- My Data
diff --git a/vocodes/src/v2/NewVocodesContainer.tsx b/vocodes/src/v2/NewVocodesContainer.tsx index a537920fdc..675653505a 100644 --- a/vocodes/src/v2/NewVocodesContainer.tsx +++ b/vocodes/src/v2/NewVocodesContainer.tsx @@ -84,7 +84,6 @@ class NewVocodesContainer extends React.Component { {}} sessionWrapper={this.props.sessionWrapper} /> diff --git a/vocodes/src/v2/upload/UploadComponent.tsx b/vocodes/src/v2/upload/UploadComponent.tsx index cb9c8f6162..b7d4a5a68e 100644 --- a/vocodes/src/v2/upload/UploadComponent.tsx +++ b/vocodes/src/v2/upload/UploadComponent.tsx @@ -1,8 +1,14 @@ import React from 'react'; import { ApiConfig } from '../../v1/api/ApiConfig'; import { Mode } from '../../AppMode'; +import { v4 } from 'uuid'; import { SessionWrapper } from '../../session/SessionWrapper'; +enum UploadType { + TTS_MODEL, + W2L_TEMPLATE, +} + enum FieldTriState { EMPTY_FALSE, FALSE, @@ -10,19 +16,21 @@ enum FieldTriState { } interface Props { - sessionWrapper: SessionWrapper, - querySessionCallback : () => void, - switchModeCallback?: (mode: Mode) => void, + sessionWrapper : SessionWrapper, } interface State { - usernameOrEmail: string, - usernameOrEmailValid: FieldTriState, - usernameOrEmailInvalidReason: string, + uploadType: UploadType, - password: string, - passwordValid: FieldTriState, - passwordInvalidReason: string, + title: string, + titleValid: FieldTriState, + titleInvalidReason: string, + + downloadUrl: string, + downloadUrlValid: FieldTriState, + downloadUrlInvalidReason: string, + + idempotencyToken: string, } class UploadComponent extends React.Component { @@ -30,36 +38,40 @@ class UploadComponent extends React.Component { constructor(props: Props) { super(props); this.state = { - usernameOrEmail: "", - usernameOrEmailValid: FieldTriState.EMPTY_FALSE, - usernameOrEmailInvalidReason: "", + uploadType: UploadType.TTS_MODEL, - password: "", - passwordValid: FieldTriState.EMPTY_FALSE, - passwordInvalidReason: "", + title: "", + titleValid: FieldTriState.EMPTY_FALSE, + titleInvalidReason: "", + + downloadUrl: "", + downloadUrlValid: FieldTriState.EMPTY_FALSE, + downloadUrlInvalidReason: "", + + idempotencyToken: "", }; } - handleUsernameOrEmailChange = (ev: React.FormEvent) => { + handleTitleChange = (ev: React.FormEvent) => { ev.preventDefault(); - const usernameOrEmail = (ev.target as HTMLInputElement).value; + const title = (ev.target as HTMLInputElement).value; this.setState({ - usernameOrEmail: usernameOrEmail, - }) + title: title, + }); return false; } - handlePasswordChange = (ev: React.FormEvent) => { + handleDownloadUrlChange = (ev: React.FormEvent) => { ev.preventDefault(); - const password = (ev.target as HTMLInputElement).value; + const downloadUrl = (ev.target as HTMLInputElement).value; this.setState({ - password: password, - }) + downloadUrl: downloadUrl, + }); return false; } @@ -68,11 +80,25 @@ class UploadComponent extends React.Component { ev.preventDefault(); const api = new ApiConfig(); - const endpointUrl = api.login(); + let endpointUrl = ""; + + switch (this.state.uploadType) { + case UploadType.TTS_MODEL: + endpointUrl = api.uploadTts(); + break; + case UploadType.W2L_TEMPLATE: + endpointUrl = api.uploadW2l(); + break; + } + + let idempotency_token = this.state.idempotencyToken; + + idempotency_token = v4(); const request = { - username_or_email: this.state.usernameOrEmail, - password: this.state.password, + idempotency_token: idempotency_token, + title: this.state.title, + download_url: this.state.downloadUrl, } fetch(endpointUrl, { @@ -86,14 +112,9 @@ class UploadComponent extends React.Component { }) .then(res => res.json()) .then(res => { - console.log('login response', res) + console.log('upload response', res) if (res.success) { - console.log('querying new session'); - this.props.querySessionCallback(); - - if (this.props.switchModeCallback !== undefined) { - this.props.switchModeCallback(Mode.SPEAK_MODE); - } + //this.props.switchModeCallback(Mode.SPEAK_MODE); return; } }) @@ -104,22 +125,88 @@ class UploadComponent extends React.Component { return false; } + setTts = () => { + this.setState({ + uploadType: UploadType.TTS_MODEL, + }) + } + + setW2l = () => { + this.setState({ + uploadType: UploadType.W2L_TEMPLATE, + }) + } + public render() { - if (this.props.sessionWrapper.isLoggedIn()) { - return
Invalid view for logged in users.
; + if (!this.props.sessionWrapper.isLoggedIn()) { + return ( +
+

You must be logged in to upload!

+ Invalid view for logged out users. +
+ ); + } + + let extra =
; + + if (this.state.uploadType === UploadType.TTS_MODEL) { + extra = ( +
+ Over $500 in prizes! +

You can help vo.codes grow by uploading Tacotron2 models. + The person that uploads the most models will get $100, + the person that uploads the most popular model will get $100, + and a number of other lucky winners will be chosen at random to + recieve cash prizes.

+
+ ); + } + + let title = ""; + let ttsClasses = ""; + let w2lClasses = ""; + + switch (this.state.uploadType) { + case UploadType.TTS_MODEL: + title = "Upload Tacotron 2 Model"; + ttsClasses = "button is-primary is-large is-light"; + w2lClasses = "button is-primary is-large"; + break; + case UploadType.W2L_TEMPLATE: + title = "Upload W2L Video or Image Template"; + ttsClasses = "button is-primary is-large"; + w2lClasses = "button is-primary is-large is-light"; + break; } return (
-

Login

+

{title}

-

+
+
+ +
+
+ +
+
+ + {extra}
- +
- + @@ -127,13 +214,16 @@ class UploadComponent extends React.Component {
- {/*

*/} +

{this.state.titleInvalidReason}

+ {/* + https://drive.google.com/file/d/{TOKEN}/view?usp=sharing + */}
- +
- + @@ -141,14 +231,14 @@ class UploadComponent extends React.Component {
- {/*

*/} +

{this.state.downloadUrlInvalidReason}


- +
@@ -157,4 +247,4 @@ class UploadComponent extends React.Component { } } -export { UploadComponent }; +export { UploadComponent }; \ No newline at end of file