forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add hikes/map pulls hikes out of db and renders
- Loading branch information
Berkeley Martinez
authored and
Berkeley Martinez
committed
Jul 23, 2015
1 parent
8f738fb
commit de1d931
Showing
13 changed files
with
161 additions
and
54 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Cat } from 'thundercats'; | ||
import { HikesActions, HikesStore } from './routes/Hikes/flux'; | ||
|
||
|
||
export default Cat() | ||
.init(({ instance }) => { | ||
instance.register(HikesActions); | ||
instance.register(HikesStore, null, instance); | ||
}); |
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,33 +1,46 @@ | ||
import React from 'react'; | ||
import React, { PropTypes } from 'react'; | ||
import stampit from 'react-stampit'; | ||
import { Link } from 'react-router'; | ||
import { contain } from 'thundercats-react'; | ||
import { ListGroup, ListGroupItem, Panel } from 'react-bootstrap'; | ||
import videos from '../videos.json'; | ||
|
||
export default stampit(React, { | ||
displayName: 'HikesMap', | ||
export default contain( | ||
{ | ||
store: 'hikesStore', | ||
fetchAction: 'hikesActions.fetchHikes' | ||
}, | ||
stampit(React, { | ||
displayName: 'HikesMap', | ||
|
||
render() { | ||
propTypes: { | ||
hikes: PropTypes.array | ||
}, | ||
|
||
render() { | ||
const { | ||
hikes | ||
} = this.props; | ||
|
||
const vidElements = hikes.map(({ name, id }) => { | ||
return ( | ||
<ListGroupItem key={ id }> | ||
<Link to={ `/hikes/${id}` }> | ||
<h3>{ name }</h3> | ||
</Link> | ||
</ListGroupItem> | ||
); | ||
}); | ||
|
||
const vidElements = videos.map(({ title, id }) => { | ||
return ( | ||
<ListGroupItem key={ id }> | ||
<Link to={ `/hikes/${id}` }> | ||
<h3>{ title }</h3> | ||
</Link> | ||
</ListGroupItem> | ||
<div> | ||
<Panel> | ||
<h2>Welcome To Hikes!</h2> | ||
</Panel> | ||
<ListGroup> | ||
{ vidElements } | ||
</ListGroup> | ||
</div> | ||
); | ||
}); | ||
|
||
return ( | ||
<div> | ||
<Panel> | ||
<h2>Welcome To Hikes!</h2> | ||
</Panel> | ||
<ListGroup> | ||
{ vidElements } | ||
</ListGroup> | ||
</div> | ||
); | ||
} | ||
}); | ||
} | ||
}) | ||
); |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Actions } from 'thundercats'; | ||
import debugFactory from 'debug'; | ||
import Fetchr from 'fetchr'; | ||
|
||
const debug = debugFactory('freecc:hikes:actions'); | ||
const service = new Fetchr({ | ||
xhrPath: '/services' | ||
}); | ||
|
||
export default Actions({ | ||
// start fetching hikes | ||
fetchHikes: null, | ||
// set hikes on store | ||
setHikes: null, | ||
|
||
getHike(id) { | ||
return { id }; | ||
} | ||
}) | ||
.refs({ displayName: 'HikesActions' }) | ||
.init(({ instance }) => { | ||
// set up hikes fetching | ||
// TODO(berks): check if store is already primed | ||
instance.fetchHikes.subscribe( | ||
() => { | ||
service.read('hikes', null, null, (err, hikes) => { | ||
if (err) { | ||
debug('an error occured fetching hikes', err); | ||
} | ||
instance.setHikes({ hikes }); | ||
}); | ||
} | ||
); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Store } from 'thundercats'; | ||
|
||
const initialValue = { | ||
hikes: [], | ||
isPrimed: false | ||
}; | ||
|
||
export default Store(initialValue) | ||
.refs({ displayName: 'HikesStore'}) | ||
.init(({ instance, args }) => { | ||
const [cat] = args; | ||
let { | ||
setHikes | ||
// getHike | ||
} = cat.getActions('hikesActions'); | ||
instance.register(Store.setter(setHikes)); | ||
|
||
return instance; | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as HikesActions } from './Actions'; | ||
export { default as HikesStore } from './Store'; |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Fetchr from 'fetchr'; | ||
import getHikesService from '../services/hikes'; | ||
|
||
export default function bootServices(app) { | ||
const hikesService = getHikesService(app); | ||
Fetchr.registerFetcher(hikesService); | ||
app.use('/services', Fetchr.middleware()); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export default function hikesService(app) { | ||
const Challenge = app.models.Challenge; | ||
|
||
return { | ||
name: 'hikes', | ||
read: (req, resource, params, config, cb) => { | ||
Challenge.find({ where: { challengeType: '6' } }, (err, hikes) => { | ||
if (err) { | ||
return cb(err); | ||
} | ||
cb(null, hikes); | ||
}); | ||
} | ||
}; | ||
} |