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,15 +30,17 @@ export class LinkDetail extends Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
// if we have no preloaded data, and we aren't expecting it, get it
|
||||
if (!this.state.data.title) {
|
||||
this.props.api.getSubmission(
|
||||
this.props.resourcePath, this.props.url, this.updateData.bind(this)
|
||||
);
|
||||
}
|
||||
this.componentDidUpdate();
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
// if we have no preloaded data, and we aren't expecting it, get it
|
||||
if ((!this.state.data.title) && (this.props.api)) {
|
||||
this.props.api?.getSubmission(
|
||||
this.props.resourcePath, this.props.url, this.updateData.bind(this)
|
||||
);
|
||||
}
|
||||
if (prevProps) {
|
||||
if (this.props.url !== prevProps.url) {
|
||||
this.updateData(this.props.data);
|
||||
}
|
||||
@ -58,6 +60,7 @@ export class LinkDetail extends Component {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onClickPost() {
|
||||
const url = this.props.url || '';
|
||||
|
@ -26,14 +26,16 @@ export class Links extends Component {
|
||||
// and don't have links for it yet,
|
||||
// or the links we have might not be complete,
|
||||
// request the links for that page.
|
||||
if ( (!prevProps ||
|
||||
linkPage !== prevProps.page ||
|
||||
this.props.resourcePath !== prevProps.resourcePath
|
||||
) &&
|
||||
!this.props.links[linkPage] ||
|
||||
this.props.links.local[linkPage]
|
||||
if ( ((!prevProps || // first load?
|
||||
linkPage !== prevProps.page || // already waiting on response?
|
||||
this.props.resourcePath !== prevProps.resourcePath // new page?
|
||||
) ||
|
||||
(prevProps.api !== this.props.api)) // api prop instantiated?
|
||||
&&
|
||||
!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