-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
53 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,44 @@ | ||
import Vue from 'vue'; | ||
import Vuex, {Store} from 'vuex'; | ||
import { defineStore } from 'pinia'; | ||
import RootState from './RootState'; | ||
import { Inertia } from '@inertiajs/inertia'; | ||
import mutations from './mutations'; | ||
|
||
export function getInitialState(): RootState { | ||
return { | ||
loading: false, | ||
lastSearchedIds: '' | ||
} | ||
} | ||
|
||
export function createStore(): Store<RootState>{ | ||
Vue.use(Vuex); | ||
|
||
const store = new Store({ | ||
state: getInitialState(), | ||
mutations | ||
}); | ||
export const useStore = defineStore('storeId', { | ||
state: () : RootState => { | ||
return { | ||
loading: false, | ||
lastSearchedIds: '' | ||
} | ||
}, | ||
actions: { | ||
startLoader () { | ||
this.loading = true; | ||
}, | ||
stopLoader () { | ||
this.loading = false; | ||
}, | ||
saveSearchedIds (searchedIds: string) { | ||
this.lastSearchedIds = searchedIds; | ||
} | ||
}, | ||
|
||
let timer: ReturnType<typeof setTimeout>; | ||
}); | ||
|
||
Inertia.on('start', () => { | ||
// Only instantiate loading state after 250ms. This is done to | ||
// prevent a flash of the loader in case loading is nearly | ||
// immediate, which can be visually distracting. | ||
timer = setTimeout(() => store.commit('startLoader'), 250); | ||
}); | ||
let timer: ReturnType<typeof setTimeout>; | ||
|
||
Inertia.on('finish', (event) => { | ||
clearTimeout(timer); | ||
const status = event.detail.visit; | ||
Inertia.on('start', () => { | ||
// Only instantiate loading state after 250ms. This is done to | ||
// prevent a flash of the loader in case loading is nearly | ||
// immediate, which can be visually distracting. | ||
const store = useStore(); | ||
timer = setTimeout(() => store.startLoader(), 250); | ||
}); | ||
|
||
if (status.completed || status.cancelled) { | ||
store.commit('stopLoader'); | ||
} | ||
}); | ||
Inertia.on('finish', (event) => { | ||
clearTimeout(timer); | ||
const status = event.detail.visit; | ||
|
||
return store; | ||
} | ||
if (status.completed || status.cancelled) { | ||
const store = useStore(); | ||
store.stopLoader(); | ||
} | ||
}); |