Work on MyAccount stuff
This commit is contained in:
parent
728ba28d5b
commit
687c65268d
|
@ -0,0 +1,37 @@
|
||||||
|
import Inferno from 'inferno';
|
||||||
|
import { Component } from 'inferno';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
export class LoginForm extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
PropTypes.checkPropTypes({
|
||||||
|
email: PropTypes.string.isRequired,
|
||||||
|
username: PropTypes.string.isRequired,
|
||||||
|
publicName: PropTypes.string.isRequired,
|
||||||
|
allowEmails: PropTypes.bool.isRequired,
|
||||||
|
useIPAPronunciation: PropTypes.bool.isRequired,
|
||||||
|
userDictionaries: PropTypes.array.isRequired,
|
||||||
|
updateUserData: PropTypes.func,
|
||||||
|
changeDictionary: PropTypes.func,
|
||||||
|
}, props, 'prop', 'LoginForm');
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
email: this.props.email,
|
||||||
|
username: this.props.username,
|
||||||
|
publicName: this.props.publicName,
|
||||||
|
allowEmails: this.props.allowEmails,
|
||||||
|
useIPAPronunciation: this.props.useIPAPronunciation,
|
||||||
|
userDictionaries: this.props.userDictionaries,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div className='content has-text-left'>
|
||||||
|
<p>Hello My Account!</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,9 +6,18 @@ import store from 'store';
|
||||||
|
|
||||||
import { Modal } from '../../structure/Modal';
|
import { Modal } from '../../structure/Modal';
|
||||||
import { LoginForm } from './LoginForm';
|
import { LoginForm } from './LoginForm';
|
||||||
|
// import { MyAccount } from './MyAccount';
|
||||||
|
|
||||||
import { request } from '../../../Helpers';
|
import { request } from '../../../Helpers';
|
||||||
|
|
||||||
|
const defaultUserData = {
|
||||||
|
email: '',
|
||||||
|
username: '',
|
||||||
|
publicName: '',
|
||||||
|
allowEmails: true,
|
||||||
|
useIPAPronunciation: true,
|
||||||
|
};
|
||||||
|
|
||||||
export class AccountManager extends Component {
|
export class AccountManager extends Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
@ -17,9 +26,21 @@ export class AccountManager extends Component {
|
||||||
updater: PropTypes.object.isRequired,
|
updater: PropTypes.object.isRequired,
|
||||||
}, props, 'prop', 'AccountManager');
|
}, props, 'prop', 'AccountManager');
|
||||||
|
|
||||||
|
const userData = store.get('LexicongaUserData');
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
isLoggedIn: false,
|
isLoggedIn: false,
|
||||||
|
userData: {
|
||||||
|
email: userData ? userData.email : defaultUserData.email,
|
||||||
|
username: userData ? userData.username : defaultUserData.username,
|
||||||
|
publicName: userData ? userData.publicName : defaultUserData.publicName,
|
||||||
|
allowEmails: userData ? userData.allowEmails : defaultUserData.allowEmails,
|
||||||
|
useIPAPronunciation: userData ? userData.useIPAPronunciation : defaultUserData.useIPAPronunciation,
|
||||||
|
},
|
||||||
|
userDictionaries: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.getDictionaryNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
logIn (email, password) {
|
logIn (email, password) {
|
||||||
|
@ -28,7 +49,12 @@ export class AccountManager extends Component {
|
||||||
|
|
||||||
logOut () {
|
logOut () {
|
||||||
store.remove('LexicongaToken');
|
store.remove('LexicongaToken');
|
||||||
this.setState({ isLoggedIn: false });
|
store.remove('LexicongaUserData');
|
||||||
|
this.setState({
|
||||||
|
isLoggedIn: false,
|
||||||
|
userData: Object.assign({}, defaultUserData),
|
||||||
|
userDictionaries: [],
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
signUp (email, password, userData) {
|
signUp (email, password, userData) {
|
||||||
|
@ -44,23 +70,71 @@ export class AccountManager extends Component {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(data);
|
console.error(data);
|
||||||
} else {
|
} else {
|
||||||
store.set('LexicongaToken', data);
|
store.set('LexicongaToken', data.token);
|
||||||
this.setState({ isLoggedIn: true }, () => {
|
store.set('LexicongaUserData', data.user);
|
||||||
|
this.setState({
|
||||||
|
isLoggedIn: true,
|
||||||
|
userData: data.user,
|
||||||
|
}, () => {
|
||||||
|
this.getDictionaryNames();
|
||||||
this.props.updater.sync();
|
this.props.updater.sync();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateUserData (newUserData) {
|
||||||
|
const token = store.get('LexicongaToken');
|
||||||
|
|
||||||
|
if (token) {
|
||||||
|
store.set('LexicongaUserData', newUserData);
|
||||||
|
this.setState({ userData: newUserData }, () => {
|
||||||
|
request('set-user-data', { token, userData: newUserData }, (response) => {
|
||||||
|
const {data, error} = response;
|
||||||
|
if (error) {
|
||||||
|
console.error(data);
|
||||||
|
} else {
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getDictionaryNames () {
|
||||||
|
const token = store.get('LexicongaToken');
|
||||||
|
|
||||||
|
if (token) {
|
||||||
|
return request('get-all-dictionary-names', { token }, (response) => {
|
||||||
|
const {data, error} = response;
|
||||||
|
if (error) {
|
||||||
|
console.error(data);
|
||||||
|
} else {
|
||||||
|
this.setState({ userDictionaries: data });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const token = store.get('LexicongaToken');
|
const token = store.get('LexicongaToken');
|
||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
|
const { userData } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Modal buttonText='Account' title='My Account'>
|
<Modal buttonText='Account' title='My Account' onShow={ this.getDictionaryNames.bind(this) }>
|
||||||
<div className='content has-text-left'>
|
<div className='content has-text-left'>
|
||||||
<p>Hello My Account!</p>
|
<p>Hello My Account!</p>
|
||||||
</div>
|
</div>
|
||||||
|
{/* <MyAccount
|
||||||
|
email={ userData.email }
|
||||||
|
username={ userData.username }
|
||||||
|
publicName={ userData.publicName }
|
||||||
|
allowEmails={ userData.allowEmails }
|
||||||
|
useIPAPronunciation={ userData.useIPAPronunciation }
|
||||||
|
updateUserData={ this.updateUserData.bind(this) }
|
||||||
|
changeDictionary={ () => {} } /> */}
|
||||||
</Modal>
|
</Modal>
|
||||||
<a className='button' onClick={this.logOut.bind(this)}>
|
<a className='button' onClick={this.logOut.bind(this)}>
|
||||||
Log Out
|
Log Out
|
||||||
|
|
Loading…
Reference in New Issue