return currentHike on load

pull/1319/head^2
Berkeley Martinez 2015-07-18 23:12:38 -07:00
parent b945fc94a4
commit cafd18a5ec
1 changed files with 7 additions and 2 deletions

View File

@ -10,9 +10,14 @@ const service = new Fetchr({
function getCurrentHike(hikes =[{}], dashedName, currentHike) {
if (!dashedName) {
debug('no dashedName');
return hikes[0];
}
const filterRegex = new RegExp(dashedName, 'i');
if (currentHike && filterRegex.test(currentHike.dashedName)) {
return currentHike;
}
return hikes
.filter(({ dashedName }) => {
@ -37,11 +42,11 @@ export default Actions({
if (isPrimed) {
return instance.setHikes({
transform: (oldState) => {
const { hikes, currentContext } = oldState;
const { hikes } = oldState;
const currentHike = getCurrentHike(
hikes,
dashedName,
currentContext
oldState.currentHike
);
return assign({}, oldState, { currentHike });
}