Skip to content

Commit feb3044

Browse files
committed
yolo
1 parent 2205eb3 commit feb3044

30 files changed

+3326
-63
lines changed

gatsby-browser.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import { Provider } from "react-redux";
33
import initStore from "./src/methods/initStore";
44
import { I18nextProvider } from "react-i18next";
55
import i18n from "./src/methods/i18n";
6+
import { AppContextProvider } from "./src/components/AppContext"
67

78
const store = initStore();
89

910
export const wrapRootElement = ({ element }) => (
10-
<Provider store={store}>
11-
<I18nextProvider i18n={i18n}>{element}</I18nextProvider>
12-
</Provider>
11+
<AppContextProvider>
12+
<Provider store={store}>
13+
<I18nextProvider i18n={i18n}>{element}</I18nextProvider>
14+
</Provider>
15+
</AppContextProvider>
1316
);

package-lock.json

+21-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/AppContext.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import React from "react";
2+
3+
// Explainer here: https://www.gatsbyjs.org/blog/2019-01-31-using-react-context-api-with-gatsby/
4+
// See also: ../../gatsby-browser.js
5+
6+
/*
7+
zip: '', // zip code
8+
area: '', // statistical area for CPI calc
9+
town: '', // encorporated town/city for local ordinances
10+
county: '', // county for local ordinances
11+
building_age: null, // building age (proxy for certificate of occupancy)
12+
rental_type: null, // category of rental (e.g. condo, sfh, room, dorm room, hotel, etc)
13+
duplex: null, // in a unit of a duplex
14+
sfh_or_condo: null, // in a condo or single family home (proxy for alienable separable from title)
15+
share_with_landlord: null, // do they share either a sfh/condo with landlord or duplex
16+
share_bathroom_kitchen: null, // do they share a bathroom of kitchen with their landlord
17+
gov_housing: null, // is it gov housing (or subsidized)
18+
dorm: null, // is it a dorm
19+
corp_owned: null, // is it owned by a corp
20+
notice: null, // did they get a notice of excemption
21+
shared_with_landlord_start_of_lease: null, // did they share with the landlord at the start of their lease
22+
*/
23+
24+
const defaultState = {
25+
appCtx: {},
26+
updateContext: () => { },
27+
}
28+
const AppContext = React.createContext(defaultState);
29+
30+
class AppContextProvider extends React.Component {
31+
state = {
32+
appCtx: {}
33+
}
34+
35+
updateContext = (appCtx) => {
36+
this.setState({ appCtx }, () => {
37+
console.log('updated context : ' + appCtx);
38+
});
39+
}
40+
41+
componentDidMount() {
42+
// Getting appstate mode value from localStorage!
43+
const lsAppCtx = JSON.parse(localStorage.getItem("appCtx"))
44+
if (lsAppCtx) {
45+
this.setState({ appCtx: lsAppCtx })
46+
}
47+
}
48+
49+
render() {
50+
const { children } = this.props;
51+
const { appCtx } = this.state;
52+
53+
return (
54+
<AppContext.Provider
55+
value={{
56+
appCtx,
57+
updateContext: this.updateContext,
58+
}}
59+
>
60+
{children}
61+
</AppContext.Provider>
62+
)
63+
64+
}
65+
}
66+
67+
export default AppContext;
68+
export { AppContextProvider };

src/components/Building.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22

3-
const Building = ({ title, description }) => (
4-
<li className="building-card">
3+
const Building = ({ title, description, onClick }) => (
4+
<li className="building-card" onClick={(e)=>{onClick(e)}}>
55
<div></div>
66
<h2>{title}</h2>
77
<p>{description}</p>

src/components/Buildings.js

+36-21
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,60 @@
11
import React from "react";
22
import Building from "./Building";
3+
import AppContext from "./AppContext"
4+
import { navigate } from "@reach/router";
35

46
const buildingTypes = [
57
{
68
title: "Apartment",
79
description:
8-
"Your building has multiple units that are all rented. No one owns their units in this building. "
10+
"The property has multiple (3+) units that are all rented. In apartments buildings all residents will rent from the same owner.",
11+
type: "apartment",
12+
to: "/tom/state/apartments",
913
},
1014
{
1115
title: "Duplex",
12-
description: "Your building has exactly 2 separate units in it. "
16+
description: "The property has exactly 2 separate units in it. The other unit may or may not be rented.",
17+
type: "duplex",
18+
to: "",
1319
},
1420
{
1521
title: "Single Family",
16-
description: "Your building has one living space in it that you rent. "
22+
description: "The property has one living space in it and you rent either all or some of it (such as a bedroom or an 'in-law' apartment).",
23+
type: "sfh",
24+
to: "",
1725
},
1826
{
1927
title: "Condo",
2028
description:
21-
"Your building has multiple units that have been bought by individual owners. Some may be owned, but you rent your unit. "
22-
},
23-
{
24-
title: "Dormitory",
25-
description:
26-
"You are a student living in housing that is owned and managed by a school or university."
27-
},
28-
{
29-
title: "Public Housing",
30-
description:
31-
"You live in housing that is owned or managed by your local goverment. This also include Below Market Rate (BMR) housing."
29+
"The property has multiple (3+) units that have been bought by individual owners. In a condo residents will either own their apartments or rent from different landlords.",
30+
type: "condo",
31+
to: "",
3232
}
3333
];
3434

35-
const Buildings = () => {
36-
const listItems = buildingTypes.map(type => {
35+
const onClick = (appCtx, updateContext, type, to) => {
36+
appCtx.buildingType = type;
37+
updateContext(appCtx);
38+
39+
navigate(to);
40+
}
41+
42+
const Buildings = (buildings) => {
43+
if (Object.keys(buildings).length === 0) {
44+
buildings = buildingTypes;
45+
}
46+
const listItems = buildings.map(building => {
3747
return (
38-
<Building
39-
key={type.title}
40-
title={type.title}
41-
description={type.description}
42-
></Building>
48+
<AppContext.Consumer>
49+
{({ appCtx, updateContext }) => (
50+
<Building
51+
key={building.title}
52+
title={building.title}
53+
description={building.description}
54+
onClick={(e)=>{onClick(appCtx, updateContext, building.type, building.to)}}
55+
></Building>
56+
)}
57+
</AppContext.Consumer>
4358
);
4459
});
4560
return <ul className="buildings-list">{listItems}</ul>;

src/components/Buttons.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const SecondaryButton = ({ to, children }) => {
2222
);
2323
};
2424

25-
export const PrimaryButton = ({ to, children }) => {
25+
export const PrimaryButton = ({ to, children}) => {
2626
return (
2727
<StyledPrimaryButton onClick={() => navigate(to)} type="button">
2828
{children}

0 commit comments

Comments
 (0)