A coding challenge to display a stream of home listings using the SimplyRETS API, React, Firebase, and localStorage.
git clone https://github.com/asapzacy/home-stream.git && cd home-stream
yarn && yarn start
then --> localhost:3000
This is what happens on initial page load.
-
<AppContainer />
checkslocalStorage
for auserId
property, if it doesn't find one, it creates a 9-digit random integer, and has 1 state property—userId
(integer)
-
<AppContainer />
passes along its' state to<StreamContainer />
who uses the axios promise-based HTTP package to fetch the simpleRETS API listings.<StreamContainer />
has 3 state properties—-
listings
(array) -
isLoading
(boolean) -
isError
(boolean)
-
-
isLoading
state is initially set totrue
and renders<Loading />
component. -
Once axios returns a promise,
isLoading
is set tofalse
. If the promise is successful,listings
array is filled with data, if not,isError
is set totrue
and will render<Error />
component. -
<StreamContainer />
passeslistings
array to<Stream />
presentational component, who maps over the array and returns a<HomeListing />
functional container for each listing. -
<HomeContainer />
is the final stateful container in this project. It is comprised of 2 state properties—-
isSaved
(boolean) -
photo
(integer)
-
-
The
photo
state will pick a random number0
or1
and use that number for the listing image (simpleRETS API returns an array of 2 images).<HomeContainer />
will check Firebase (https://home-stream.firebaseio.com) and see if the listing id is saved, will update its' state appropriately. -
The last step in this process is creating a
saveListing()
function in<HomeContainer />
and passing that along to a<Save />
component. The<Save />
is just a simple button that will display a<Save />
or<Check />
Google Material icon depending on its'isSaved
state. -
Finally,
<HomeContainer />
passes along all its' listing information to a<Home />
presentational component who displays the data and makes it look nice.
-
create-react-app - this project was bootstrapped using Facebook's create-react-app
-
axios - promise-based HTTP client
-
firebase - to interact with Google Firebase data
-
react-icons - for grabbing the 2 Google Material Icons
-
velocity-react - used Twitter's React animation library for the simple animation between
isSaved
states -
gh-pages - for very easy deployment to github pages https://zacarellano.github.io/home-stream
This is how the Firebase database is set up.
-
home-stream/
-
users/ - (saved users)
-
11081799/ - (9-digit random integer)
-
homes/ - (saved homes)
-
1005242/ - (mld id integer)
-
address/
-
agent/
-
geo/
-
photos/
-
etc../ - (all the listing information)
-
-
-
-
313120421/
-
257400343/
-
814608816/
-
-