mirror of
https://github.com/urbit/shrub.git
synced 2024-12-02 21:34:04 +03:00
improve validation
This commit is contained in:
parent
e3af0bcde9
commit
5912ba0c0c
@ -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('/');
|
||||||
|
Loading…
Reference in New Issue
Block a user