Move ~/modules to ~/init

This commit is contained in:
Kasper Seweryn 2022-04-23 14:10:36 +02:00 committed by Georg Krause
commit 071eb2fa35
21 changed files with 10 additions and 10 deletions

View file

@ -0,0 +1,28 @@
import { AppModule } from '~/types'
import { watchEffect, watch } from '@vue/composition-api'
import { useWebSocket, whenever } from '@vueuse/core'
export const install: AppModule = ({ store }) => {
watch(() => store.state.instance.instanceUrl, () => {
const url = store.getters['instance/absoluteUrl']('api/v1/activity')
.replace(/^http/, 'ws')
const { data, status, open, close } = useWebSocket(url, {
autoReconnect: true,
immediate: false
})
watch(() => store.state.auth.authenticated, (authenticated) => {
if (authenticated) return open()
close()
})
whenever(data, () => {
return store.dispatch('ui/websocketEvent', JSON.parse(data.value))
})
watchEffect(() => {
console.log('Websocket status:', status.value)
})
})
}