more progress on refactor
This commit is contained in:
@ -1,9 +1,18 @@
|
||||
import { getterTree, mutationTree, actionTree } from 'typed-vuex'
|
||||
import { EVENT } from '~/client/events'
|
||||
import { makeid } from '~/utils'
|
||||
import { EVENT } from '~/neko/events'
|
||||
import { accessor } from '~/store'
|
||||
|
||||
export const namespaced = true
|
||||
|
||||
interface Emote {
|
||||
type: string
|
||||
}
|
||||
|
||||
interface Emotes {
|
||||
[id: string]: Emote
|
||||
}
|
||||
|
||||
interface Message {
|
||||
id: string
|
||||
content: string
|
||||
@ -13,6 +22,7 @@ interface Message {
|
||||
|
||||
export const state = () => ({
|
||||
history: [] as Message[],
|
||||
emotes: {} as Emotes,
|
||||
})
|
||||
|
||||
export const getters = getterTree(state, {
|
||||
@ -23,7 +33,24 @@ export const mutations = mutationTree(state, {
|
||||
addMessage(state, message: Message) {
|
||||
state.history = state.history.concat([message])
|
||||
},
|
||||
|
||||
addEmote(state, { id, emote }: { id: string; emote: Emote }) {
|
||||
state.emotes = {
|
||||
...state.emotes,
|
||||
[id]: emote,
|
||||
}
|
||||
},
|
||||
|
||||
delEmote(state, id: string) {
|
||||
const emotes = {
|
||||
...state.emotes,
|
||||
}
|
||||
delete emotes[id]
|
||||
state.emotes = emotes
|
||||
},
|
||||
|
||||
clear(state) {
|
||||
state.emotes = {}
|
||||
state.history = []
|
||||
},
|
||||
})
|
||||
@ -31,20 +58,34 @@ export const mutations = mutationTree(state, {
|
||||
export const actions = actionTree(
|
||||
{ state, getters, mutations },
|
||||
{
|
||||
newEmote(store, emote: Emote) {
|
||||
if (accessor.settings.ignore_emotes) {
|
||||
return
|
||||
}
|
||||
|
||||
const id = makeid(10)
|
||||
accessor.chat.addEmote({ id, emote })
|
||||
},
|
||||
|
||||
newMessage({ state }, message: Message) {
|
||||
if (accessor.settings.chat_sound) {
|
||||
new Audio('chat.mp3').play().catch(console.error)
|
||||
}
|
||||
accessor.chat.addMessage(message)
|
||||
},
|
||||
|
||||
sendMessage(store, content: string) {
|
||||
if (!accessor.connected || accessor.user.muted) {
|
||||
return
|
||||
}
|
||||
|
||||
$client.sendMessage(EVENT.CHAT.MESSAGE, { content })
|
||||
},
|
||||
|
||||
sendEmoji(store, emoji: string) {
|
||||
if (!accessor.connected || !accessor.user.muted) {
|
||||
sendEmote(store, emote: string) {
|
||||
if (!accessor.connected || accessor.user.muted) {
|
||||
return
|
||||
}
|
||||
|
||||
$client.sendMessage(EVENT.CHAT.EMOJI, { emoji })
|
||||
$client.sendMessage(EVENT.CHAT.EMOTE, { emote })
|
||||
},
|
||||
},
|
||||
)
|
||||
|
@ -1,35 +1,22 @@
|
||||
import { getterTree, mutationTree, actionTree } from 'typed-vuex'
|
||||
import { get, set } from '~/utils/localstorage'
|
||||
import { accessor } from '~/store'
|
||||
|
||||
export const namespaced = true
|
||||
|
||||
export const state = () => {
|
||||
let side = false
|
||||
let _side = localStorage.getItem('side')
|
||||
if (_side) {
|
||||
side = _side === '1'
|
||||
}
|
||||
|
||||
let tab = 'chat'
|
||||
let _tab = localStorage.getItem('tab')
|
||||
if (_tab) {
|
||||
tab = _tab
|
||||
}
|
||||
|
||||
return {
|
||||
side,
|
||||
about: false,
|
||||
about_page: '',
|
||||
tab,
|
||||
}
|
||||
}
|
||||
export const state = () => ({
|
||||
side: get<boolean>('side', false),
|
||||
tab: get<string>('tab', 'chat'),
|
||||
about: false,
|
||||
about_page: '',
|
||||
})
|
||||
|
||||
export const getters = getterTree(state, {})
|
||||
|
||||
export const mutations = mutationTree(state, {
|
||||
setTab(state, tab: string) {
|
||||
state.tab = tab
|
||||
localStorage.setItem('tab', tab)
|
||||
set('tab', tab)
|
||||
},
|
||||
setAbout(state, page: string) {
|
||||
state.about_page = page
|
||||
@ -39,7 +26,7 @@ export const mutations = mutationTree(state, {
|
||||
},
|
||||
toggleSide(state) {
|
||||
state.side = !state.side
|
||||
localStorage.setItem('side', state.side ? '1' : '0')
|
||||
set('side', state.side)
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -12,17 +12,12 @@ import * as client from './client'
|
||||
export const state = () => ({
|
||||
connecting: false,
|
||||
connected: false,
|
||||
locked: false,
|
||||
})
|
||||
|
||||
// type RootState = ReturnType<typeof state>
|
||||
|
||||
export const getters = {
|
||||
// connected: (state: RootState) => state.connected
|
||||
}
|
||||
|
||||
export const mutations = mutationTree(state, {
|
||||
initialiseStore(state) {
|
||||
console.log('test')
|
||||
setLocked(state, locked: boolean) {
|
||||
state.locked = locked
|
||||
},
|
||||
|
||||
setConnnecting(state) {
|
||||
@ -37,7 +32,7 @@ export const mutations = mutationTree(state, {
|
||||
})
|
||||
|
||||
export const actions = actionTree(
|
||||
{ state, getters, mutations },
|
||||
{ state, mutations },
|
||||
{
|
||||
//
|
||||
connect(store, { username, password }: { username: string; password: string }) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { getterTree, mutationTree, actionTree } from 'typed-vuex'
|
||||
import { Member } from '~/client/types'
|
||||
import { EVENT } from '~/client/events'
|
||||
import { Member } from '~/neko/types'
|
||||
import { EVENT } from '~/neko/events'
|
||||
import { accessor } from '~/store'
|
||||
|
||||
export const namespaced = true
|
||||
@ -22,9 +22,6 @@ export const getters = getterTree(state, {
|
||||
})
|
||||
|
||||
export const mutations = mutationTree(state, {
|
||||
clearHost(state) {
|
||||
state.id = ''
|
||||
},
|
||||
setHost(state, host: string | Member) {
|
||||
if (typeof host === 'string') {
|
||||
state.id = host
|
||||
@ -32,6 +29,10 @@ export const mutations = mutationTree(state, {
|
||||
state.id = host.id
|
||||
}
|
||||
},
|
||||
|
||||
clear(state) {
|
||||
state.id = ''
|
||||
},
|
||||
})
|
||||
|
||||
export const actions = actionTree(
|
||||
@ -68,6 +69,22 @@ export const actions = actionTree(
|
||||
$client.sendMessage(EVENT.CONTROL.RELEASE)
|
||||
},
|
||||
|
||||
give({ getters }, member: string | Member) {
|
||||
if (!accessor.connected || !getters.hosting) {
|
||||
return
|
||||
}
|
||||
|
||||
if (typeof member === 'string') {
|
||||
member = accessor.user.members[member]
|
||||
}
|
||||
|
||||
if (!member) {
|
||||
return
|
||||
}
|
||||
|
||||
$client.sendMessage(EVENT.CONTROL.GIVE, { id: member.id })
|
||||
},
|
||||
|
||||
adminControl() {
|
||||
if (!accessor.connected || !accessor.user.admin) {
|
||||
return
|
||||
@ -84,6 +101,22 @@ export const actions = actionTree(
|
||||
$client.sendMessage(EVENT.ADMIN.RELEASE)
|
||||
},
|
||||
|
||||
adminGive({ getters }, member: string | Member) {
|
||||
if (!accessor.connected) {
|
||||
return
|
||||
}
|
||||
|
||||
if (typeof member === 'string') {
|
||||
member = accessor.user.members[member]
|
||||
}
|
||||
|
||||
if (!member) {
|
||||
return
|
||||
}
|
||||
|
||||
$client.sendMessage(EVENT.ADMIN.GIVE, { id: member.id })
|
||||
},
|
||||
|
||||
lock() {
|
||||
if (!accessor.connected || !accessor.user.admin) {
|
||||
return
|
||||
|
@ -1,30 +1,43 @@
|
||||
import { getterTree, mutationTree, actionTree } from 'typed-vuex'
|
||||
import { accessor } from '~/store'
|
||||
import { getterTree, mutationTree } from 'typed-vuex'
|
||||
import { get, set } from '~/utils/localstorage'
|
||||
|
||||
export const namespaced = true
|
||||
|
||||
export const state = () => ({
|
||||
scroll: 10,
|
||||
scroll_invert: true,
|
||||
})
|
||||
export const state = () => {
|
||||
return {
|
||||
scroll: get<number>('scroll', 10),
|
||||
scroll_invert: get<boolean>('scroll_invert', true),
|
||||
autoplay: get<boolean>('autoplay', true),
|
||||
ignore_emotes: get<boolean>('ignore_emotes', false),
|
||||
chat_sound: get<boolean>('chat_sound', true),
|
||||
}
|
||||
}
|
||||
|
||||
export const getters = getterTree(state, {})
|
||||
|
||||
export const mutations = mutationTree(state, {
|
||||
setScroll(state, scroll: number) {
|
||||
state.scroll = scroll
|
||||
localStorage.setItem('scroll', `${scroll}`)
|
||||
set('scroll', scroll)
|
||||
},
|
||||
|
||||
setInvert(state, value: boolean) {
|
||||
state.scroll_invert = value
|
||||
set('scroll_invert', value)
|
||||
},
|
||||
|
||||
setAutoplay(state, value: boolean) {
|
||||
state.autoplay = value
|
||||
set('autoplay', value)
|
||||
},
|
||||
|
||||
setIgnore(state, value: boolean) {
|
||||
state.ignore_emotes = value
|
||||
set('ignore_emotes', value)
|
||||
},
|
||||
|
||||
setSound(state, value: boolean) {
|
||||
state.chat_sound = value
|
||||
set('chat_sound', value)
|
||||
},
|
||||
})
|
||||
|
||||
export const actions = actionTree(
|
||||
{ state, getters, mutations },
|
||||
{
|
||||
initialise() {
|
||||
const scroll = localStorage.getItem('scroll')
|
||||
if (scroll) {
|
||||
accessor.settings.setScroll(parseInt(scroll))
|
||||
}
|
||||
},
|
||||
},
|
||||
)
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { getterTree, mutationTree, actionTree } from 'typed-vuex'
|
||||
import { Member } from '~/client/types'
|
||||
import { EVENT } from '~/client/events'
|
||||
import { Member } from '~/neko/types'
|
||||
import { EVENT } from '~/neko/events'
|
||||
|
||||
import { accessor } from '~/store'
|
||||
|
||||
@ -22,6 +22,12 @@ export const getters = getterTree(state, {
|
||||
})
|
||||
|
||||
export const mutations = mutationTree(state, {
|
||||
setIgnored(state, { id, ignored }: { id: string; ignored: boolean }) {
|
||||
state.members[id] = {
|
||||
...state.members[id],
|
||||
ignored,
|
||||
}
|
||||
},
|
||||
setMuted(state, { id, muted }: { id: string; muted: boolean }) {
|
||||
state.members[id] = {
|
||||
...state.members[id],
|
||||
@ -56,7 +62,7 @@ export const mutations = mutationTree(state, {
|
||||
connected: false,
|
||||
}
|
||||
},
|
||||
clearMembers(state) {
|
||||
clear(state) {
|
||||
state.members = {}
|
||||
},
|
||||
})
|
||||
|
@ -1,35 +1,21 @@
|
||||
import { getterTree, mutationTree, actionTree } from 'typed-vuex'
|
||||
import { accessor } from '~/store'
|
||||
import { get, set } from '~/utils/localstorage'
|
||||
|
||||
export const namespaced = true
|
||||
|
||||
export const state = () => {
|
||||
let volume = 100
|
||||
let _volume = localStorage.getItem('volume')
|
||||
if (_volume) {
|
||||
volume = parseInt(_volume)
|
||||
}
|
||||
|
||||
let muted = false
|
||||
let _muted = localStorage.getItem('muted')
|
||||
if (_muted) {
|
||||
muted = _muted === '1'
|
||||
}
|
||||
|
||||
return {
|
||||
index: -1,
|
||||
tracks: [] as MediaStreamTrack[],
|
||||
streams: [] as MediaStream[],
|
||||
width: 1280,
|
||||
height: 720,
|
||||
horizontal: 16,
|
||||
vertical: 9,
|
||||
volume,
|
||||
muted,
|
||||
playing: false,
|
||||
playable: false,
|
||||
}
|
||||
}
|
||||
export const state = () => ({
|
||||
index: -1,
|
||||
tracks: [] as MediaStreamTrack[],
|
||||
streams: [] as MediaStream[],
|
||||
width: 1280,
|
||||
height: 720,
|
||||
horizontal: 16,
|
||||
vertical: 9,
|
||||
volume: get<number>('volume', 100),
|
||||
muted: get<boolean>('muted', false),
|
||||
playing: false,
|
||||
playable: false,
|
||||
})
|
||||
|
||||
export const getters = getterTree(state, {
|
||||
stream: state => state.streams[state.index],
|
||||
@ -58,6 +44,7 @@ export const mutations = mutationTree(state, {
|
||||
|
||||
toggleMute(state) {
|
||||
state.muted = !state.muted
|
||||
set('mute', state.muted)
|
||||
},
|
||||
|
||||
setPlayable(state, playable: boolean) {
|
||||
@ -107,7 +94,7 @@ export const mutations = mutationTree(state, {
|
||||
|
||||
setVolume(state, volume: number) {
|
||||
state.volume = volume
|
||||
localStorage.setItem('volume', `${volume}`)
|
||||
set('volume', volume)
|
||||
},
|
||||
|
||||
setStream(state, index: number) {
|
||||
@ -130,15 +117,3 @@ export const mutations = mutationTree(state, {
|
||||
state.streams = []
|
||||
},
|
||||
})
|
||||
|
||||
export const actions = actionTree(
|
||||
{ state, getters, mutations },
|
||||
{
|
||||
initialise({ commit }) {
|
||||
const volume = localStorage.getItem('volume')
|
||||
if (volume) {
|
||||
accessor.video.setVolume(parseInt(volume))
|
||||
}
|
||||
},
|
||||
},
|
||||
)
|
||||
|
Reference in New Issue
Block a user