improve validation

This commit is contained in:
A Arroyo 2020-02-03 17:27:53 -08:00
parent e3af0bcde9
commit 5912ba0c0c

View File

@ -16,24 +16,33 @@ export class JoinScreen extends Component {
this.bookChange = this.bookChange.bind(this); this.bookChange = this.bookChange.bind(this);
} }
componentDidUpdate(prevProps, prevState) { notebooksInclude(text, notebookObj) {
const { props, state } = this; let verdict = false;
if (state.book in props.notebooks) { let keyPair = [];
props.history.push('/~publish'); // validate that it's a worthwhile thing to check
} // certainly a unit would be nice here
} if (text.indexOf('/') === -1) {
return verdict;
} else {
keyPair = text.split('/');
};
// check both levels of object
if (keyPair[0] in notebookObj) {
if (keyPair[1] in notebookObj[keyPair[0]]) {
verdict = true;
}
}
return verdict;
}
onClickJoin() { onClickJoin() {
const { props, state } = this; const { props, state } = this;
let text = state.book; let text = state.book;
// an error condition to prevent double joins? // an error condition to prevent double joins?
if (text in props.notebooks || if (this.notebooksInclude(state.book,props.notebooks) ||
text.length === 0) { text.length === 0) {
this.setState({ props.history.push('/~publish');
error: true,
});
return;
} }
let book = text.split('/'); let book = text.split('/');