mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-12 15:01:38 +03:00
links: wait for api prop instantiation
Now that API is a prop, we can't use it to auto-grab data. We wait for it as a prop before requesting info.
This commit is contained in:
parent
24689f852d
commit
50cb14debd
@ -30,20 +30,22 @@ export class LinkDetail extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
// if we have no preloaded data, and we aren't expecting it, get it
|
this.componentDidUpdate();
|
||||||
if (!this.state.data.title) {
|
|
||||||
this.props.api.getSubmission(
|
|
||||||
this.props.resourcePath, this.props.url, this.updateData.bind(this)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
if (this.props.url !== prevProps.url) {
|
// if we have no preloaded data, and we aren't expecting it, get it
|
||||||
this.updateData(this.props.data);
|
if ((!this.state.data.title) && (this.props.api)) {
|
||||||
|
this.props.api?.getSubmission(
|
||||||
|
this.props.resourcePath, this.props.url, this.updateData.bind(this)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (prevProps.comments && prevProps.comments['0'] &&
|
if (prevProps) {
|
||||||
this.props.comments && this.props.comments['0']) {
|
if (this.props.url !== prevProps.url) {
|
||||||
|
this.updateData(this.props.data);
|
||||||
|
}
|
||||||
|
if (prevProps.comments && prevProps.comments['0'] &&
|
||||||
|
this.props.comments && this.props.comments['0']) {
|
||||||
const prevFirstComment = prevProps.comments['0'][0];
|
const prevFirstComment = prevProps.comments['0'][0];
|
||||||
const thisFirstComment = this.props.comments['0'][0];
|
const thisFirstComment = this.props.comments['0'][0];
|
||||||
if ((prevFirstComment && prevFirstComment.udon) &&
|
if ((prevFirstComment && prevFirstComment.udon) &&
|
||||||
@ -56,6 +58,7 @@ export class LinkDetail extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,14 +26,16 @@ export class Links extends Component {
|
|||||||
// and don't have links for it yet,
|
// and don't have links for it yet,
|
||||||
// or the links we have might not be complete,
|
// or the links we have might not be complete,
|
||||||
// request the links for that page.
|
// request the links for that page.
|
||||||
if ( (!prevProps ||
|
if ( ((!prevProps || // first load?
|
||||||
linkPage !== prevProps.page ||
|
linkPage !== prevProps.page || // already waiting on response?
|
||||||
this.props.resourcePath !== prevProps.resourcePath
|
this.props.resourcePath !== prevProps.resourcePath // new page?
|
||||||
) &&
|
) ||
|
||||||
!this.props.links[linkPage] ||
|
(prevProps.api !== this.props.api)) // api prop instantiated?
|
||||||
this.props.links.local[linkPage]
|
&&
|
||||||
|
!this.props.links[linkPage] || // don't have info?
|
||||||
|
this.props.links.local[linkPage] // waiting on post confirmation?
|
||||||
) {
|
) {
|
||||||
this.props.api.getPage(this.props.resourcePath, this.props.page);
|
this.props.api?.getPage(this.props.resourcePath, this.props.page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user