Skip to content

Commit

Permalink
fix: using typescript in store directory
Browse files Browse the repository at this point in the history
  • Loading branch information
technikhil314 committed Nov 28, 2021
1 parent 8a7700e commit 3cdd947
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 35 deletions.
35 changes: 0 additions & 35 deletions store/toast.js

This file was deleted.

45 changes: 45 additions & 0 deletions store/toast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { GetterTree, Store, MutationTree } from 'vuex'

export const state = () => ({
show: false,
content: '',
theme: 'info',
iconHTML: '',
autoDismiss: true,
timeout: 5000,
})
let timeoutId: NodeJS.Timeout

export type ToastState = ReturnType<typeof state>

export const getters: GetterTree<ToastState, ToastState> = {
show: (state) => state.show,
content: (state) => state.content,
theme: (state) => state.theme,
iconHTML: (state) => state.iconHTML,
autoDismiss: (state) => state.autoDismiss,
timeout: (state) => state.timeout,
}

export const mutations: MutationTree<ToastState> = {
show(state, { show, content, iconHTML, theme }: ToastState) {
if (!show) {
state.show = show
return
}
const isAlreadyShowing = state.show
state.content = content
state.theme = theme || 'info'
state.iconHTML = iconHTML
state.show = !!content && show
if (isAlreadyShowing && state.show && timeoutId) {
clearTimeout(timeoutId)
}
if (state.show) {
timeoutId = setTimeout(() => {
const store = this as unknown as Store<ToastState>
store.commit('toast/show', { show: false })
}, 5000)
}
},
}

1 comment on commit 3cdd947

@vercel
Copy link

@vercel vercel bot commented on 3cdd947 Nov 28, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.