Store last viewed org in local storage for better UX

This commit is contained in:
Rotimi Best
2023-09-13 20:22:15 +01:00
parent 56f979d76e
commit c07c119b5b
6 changed files with 33 additions and 16 deletions
+13 -3
View File
@@ -91,15 +91,25 @@ export async function getOrganizations(userId) {
orgs.set(orgsArray);
const _cOrg = get(currentOrg);
if (!_cOrg.siteName) {
if (localStorage) {
const lastOrgSiteName = localStorage.getItem('classroomio_org_sitename');
const lastOrg = orgsArray.find((org) => org.siteName === lastOrgSiteName);
if (lastOrg) {
currentOrg.set(lastOrg);
}
}
const _currentOrg = get(currentOrg);
if (!_currentOrg.siteName) {
currentOrg.set(orgsArray[0]);
}
}
return {
orgs: orgsArray,
currentOrg: orgsArray[0],
currentOrg: get(currentOrg),
error
};
}