mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-17 07:04:36 +00:00
remove unused components, move upload component
This commit is contained in:
1 parent
6cee440b32
commit
fc8d1cb7a6
7 files changed
+139
-863
No files matched your search
@@ -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<Props, State> {
|
||||
case Mode.TERMS_MODE:
|
||||
component = <TermsComponent resetModeCallback={this.resetMode} />;
|
||||
break;
|
||||
|
||||
case Mode.SIGNUP_MODE:
|
||||
component = <SignupComponent
|
||||
loggedIn={this.state.loggedIn}
|
||||
querySessionCallback={this.querySession}
|
||||
switchModeCallback={this.switchMode}
|
||||
/>
|
||||
break;
|
||||
case Mode.LOGIN_MODE:
|
||||
component = <LoginComponent
|
||||
loggedIn={this.state.loggedIn}
|
||||
querySessionCallback={this.querySession}
|
||||
switchModeCallback={this.switchMode}
|
||||
/>
|
||||
break;
|
||||
case Mode.UPLOAD_MODE:
|
||||
component = <UploadComponent
|
||||
loggedIn={this.state.loggedIn}
|
||||
querySessionCallback={this.querySession}
|
||||
switchModeCallback={this.switchMode}
|
||||
/>
|
||||
break;
|
||||
}
|
||||
return (
|
||||
<div id="main" className="mainwrap">
|
||||
|
||||
@@ -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<Props, State> {
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
usernameOrEmail: "",
|
||||
usernameOrEmailValid: FieldTriState.EMPTY_FALSE,
|
||||
usernameOrEmailInvalidReason: "",
|
||||
|
||||
password: "",
|
||||
passwordValid: FieldTriState.EMPTY_FALSE,
|
||||
passwordInvalidReason: "",
|
||||
};
|
||||
}
|
||||
|
||||
handleUsernameOrEmailChange = (ev: React.FormEvent<HTMLInputElement>) => {
|
||||
ev.preventDefault();
|
||||
|
||||
const usernameOrEmail = (ev.target as HTMLInputElement).value;
|
||||
|
||||
this.setState({
|
||||
usernameOrEmail: usernameOrEmail,
|
||||
})
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
handlePasswordChange = (ev: React.FormEvent<HTMLInputElement>) => {
|
||||
ev.preventDefault();
|
||||
|
||||
const password = (ev.target as HTMLInputElement).value;
|
||||
|
||||
this.setState({
|
||||
password: password,
|
||||
})
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
handleFormSubmit = (ev: React.FormEvent<HTMLFormElement>) : 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 <div>Invalid view for logged in users.</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className="title is-1"> Login </h1>
|
||||
|
||||
<p></p>
|
||||
|
||||
<form onSubmit={this.handleFormSubmit}>
|
||||
<div className="field">
|
||||
<label className="label">Username or Email</label>
|
||||
<div className="control has-icons-left has-icons-right">
|
||||
<input className="input" type="text" placeholder="Username or Email" value={this.state.usernameOrEmail} onChange={this.handleUsernameOrEmailChange} />
|
||||
<span className="icon is-small is-left">
|
||||
<i className="fas fa-user"></i>
|
||||
</span>
|
||||
<span className="icon is-small is-right">
|
||||
<i className="fas fa-check"></i>
|
||||
</span>
|
||||
</div>
|
||||
{/*<p className="help"></p>*/}
|
||||
</div>
|
||||
|
||||
<div className="field">
|
||||
<label className="label">Password</label>
|
||||
<div className="control has-icons-left has-icons-right">
|
||||
<input className="input" type="password" placeholder="Password" value={this.state.password} onChange={this.handlePasswordChange} />
|
||||
<span className="icon is-small is-left">
|
||||
<i className="fas fa-envelope"></i>
|
||||
</span>
|
||||
<span className="icon is-small is-right">
|
||||
<i className="fas fa-exclamation-triangle"></i>
|
||||
</span>
|
||||
</div>
|
||||
{/*<p className="help"></p>*/}
|
||||
</div>
|
||||
|
||||
<br />
|
||||
|
||||
<div className="field is-grouped">
|
||||
<div className="control">
|
||||
<button className="button is-link is-large">Login</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export { LoginComponent };
|
||||
@@ -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<Props, State> {
|
||||
|
||||
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<HTMLInputElement>) => {
|
||||
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<HTMLInputElement>) => {
|
||||
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<HTMLInputElement>) => {
|
||||
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<HTMLInputElement>) => {
|
||||
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<HTMLFormElement>) : 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 <div>Invalid view for logged in users.</div>;
|
||||
}
|
||||
|
||||
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 (
|
||||
<div>
|
||||
<h1 className="title is-1"> Sign Up </h1>
|
||||
|
||||
<form onSubmit={this.handleFormSubmit}>
|
||||
<div className="field">
|
||||
<label className="label">Username</label>
|
||||
<div className="control has-icons-left has-icons-right">
|
||||
<input className={usernameInputClass} type="text" placeholder="Username" value={this.state.username} onChange={this.handleUsernameChange} />
|
||||
<span className="icon is-small is-left">
|
||||
<i className="fas fa-user"></i>
|
||||
</span>
|
||||
<span className="icon is-small is-right">
|
||||
<i className="fas fa-check"></i>
|
||||
</span>
|
||||
</div>
|
||||
<p className={usernameHelpClass}>{this.state.usernameInvalidReason}</p>
|
||||
</div>
|
||||
|
||||
<div className="field">
|
||||
<label className="label">Email</label>
|
||||
<div className="control has-icons-left has-icons-right">
|
||||
<input className={emailInputClass} type="email" placeholder="Email" value={this.state.email} onChange={this.handleEmailChange} />
|
||||
<span className="icon is-small is-left">
|
||||
<i className="fas fa-envelope"></i>
|
||||
</span>
|
||||
<span className="icon is-small is-right">
|
||||
<i className="fas fa-exclamation-triangle"></i>
|
||||
</span>
|
||||
</div>
|
||||
<p className={emailHelpClass}>{this.state.emailInvalidReason}</p>
|
||||
</div>
|
||||
|
||||
<div className="field">
|
||||
<label className="label">Password</label>
|
||||
<div className="control has-icons-left has-icons-right">
|
||||
<input className={passwordInputClass} type="password" placeholder="Password" value={this.state.password} onChange={this.handlePasswordChange} />
|
||||
<span className="icon is-small is-left">
|
||||
<i className="fas fa-envelope"></i>
|
||||
</span>
|
||||
<span className="icon is-small is-right">
|
||||
<i className="fas fa-exclamation-triangle"></i>
|
||||
</span>
|
||||
</div>
|
||||
<p className={passwordHelpClass}>{this.state.passwordInvalidReason}</p>
|
||||
</div>
|
||||
|
||||
<div className="field">
|
||||
<label className="label">Password Confirmation</label>
|
||||
<div className="control has-icons-left has-icons-right">
|
||||
<input className={passwordConfirmationInputClass} type="password" placeholder="Password confirmation" value={this.state.passwordConfirmation} onChange={this.handlePasswordConfirmationChange} />
|
||||
<span className="icon is-small is-left">
|
||||
<i className="fas fa-envelope"></i>
|
||||
</span>
|
||||
<span className="icon is-small is-right">
|
||||
<i className="fas fa-exclamation-triangle"></i>
|
||||
</span>
|
||||
</div>
|
||||
<p className={passwordConfirmationHelpClass}>{this.state.passwordConfirmationInvalidReason}</p>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
|
||||
<div className="notification is-warning">
|
||||
<strong>Remember your password!</strong> 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.
|
||||
</div>
|
||||
|
||||
<div className="field is-grouped">
|
||||
<div className="control">
|
||||
<button className="button is-link is-large">Sign up</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export { SignupComponent };
|
||||
@@ -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<Props, State> {
|
||||
|
||||
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<HTMLInputElement>) => {
|
||||
ev.preventDefault();
|
||||
|
||||
const title = (ev.target as HTMLInputElement).value;
|
||||
|
||||
this.setState({
|
||||
title: title,
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
handleDownloadUrlChange = (ev: React.FormEvent<HTMLInputElement>) => {
|
||||
ev.preventDefault();
|
||||
|
||||
const downloadUrl = (ev.target as HTMLInputElement).value;
|
||||
|
||||
this.setState({
|
||||
downloadUrl: downloadUrl,
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
handleFormSubmit = (ev: React.FormEvent<HTMLFormElement>) : 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 (
|
||||
<div>
|
||||
<h1>You must be logged in to upload!</h1>
|
||||
Invalid view for logged out users.
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
let extra = <div />;
|
||||
|
||||
if (this.state.uploadType === UploadType.TTS_MODEL) {
|
||||
extra = (
|
||||
<div className="notification is-warning">
|
||||
<strong>Over $500 in prizes!</strong>
|
||||
<p>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.</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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 (
|
||||
<div>
|
||||
<h2> {title} </h2>
|
||||
|
||||
<div className="columns">
|
||||
<div className="column">
|
||||
<button
|
||||
className={ttsClasses}
|
||||
title="Upload TTS"
|
||||
onClick={this.setTts}
|
||||
>Upload TTS Model</button>
|
||||
</div>
|
||||
<div className="column">
|
||||
<button
|
||||
className={w2lClasses}
|
||||
title="Upload W2L"
|
||||
onClick={this.setW2l}
|
||||
>Upload Video Template</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{extra}
|
||||
|
||||
<form onSubmit={this.handleFormSubmit}>
|
||||
<div className="field">
|
||||
<label className="label">Title</label>
|
||||
<div className="control has-icons-left has-icons-right">
|
||||
<input className="input" type="text" placeholder="Title" value={this.state.title} onChange={this.handleTitleChange} />
|
||||
<span className="icon is-small is-left">
|
||||
<i className="fas fa-user"></i>
|
||||
</span>
|
||||
<span className="icon is-small is-right">
|
||||
<i className="fas fa-check"></i>
|
||||
</span>
|
||||
</div>
|
||||
<p className="help">{this.state.titleInvalidReason}</p>
|
||||
</div>
|
||||
|
||||
{/*
|
||||
https://drive.google.com/file/d/{TOKEN}/view?usp=sharing
|
||||
*/}
|
||||
<div className="field">
|
||||
<label className="label">Download URL</label>
|
||||
<div className="control has-icons-left has-icons-right">
|
||||
<input className="input" type="password" placeholder="Download URL" value={this.state.downloadUrl} onChange={this.handleDownloadUrlChange} />
|
||||
<span className="icon is-small is-left">
|
||||
<i className="fas fa-envelope"></i>
|
||||
</span>
|
||||
<span className="icon is-small is-right">
|
||||
<i className="fas fa-exclamation-triangle"></i>
|
||||
</span>
|
||||
</div>
|
||||
<p className="help">{this.state.downloadUrlInvalidReason}</p>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
|
||||
<div className="field is-grouped">
|
||||
<div className="control">
|
||||
<button className="button is-link is-large">Upload</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export { UploadComponent };
|
||||
@@ -113,17 +113,17 @@ function NewTopNav(props: Props) {
|
||||
</div>
|
||||
<div className="columns">
|
||||
<div className="column">
|
||||
<Link to="/upload_tts"
|
||||
<Link to="/upload"
|
||||
className="button is-link is-inverted"
|
||||
>Upload TTS ⬆</Link>
|
||||
</div>
|
||||
<div className="column">
|
||||
<Link to="/upload_video"
|
||||
<Link to="/upload"
|
||||
className="button is-link is-inverted"
|
||||
>Upload Video ⬆</Link>
|
||||
</div>
|
||||
<div className="column">
|
||||
<Link to="/upload_video"
|
||||
<Link to="/upload"
|
||||
className="button is-link is-inverted"
|
||||
>My Data</Link>
|
||||
</div>
|
||||
|
||||
@@ -84,7 +84,6 @@ class NewVocodesContainer extends React.Component<Props, State> {
|
||||
|
||||
<Route path="/upload">
|
||||
<UploadComponent
|
||||
querySessionCallback={()=>{}}
|
||||
sessionWrapper={this.props.sessionWrapper}
|
||||
/>
|
||||
</Route>
|
||||
|
||||
@@ -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<Props, State> {
|
||||
@@ -30,36 +38,40 @@ class UploadComponent extends React.Component<Props, State> {
|
||||
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<HTMLInputElement>) => {
|
||||
handleTitleChange = (ev: React.FormEvent<HTMLInputElement>) => {
|
||||
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<HTMLInputElement>) => {
|
||||
handleDownloadUrlChange = (ev: React.FormEvent<HTMLInputElement>) => {
|
||||
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<Props, State> {
|
||||
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<Props, State> {
|
||||
})
|
||||
.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<Props, State> {
|
||||
return false;
|
||||
}
|
||||
|
||||
setTts = () => {
|
||||
this.setState({
|
||||
uploadType: UploadType.TTS_MODEL,
|
||||
})
|
||||
}
|
||||
|
||||
setW2l = () => {
|
||||
this.setState({
|
||||
uploadType: UploadType.W2L_TEMPLATE,
|
||||
})
|
||||
}
|
||||
|
||||
public render() {
|
||||
if (this.props.sessionWrapper.isLoggedIn()) {
|
||||
return <div>Invalid view for logged in users.</div>;
|
||||
if (!this.props.sessionWrapper.isLoggedIn()) {
|
||||
return (
|
||||
<div>
|
||||
<h1>You must be logged in to upload!</h1>
|
||||
Invalid view for logged out users.
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
let extra = <div />;
|
||||
|
||||
if (this.state.uploadType === UploadType.TTS_MODEL) {
|
||||
extra = (
|
||||
<div className="notification is-warning">
|
||||
<strong>Over $500 in prizes!</strong>
|
||||
<p>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.</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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 (
|
||||
<div>
|
||||
<h1 className="title is-1"> Login </h1>
|
||||
<h2> {title} </h2>
|
||||
|
||||
<p></p>
|
||||
<div className="columns">
|
||||
<div className="column">
|
||||
<button
|
||||
className={ttsClasses}
|
||||
title="Upload TTS"
|
||||
onClick={this.setTts}
|
||||
>Upload TTS Model</button>
|
||||
</div>
|
||||
<div className="column">
|
||||
<button
|
||||
className={w2lClasses}
|
||||
title="Upload W2L"
|
||||
onClick={this.setW2l}
|
||||
>Upload Video Template</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{extra}
|
||||
|
||||
<form onSubmit={this.handleFormSubmit}>
|
||||
<div className="field">
|
||||
<label className="label">Username or Email</label>
|
||||
<label className="label">Title</label>
|
||||
<div className="control has-icons-left has-icons-right">
|
||||
<input className="input" type="text" placeholder="Username or Email" value={this.state.usernameOrEmail} onChange={this.handleUsernameOrEmailChange} />
|
||||
<input className="input" type="text" placeholder="Title" value={this.state.title} onChange={this.handleTitleChange} />
|
||||
<span className="icon is-small is-left">
|
||||
<i className="fas fa-user"></i>
|
||||
</span>
|
||||
@@ -127,13 +214,16 @@ class UploadComponent extends React.Component<Props, State> {
|
||||
<i className="fas fa-check"></i>
|
||||
</span>
|
||||
</div>
|
||||
{/*<p className="help"></p>*/}
|
||||
<p className="help">{this.state.titleInvalidReason}</p>
|
||||
</div>
|
||||
|
||||
{/*
|
||||
https://drive.google.com/file/d/{TOKEN}/view?usp=sharing
|
||||
*/}
|
||||
<div className="field">
|
||||
<label className="label">Password</label>
|
||||
<label className="label">Download URL</label>
|
||||
<div className="control has-icons-left has-icons-right">
|
||||
<input className="input" type="password" placeholder="Password" value={this.state.password} onChange={this.handlePasswordChange} />
|
||||
<input className="input" type="password" placeholder="Download URL" value={this.state.downloadUrl} onChange={this.handleDownloadUrlChange} />
|
||||
<span className="icon is-small is-left">
|
||||
<i className="fas fa-envelope"></i>
|
||||
</span>
|
||||
@@ -141,14 +231,14 @@ class UploadComponent extends React.Component<Props, State> {
|
||||
<i className="fas fa-exclamation-triangle"></i>
|
||||
</span>
|
||||
</div>
|
||||
{/*<p className="help"></p>*/}
|
||||
<p className="help">{this.state.downloadUrlInvalidReason}</p>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
|
||||
<div className="field is-grouped">
|
||||
<div className="control">
|
||||
<button className="button is-link is-large">Login</button>
|
||||
<button className="button is-link is-large">Upload</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@@ -157,4 +247,4 @@ class UploadComponent extends React.Component<Props, State> {
|
||||
}
|
||||
}
|
||||
|
||||
export { UploadComponent };
|
||||
export { UploadComponent };
|
||||
Reference in new issue
Block a user