Skip to content

Commit

Permalink
fix: Show error when deleting empty session list
Browse files Browse the repository at this point in the history
  • Loading branch information
navorite committed Nov 14, 2023
1 parent 564ee1f commit e30abaf
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/lib/stores/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const sessions = (() => {
}

async function remove(target: ESession) {
if (!target)
if (!target || !target.id || target.id === 'current')
return notification.error(
i18n.getMessage('notifyDeleteFailUndefined'),
'[sessions.remove] error: removing undefined session'
Expand All @@ -139,24 +139,33 @@ export const sessions = (() => {
update((sessions) => {
const index = sessions.indexOf(target);

if (index !== -1) sessions.splice(index, 1);
if (index === -1) {
notification.error(
i18n.getMessage('notifyDeleteFailUndefined'),
'[sessions.remove] error: removing undefined session'
);

return sessions;
}

sessionsDB.deleteSession(target);

sessions.splice(index, 1);

notify(sessions);

notification.success_warning(i18n.getMessage('notifyDeleteSuccess'));

return sessions;
});

await sessionsDB.deleteSession(target);

notification.success_warning(i18n.getMessage('notifyDeleteSuccess'));
}

async function removeAll() {
const length = get({ subscribe }).length;

if (!length) {
notification.error(
i18n.getMessage('notifyDeleteAllFailEmpty'),
i18n.getMessage('notifyDeleteAllFailUndefined'),
'[sessions.removeAll] sessions are already empty'
);
return;
Expand Down

0 comments on commit e30abaf

Please sign in to comment.