Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 26 additions & 35 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,14 @@
* ...
* ]
*/

function getPersonList() {
return new Promise((resolve, reject) => {
fetch('https://willowtreeapps.com/api/v1.0/profiles')
.then(response => {
if (response.status !== 200) {
reject(new Error("Error!"));
}

response.json().then(imageList => {
resolve(imageList);
});
});
});
return fetch('https://willowtreeapps.com/api/v1.0/profiles')
.then(response => response.json())
.then(imageList => { return imageList })
.catch(error => { return error })
}


/*==================================================

DATA TRANSFORMS
Expand All @@ -128,13 +120,13 @@
return person.lastName;
}

const getFirstName = (person) => {
function getFirstName(person) {
return person.firstName;
};

// headshot URLs are scheme relative //
// prepend http: to prevent invalid schemes like file:// or uri://
const getImageUrl = (person) => {
function getImageUrl(person) {
return `http:${person.headshot.url}`;
};

Expand All @@ -143,15 +135,16 @@
*/
function shuffleList(list) {
// Make a copy & don't mutate the passed in list
let result = list.slice(1);
let tmp, j, i;
let result = list.slice(0);
let len = list.length;

let tmp, j, i = list.length - 1

for (; i > 0; i -= 1) {
for (i = 0; i < len; i++) {
j = Math.floor(Math.random() * (i + 1));
tmp = list[i];
list[i] = list[j];
list[j] = tmp;
tmp = result[i];
result[i] = result[j];
result[j] = tmp;
}

return result;
Expand All @@ -163,7 +156,7 @@
* searching for.
*/
function filterByName(searchForName, personList) {
return personList.filter((person) => {
return personList.filter(function(person) {
return person.firstName === searchForName || person.lastName === searchForName;
});
}
Expand All @@ -188,35 +181,33 @@
function sortObjListByProp(prop) {
return function(objList) {
// Make a copy & don't mutate the passed in list
let result = objList.slice(1);
let result = objList.slice(0);

result.sort((a, b) => {
if (a[prop] < b[prop]) {
return -1;
}

if (a[prop] > b[prop]) {
return 1;
}

return 1;
result.sort(function(a, b) {
if (a[prop] < b[prop]) return -1;
if (a[prop] > b[prop]) return 1;
return 0;
});

return result;
};
}

const sortByFirstName = sortObjListByProp('firstName');
const sortByFirstName = sortObjListByProp('firstName');

const sortByLastName = (personList) => sortByFirstName(personList).reverse();
const sortByLastName = sortObjListByProp('lastName');

const sortDescendingByLastName = function(personList) {
return sortByLastName(personList).reverse();
};

/*==================================================

VIEW (React)

***************************************************/


const Search = (props) => React.DOM.input({
type: 'input',
onChange: props.onChange
Expand Down