Skip to content

Commit

Permalink
add default offer selection
Browse files Browse the repository at this point in the history
  • Loading branch information
sammdu committed Dec 9, 2021
1 parent 01f0afe commit cf10336
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 36 deletions.
37 changes: 6 additions & 31 deletions js/details.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ async function onPageLoad() {
// fetch the user_id from the URL
let userID = fetchQueryParamByKey('user_id');
// fetch all claimed offers for this user
await fetchClaimedOffers(userID);
const firstOfferID = await fetchClaimedOffers(userID);

// find the selected offer for this user
let offerSelected = fetchQueryParamByKey('offerSelected');
// select the first offer if none are specified
if (offerSelected === null || offerSelected === '') {
offerSelected = firstOfferID;
setPairInQuery('offerSelected', offerSelected);
}
// show details for the specified offer
await getOfferDetails(userID, offerSelected);
}
Expand All @@ -34,36 +39,6 @@ async function onPageLoad() {
Claimed offers list operations
*/

/*
Get the list of offers for a specific user
*/
async function fetchClaimedOffers(userID) {
try {
// call the API to get the user's claimed offers
const userClaimedOffers = await api.getClaimedOffers(userID);

// populate the sidebar with user's claimed offers
displayClaimedOffers(userClaimedOffers, userID);
}
catch (e) {
console.log(e);
console.log(window.location.search);
}
}

/*
Display the given list of claimed offers
*/
function displayClaimedOffers(offers, userID) {
removeAllLoanOffers();
for (const offer of offers) {
addOfferToContainer(
userID, offer['offerId'], offer['brand'], offer['model'], offer['year'],
offer['interestRate'], offer['termMo'], offer['totalSum']
);
}
}

/*
Highlight an offer (purely cosmetically)
*/
Expand Down
5 changes: 0 additions & 5 deletions js/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ async function onPageLoad() {
else {
userLogin();
}

// DEMO
addOfferToContainer(
"u1639018896514634", "offer123", "Honda", "Civic", 2018, 250, 320, 3.2
);
}


Expand Down
33 changes: 33 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,39 @@ function setPairInQuery(key, value) {
Claimed offers list operations
*/

/*
Get the list of offers for a specific user
*/
async function fetchClaimedOffers(userID) {
try {
// call the API to get the user's claimed offers
const userClaimedOffers = await api.getClaimedOffers(userID);

// populate the sidebar with user's claimed offers
displayClaimedOffers(userClaimedOffers, userID);

// return the first offer ID as selection default
return userClaimedOffers[0]['offerId'];
}
catch (e) {
console.log(e);
console.log(window.location.search);
}
}

/*
Display the given list of claimed offers
*/
function displayClaimedOffers(offers, userID) {
removeAllLoanOffers();
for (const offer of offers) {
addOfferToContainer(
userID, offer['offerId'], offer['brand'], offer['model'], offer['year'],
offer['interestRate'], offer['termMo'], offer['totalSum']
);
}
}

/*
Add a loan offer to the loan offers container
*/
Expand Down

0 comments on commit cf10336

Please sign in to comment.