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