Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
Save filters and sorters to profile
Browse files Browse the repository at this point in the history
Closes #3
  • Loading branch information
SavageCore committed Jul 19, 2024
1 parent 1cc427e commit ba311c2
Showing 1 changed file with 53 additions and 21 deletions.
74 changes: 53 additions & 21 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,21 @@ const addProfiles = (submenu: HTMLUListElement) => {

profileNameSpan.addEventListener('click', event => {
event.preventDefault();
localStorage.setItem(currentProfileKey, profileName);

// Load quest data
const profile = profiles[profileName];
localStorage.setItem('questData', JSON.stringify(profile.questData));

// Reload page
location.reload();
try {
const profile = profiles[profileName];

localStorage.setItem(currentProfileKey, profileName);
localStorage.setItem('questData', JSON.stringify(profile.questData));
localStorage.setItem('filteredInfo', JSON.stringify(profile.filteredInfo || {}));
localStorage.setItem('questPagination', JSON.stringify(profile.questPagination || {}));
localStorage.setItem('showAvailableOnly', JSON.stringify(profile.showAvailableOnly || false));
localStorage.setItem('sortedInfo', JSON.stringify(profile.sortedInfo || {}));

// Reload page
location.reload();
} catch (error) {
console.error('Error setting profile data:', error);
}
});

// Add delete icon
Expand Down Expand Up @@ -425,21 +432,46 @@ const trackPage = () => {

const trackQuestData = () => {
const localStoreHandler = function (event: any) {
if (event.key === 'questData') {
// Update current profile's quest data
const currentProfile = localStorage.getItem(currentProfileKey);
if (!currentProfile) {
return;
}
// Handle local storage updates
const currentProfile = localStorage.getItem(currentProfileKey);
if (!currentProfile) {
return;
}

const profiles = JSON.parse(localStorage.getItem(profilesKey) || '{}');
const profile = profiles[currentProfile];
if (!profile) {
return;
}
const profiles = JSON.parse(localStorage.getItem(profilesKey) || '{}');
const profile = profiles[currentProfile];
if (!profile) {
return;
}

profile.questData = JSON.parse(event.value);
localStorage.setItem(profilesKey, JSON.stringify(profiles));
switch (event.key) {
case 'questData':
// Update current profile's quest data
profile.questData = JSON.parse(event.value);
localStorage.setItem(profilesKey, JSON.stringify(profiles));
break;
case 'questPagination':
// Update current profile's quest pagination
profile.questPagination = JSON.parse(event.value);
localStorage.setItem(profilesKey, JSON.stringify(profiles));
break;
case 'filteredInfo':
// Update current profile's quest filters
profile.filteredInfo = JSON.parse(event.value);
localStorage.setItem(profilesKey, JSON.stringify(profiles));
break;
case 'sortedInfo':
// Update current profile's quest sorting
profile.sortedInfo = JSON.parse(event.value);
localStorage.setItem(profilesKey, JSON.stringify(profiles));
break;
case 'showAvailableOnly':
// Update current profile's show available only setting
profile.showAvailableOnly = JSON.parse(event.value);
localStorage.setItem(profilesKey, JSON.stringify(profiles));
break;
default:
break;
}
};

Expand Down

0 comments on commit ba311c2

Please sign in to comment.