Rewrite player component to script setup

This commit is contained in:
wvffle 2022-07-03 18:12:09 +00:00 committed by Georg Krause
commit cec34d49fa
15 changed files with 678 additions and 680 deletions

View file

@ -1,6 +1,14 @@
import { InitModule } from '~/types'
import {
InitModule,
ListenWSEvent,
PendingReviewEditsWSEvent,
PendingReviewReportsWSEvent,
PendingReviewRequestsWSEvent,
} from '~/types'
import { watchEffect, watch } from 'vue'
import { useWebSocket, whenever } from '@vueuse/core'
import useWebSocketHandler from '~/composables/useWebSocketHandler'
import { CLIENT_RADIOS } from '~/utils/clientRadios'
export const install: InitModule = ({ store }) => {
watch(() => store.state.instance.instanceUrl, () => {
@ -25,4 +33,47 @@ export const install: InitModule = ({ store }) => {
console.log('Websocket status:', status.value)
})
}, { immediate: true })
// WebSocket handlers
useWebSocketHandler('inbox.item_added', () => {
store.commit('ui/incrementNotifications', { type: 'inbox', count: 1 })
})
useWebSocketHandler('mutation.created', (event) => {
store.commit('ui/incrementNotifications', {
type: 'pendingReviewEdits',
value: (event as PendingReviewEditsWSEvent).pending_review_count
})
})
useWebSocketHandler('mutation.updated', (event) => {
store.commit('ui/incrementNotifications', {
type: 'pendingReviewEdits',
value: (event as PendingReviewEditsWSEvent).pending_review_count
})
})
useWebSocketHandler('report.created', (event) => {
store.commit('ui/incrementNotifications', {
type: 'pendingReviewReports',
value: (event as PendingReviewReportsWSEvent).unresolved_count
})
})
useWebSocketHandler('user_request.created', (event) => {
store.commit('ui/incrementNotifications', {
type: 'pendingReviewRequests',
value: (event as PendingReviewRequestsWSEvent).pending_count
})
})
useWebSocketHandler('Listen', (event) => {
if (store.state.radios.current && store.state.radios.running) {
const { current } = store.state.radios
if (current.clientOnly) {
CLIENT_RADIOS[current.type].handleListen(current, event as ListenWSEvent, store)
}
}
})
}