GreenInfo-Network/caliparks.org

Wander function not working

gregallensworth opened this issue · 6 comments

The Wander link is not working.

Seems the API is trying to find a random park which had a photo within the last month:

return dataStore.db('randomPark', {interval:'month-now'}).then((park) => {

See what could be done to remove the "last month" filter, and return a random park? Performance shouldn't be bad.

Though Sean follows up, that perhaps it's not using that interval but a hardcoded one:

https://github.com/GreenInfo-Network/caliparks.org/blob/parksforward-redesign/app/server/services/queries/parks.js#L244

Then follows up, that one needs to change these lines:

https://github.com/GreenInfo-Network/caliparks.org/blob/parksforward-redesign/app/server/services/queries/parks.js#L260-L262

I probably meant to use the interval option but never got around to implementing it, sorry :-(

The "wander" button on the home page actually routes to "/wander" then redirects to parks page.

app.get('/wander', (req, res, next) => {
return dataStore.db('randomPark', {interval:'month-now'}).then((park) => {
const parkid = park[0].su_id;
res.set('Cache-Control', 'private, max-age=0, no-cache');
return res.redirect('/park/' + parkid);
}).catch((err) => {
return next(err);
});
});

Currently it's not even hitting the express route as it's missing a route in routes.jsx:

<Router>
<Route path='/' component={Layout} onUpdate={() => window.scrollTo(0, 0)}>
<IndexRoute component={AppContainer} />
<Route path='discover' component={NotFound} />
<Route path='explore' component={NotFound} />
<Route path='park/:id' component={ParkContainer} />
<Route path='activity/:activity' component={ActivityContainer} />
<Route path='faq' component={FaqContainer} />
<Redirect from='parks/:id' to='/park/:id' />
<Redirect from='parks' to='/' />
<Route path='*' component={NotFound} />
</Route>
</Router>

Actually I see it doesn't need a route, as the Nav component creates the link. Slightly confusing that routes for /discover and /explore point to the 404 page and that /wander was missing from Routes.jsx. The first two should probably redirect to the home page as /#discover and /#explore, although when you refresh the page with either of those in URL it doesn't scroll to the correct section, but that's another issue.

Fixed the SQL query by removing the WHERE clause on the SELECT * FROM instagram_photos and tacking on a LIMIT 500 as to not grab millions of photos. There's probably a better way to make the query return rows that are more randomized.

I just tried this on live site and I'm still getting 404 when I click on or load http://www.caliparks.org/wander

Does this fix still need to be deployed?