Skip to content

Commit

Permalink
feat: added clear data function
Browse files Browse the repository at this point in the history
  • Loading branch information
juzraai committed Mar 28, 2021
1 parent e770303 commit 958a49a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/components/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
View profile
</b-dd-item>
<b-dd-divider></b-dd-divider>
<b-dd-item-button variant="danger">
<b-dd-item-button
variant="danger"
@click="clearDataWithConfirm"
>
<i class="fas fa-trash-alt fa-fw mr-2"></i>
Clear data
</b-dd-item-button>
Expand All @@ -56,7 +59,7 @@
<script>
// TODO fix dropdown menu (Bootstrap-Vue)
// TODO implement dropdown features
import { mapState } from "vuex";
import { mapActions, mapState } from "vuex";
import { formatTimestamp } from "@/util.js";
export default {
Expand All @@ -69,6 +72,14 @@ export default {
...mapState(["apiKey", "names", "playerId"]),
},
methods: {
...mapActions(["clearData"]),
clearDataWithConfirm() {
if (
confirm("Are you sure you want to clear your TLL data in this browser?")
) {
this.clearData();
}
},
getTctTime() {
return formatTimestamp(new Date().getTime() / 1000);
},
Expand Down
6 changes: 5 additions & 1 deletion src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const store = new Vuex.Store({
},
mutations: {
init(state) {
if (localStorage.getItem('store')) {
if (localStorage.getItem(LOCAL_STORAGE_KEY)) {
const obj = loadFromStorage()
const newState = Object.assign(state, obj)
this.replaceState(newState)
Expand Down Expand Up @@ -136,6 +136,10 @@ const store = new Vuex.Store({
}
},
actions: {
clearData() {
localStorage.removeItem(LOCAL_STORAGE_KEY)
window.location.reload()
},
async login(context, apiKey) {
context.commit('setLoading', true)
context.commit('setApiKey', apiKey)
Expand Down

0 comments on commit 958a49a

Please sign in to comment.