-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert AddressPage.js to TSX. #346
Merged
Merged
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
769a73b
Convert part of AddressPage.js to TSX.
toolness 3452339
Add typings for props.
toolness 6eee2fe
Blargh
toolness 23a2513
Define assocAddrs.
toolness 83645bb
Add typing for geosearch.
toolness 591f26e
Run prettier.
toolness 0fc33cd
Merge branch 'master' into addresspage-partial-tsx
d42847a
fixed missing typings (WIP)
b8186ac
Updated handleResults to work with non-registered cases
6566776
prettier
e336332
made detail address potentially null in components
ccfb7d5
prettier
7b7c763
Merge branch 'master' into addresspage-partial-tsx
e227f0d
fixed issue with detailAddr not allwed to be null
f023015
simplified render logic
86ea774
updated comment
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,64 @@ | ||
import React, { Component } from "react"; | ||
import FileSaver from "file-saver"; | ||
import Browser from "util/browser"; | ||
import Browser from "../util/browser"; | ||
|
||
import _find from "lodash/find"; | ||
|
||
import AddressToolbar from "components/AddressToolbar"; | ||
import PropertiesMap from "components/PropertiesMap"; | ||
import PropertiesList from "components/PropertiesList"; | ||
import PropertiesSummary from "components/PropertiesSummary"; | ||
import Indicators from "components/Indicators"; | ||
import DetailView from "components/DetailView"; | ||
import APIClient from "components/APIClient"; | ||
import Loader from "components/Loader"; | ||
import AddressToolbar from "../components/AddressToolbar"; | ||
import PropertiesMap from "../components/PropertiesMap"; | ||
import PropertiesList from "../components/PropertiesList"; | ||
import PropertiesSummary from "../components/PropertiesSummary"; | ||
import Indicators from "../components/Indicators"; | ||
import DetailView from "../components/DetailView"; | ||
import APIClient from "../components/APIClient"; | ||
import Loader from "../components/Loader"; | ||
|
||
import "styles/AddressPage.css"; | ||
import NychaPage from "./NychaPage"; | ||
import NotRegisteredPage from "./NotRegisteredPage"; | ||
import helpers from "../util/helpers"; | ||
import { Trans, Plural } from "@lingui/macro"; | ||
import { Link } from "react-router-dom"; | ||
import { Link, RouteComponentProps } from "react-router-dom"; | ||
import Page from "../components/Page"; | ||
import { SearchResults, AddressRecord, GeoSearchData } from "../components/APIDataTypes"; | ||
|
||
export default class AddressPage extends Component { | ||
constructor(props) { | ||
type RouteParams = { | ||
locale?: string; | ||
boro?: string; | ||
housenumber?: string; | ||
streetname?: string; | ||
}; | ||
|
||
type RouteState = { | ||
// TODO: Fix this typing. | ||
results?: any; | ||
}; | ||
|
||
type AddressPageProps = RouteComponentProps<RouteParams, {}, RouteState> & { | ||
currentTab: number; | ||
}; | ||
|
||
type State = { | ||
hasSearched: boolean; | ||
detailMobileSlide: boolean; | ||
assocAddrs: AddressRecord[]; | ||
geosearch?: GeoSearchData; | ||
|
||
// TODO: Fix these typings. | ||
searchAddress: any; | ||
userAddr: any; | ||
detailAddr: any; | ||
}; | ||
|
||
export default class AddressPage extends Component<AddressPageProps, State> { | ||
constructor(props: AddressPageProps) { | ||
super(props); | ||
|
||
this.state = { | ||
searchAddress: { ...props.match.params }, // maybe this should be | ||
userAddr: {}, // merged together? | ||
hasSearched: false, | ||
geosearch: {}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit queasy about this change but hopefully it should work. We should probably kick the tires a bit just to make sure nothing explodes... |
||
geosearch: undefined, | ||
assocAddrs: [], | ||
detailAddr: null, | ||
detailMobileSlide: false, | ||
|
@@ -61,9 +90,13 @@ export default class AddressPage extends Component { | |
} | ||
|
||
// Processes the results and setState accordingly. Doesn't care where results comes from | ||
handleResults = (results) => { | ||
handleResults = (results: SearchResults) => { | ||
const { geosearch, addrs } = results; | ||
|
||
if (!geosearch) { | ||
throw new Error("Address results do not contain geosearch results!"); | ||
} | ||
|
||
this.setState( | ||
{ | ||
searchAddress: { ...this.state.searchAddress, bbl: geosearch.bbl }, | ||
|
@@ -78,7 +111,8 @@ export default class AddressPage extends Component { | |
); | ||
}; | ||
|
||
handleAddrChange = (addr) => { | ||
// TODO: Fix this typing. | ||
handleAddrChange = (addr: any) => { | ||
this.setState({ | ||
detailAddr: addr, | ||
detailMobileSlide: true, | ||
|
@@ -108,16 +142,15 @@ export default class AddressPage extends Component { | |
|
||
render() { | ||
if (this.state.hasSearched && this.state.assocAddrs.length === 0) { | ||
return this.state.searchAddress && | ||
this.state.searchAddress.bbl && | ||
helpers.getNychaData(this.state.searchAddress.bbl) ? ( | ||
const nychaData = helpers.getNychaData(this.state.searchAddress.bbl); | ||
return this.state.searchAddress && this.state.searchAddress.bbl && nychaData ? ( | ||
<Page | ||
title={`${this.state.searchAddress.housenumber} ${this.state.searchAddress.streetname}`} | ||
> | ||
<NychaPage | ||
geosearch={this.state.geosearch} | ||
searchAddress={this.state.searchAddress} | ||
nychaData={helpers.getNychaData(this.state.searchAddress.bbl)} | ||
nychaData={nychaData} | ||
/> | ||
</Page> | ||
) : ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, at least we're getting rid of this duplicate typing.