Skip to content

Commit

Permalink
Merge pull request #11 from talis/plat-3908-default-region
Browse files Browse the repository at this point in the history
Convert the active tenant in local storage from a string to an object transparently if the user has previously saved their institution
  • Loading branch information
kiyanwang authored Aug 27, 2020
2 parents 5810106 + a2758fa commit c5b20be
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
1 change: 1 addition & 0 deletions js/bookmarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
}

var bookmarker = document.createElement('script');

var bookmarkingEndpoint = (
tenant.region === 'CA' ?
'https://bookmarking.ca.talis.com' :
Expand Down
50 changes: 48 additions & 2 deletions js/tenants.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,60 @@ function getActiveTenant(cb) {
if (tenants.activeTenant) {
storage = chromeOrBrowser().storage.local;
}
return cb(tenants.activeTenant);

convertActiveTenantToObject(tenants.activeTenant, function(updatedTenant){
return cb(updatedTenant);
});
});
} else {
return cb(tenants.activeTenant);
convertActiveTenantToObject(tenants.activeTenant, function(updatedTenant){
return cb(updatedTenant);
});
}
});
}

/**
* Checks to see if the active tenant is stored as a simple
* string, if so converts to an object and overwrites the
* value currently stored in browser storage.
*
* @param {object} tenant
* @param {function()} cb - Callback to run once updated
*/
function convertActiveTenantToObject(activeTenant, cb) {
if (!activeTenant) {
// if the activeTenant is null or undefined then
// simply return null, and let the extension
// force the user to the options pane
return cb(null);
}

if (activeTenant.region) {
// if the activeTenant has a region property
// then, its an object just continue.
return cb(activeTenant);
} else {
// if the active tenant doesn't have a region property
// then it's going to be a simple string. Retrieve the
// complete tenants list and find the tenant object, then
// overwrite active tenant in local storage with the object
// and return it.
getTenants(function(updatedTenantsList) {
var updatedTenant = updatedTenantsList[activeTenant];
if (updatedTenant) {
saveActiveTenant(updatedTenant, function() {
return cb(updatedTenant);
});
} else {
// return null which will
// force the user to the options pane
return cb(null);
}
});
}
}

/**
* Stores the preferred tenant in browser storage
*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "talis-reading-lists-bookmarker",
"version": "0.3.7",
"version": "0.3.8",
"description": "A browser extension to bookmark resources to Talis Aspire Reading Lists",
"devDependencies": {
"grunt": "^1.0.1",
Expand Down

0 comments on commit c5b20be

Please sign in to comment.