Fix up login and article content editing and display.
This commit is contained in:
parent
68ddf0e033
commit
0e06767f98
|
@ -220,14 +220,16 @@ export function loginUser(username, password) {
|
|||
},
|
||||
body: JSON.stringify({username: username, password: password})
|
||||
}).then((response) => {
|
||||
if (response.status === 200) {
|
||||
let userInfoJson = response.json();
|
||||
let authToken = Reflect.get(userInfoJson, "token");
|
||||
let user = Reflect.get(userInfoJson, "user");
|
||||
dispatch(updateUser(authToken, user));
|
||||
} else {
|
||||
dispatch(logoutUser(`Unable to login "${username}": ${response.text}`));
|
||||
// TODO: Turn this into a better action:
|
||||
if (response.status !== 200) {
|
||||
// TODO: Deal with resolving the promise first.
|
||||
return dispatch(logoutUser(`Unable to login "${username}": ${response.text()}`));
|
||||
}
|
||||
return response.json();
|
||||
}).then((json) => {
|
||||
let authToken = Reflect.get(json, "token");
|
||||
let user = Reflect.get(json, "user");
|
||||
return dispatch(updateUser(authToken, user));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,8 @@ export class JournalMarkdownView extends React.Component {
|
|||
editorTheme: React.PropTypes.string,
|
||||
params: React.PropTypes.shape({
|
||||
pageId: React.PropTypes.string
|
||||
})
|
||||
}),
|
||||
userCanEdit: React.PropTypes.bool
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +48,12 @@ export class JournalMarkdownView extends React.Component {
|
|||
originalContent: this.props.article || "Please wait while we load this journal entry.",
|
||||
editorPaneState: EditorPaneState.hidden
|
||||
};
|
||||
this.updateEditAllowance(this.props.userCanEdit);
|
||||
this.handleSaveContent = this.handleSaveContent.bind(this);
|
||||
this.handleToggleEditorPane = this.handleToggleEditorPane.bind(this);
|
||||
this.handleSaveContent = this.handleSaveContent.bind(this);
|
||||
this.handleResetContent = this.handleResetContent.bind(this);
|
||||
this.handleUpdateCode = this.handleUpdateCode.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
@ -55,6 +61,11 @@ export class JournalMarkdownView extends React.Component {
|
|||
appStore.dispatch(fetchArticle(pageToLoad));
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
this.setState({displayContent: nextProps.article, originalContent: nextProps.article});
|
||||
this.updateEditAllowance(nextProps.userCanEdit)
|
||||
}
|
||||
|
||||
handleUpdateCode(newCode) {
|
||||
this.setState({displayContent: newCode});
|
||||
}
|
||||
|
@ -89,11 +100,8 @@ export class JournalMarkdownView extends React.Component {
|
|||
appStore.dispatch(saveArticle(pageContent));
|
||||
}
|
||||
|
||||
updateEditAllowance() {
|
||||
// let allowEdits = JournalEntryStore.canEditPage();
|
||||
let allowEdits = false;
|
||||
updateEditAllowance(allowEdits) {
|
||||
let editorState = this.state.editorPaneState;
|
||||
|
||||
if (!allowEdits) {
|
||||
editorState = EditorPaneState.hidden;
|
||||
}
|
||||
|
@ -148,6 +156,7 @@ export const ConnectedArticle = connect(
|
|||
'id': state.page.id,
|
||||
'article': state.page.content,
|
||||
'title': state.page.title,
|
||||
'editorTheme': state.editor.theme
|
||||
'editorTheme': state.editor.theme,
|
||||
'userCanEdit': state.user.token !== ""
|
||||
};
|
||||
})(JournalMarkdownView);
|
||||
|
|
|
@ -42,6 +42,17 @@ export class UserLoginView extends React.Component {
|
|||
this.handlePasswordUpdate = this.handlePasswordUpdate.bind(this);
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
// TODO: Fix the transitions up, maybe have the login state as part of the app itself.
|
||||
if (nextProps.externalError !== "") {
|
||||
this.updateErrorMessage(nextProps.externalError);
|
||||
}
|
||||
|
||||
if (nextProps.isUserLoggedIn === true) {
|
||||
this.handleHideLoginModal();
|
||||
}
|
||||
}
|
||||
|
||||
handleLoginAttempt() {
|
||||
if (this.state.username === "" || this.state.password === "") {
|
||||
this.updateErrorMessage("Enter a username and password to login in...");
|
||||
|
@ -80,20 +91,11 @@ export class UserLoginView extends React.Component {
|
|||
let loginIcon = loggedIn ? (<FontAwesome name="sign-in"/>) : (<FontAwesome name="sign-out"/>);
|
||||
let loginOperation = loggedIn ? this.handleLogoutUser : this.handleShowLoginModal;
|
||||
|
||||
// TODO: Fix the transitions up, maybe have the login state as part of the app itself.
|
||||
// if (this.props.externalError !== "") {
|
||||
// this.updateErrorMessage(this.props.externalError);
|
||||
// }
|
||||
|
||||
let errorDisplay = "";
|
||||
if (this.state.errorMessage !== undefined && this.state.errorMessage !== "") {
|
||||
errorDisplay = (<Alert bsStyle="danger">{ this.state.errorMessage }</Alert>);
|
||||
}
|
||||
|
||||
// if (loggedIn === true) {
|
||||
// this.handleHideLoginModal();
|
||||
// }
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="text-center muted hoverable" onClick={ loginOperation }>
|
||||
|
|
Loading…
Reference in New Issue