Skip to content

Commit

Permalink
Fix #352. (#353)
Browse files Browse the repository at this point in the history
This fixes #352. The bug was indeed introduced by #346, which essentially split what was previously a single state update into two separate ones: this then caused render() to be called in a state where the <NotRegisteredPage> was mounted and immediately unmounted.
  • Loading branch information
toolness authored Jul 29, 2020
1 parent cb1b74d commit 155d48a
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions client/src/containers/AddressPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,38 +105,36 @@ export default class AddressPage extends Component<AddressPageProps, State> {
// Processes the results and setState accordingly. Doesn't care where results comes from
handleResults = (results: SearchResults) => {
const { geosearch, addrs } = results;
let userAddr: AddressRecord | undefined = undefined;

if (!geosearch) {
throw new Error("Address results do not contain geosearch results!");
}

this.setState({
hasSearched: true,
geosearch: geosearch,
searchAddress: { ...this.state.searchAddress, bbl: geosearch.bbl },
});

/* Case for when our API call returns a portfolio of multiple associated addresses */
if (addrs.length) {
const userAddr = _find(addrs, { bbl: geosearch.bbl });
userAddr = _find(addrs, { bbl: geosearch.bbl });

if (!userAddr) {
throw new Error("The user's address was not found in the API Address Search results!");
}

this.setState(
{
userAddr: userAddr,
assocAddrs: addrs,
},
() => {
this.handleAddrChange(userAddr);
}
);
}

this.setState(
{
hasSearched: true,
geosearch: geosearch,
userAddr,
assocAddrs: addrs,
searchAddress: { ...this.state.searchAddress, bbl: geosearch.bbl },
},
() => {
this.handleAddrChange(userAddr);
}
);
};

handleAddrChange = (addr: AddressRecord) => {
handleAddrChange = (addr?: AddressRecord) => {
this.setState({
detailAddr: addr,
detailMobileSlide: true,
Expand Down

0 comments on commit 155d48a

Please sign in to comment.