Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(settings): add clearLocalStorage action #1406

Merged
merged 1 commit into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions components/views/settings/pages/storage/Storage.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
<InteractablesButton
type="danger"
size="small"
:loading='isLoading'
:text="$t('pages.settings.storage.clear.button')"
:action="clearLocalStorage"
/>
</div>
</div>
Expand Down
20 changes: 20 additions & 0 deletions components/views/settings/pages/storage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,25 @@ import Vue from 'vue'
export default Vue.extend({
name: 'StorageSettings',
layout: 'settings',
data() {
return {
isLoading: false,
}
},
methods: {
async clearLocalStorage() {
this.isLoading = true
try {
await this.$store.dispatch('settings/clearLocalStorage')
this.$toast.success(
this.$t('pages.settings.storage.clear.message') as string,
)
} catch (e: any) {
this.$toast.error(this.$t(e.message) as string)
} finally {
this.isLoading = false
}
},
},
})
</script>
4 changes: 4 additions & 0 deletions locales/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ export default {
subtitle:
'Reset Satellite. This will clear any saved accounts. Do not do this without backing up your account first.',
button: 'Clear Local Storage',
message: 'Local storage cleared successfully',
},
export: {
title: 'Export Storage',
Expand Down Expand Up @@ -473,6 +474,9 @@ export default {
mailbox_manager_not_found: 'Mailbox manager not found',
mailbox_manager_not_initialized: 'Mailbox manager not initialized',
},
storage: {
database_not_cleared: 'Could not clear database',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would trigger this error btw? I tried clear storage and then clear storage again but always shows ''Local storage cleared successfully''

},
},
search: {
search: 'Search... ',
Expand Down
13 changes: 13 additions & 0 deletions store/settings/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { db } from '~/plugins/thirdparty/dexie'
import { SettingsError } from '~/store/settings/types'

export default {
async clearLocalStorage() {
try {
await db.delete()
await localStorage.removeItem('Satellite-Store')
} catch (e) {
throw new Error(SettingsError.DATABASE_NOT_CLEARED)
}
},
}
5 changes: 5 additions & 0 deletions store/settings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export enum CaptureMouseTypes {
motion = 'motion',
never = 'never',
}

export enum SettingsError {
DATABASE_NOT_CLEARED = 'errors.storage.database_not_cleared',
}

export interface SettingsState {
audioInput: string
audioOutput: string
Expand Down