Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
m1k1o
GitHub Repository: m1k1o/neko
Path: blob/master/client/src/store/settings.ts
1301 views
1
import { getterTree, mutationTree, actionTree } from 'typed-vuex'
2
import { get, set } from '~/utils/localstorage'
3
import { EVENT } from '~/neko/events'
4
import { accessor } from '~/store'
5
6
export const namespaced = true
7
8
interface KeyboardLayouts {
9
[code: string]: string
10
}
11
12
export const state = () => {
13
return {
14
scroll: get<number>('scroll', 10),
15
scroll_invert: get<boolean>('scroll_invert', true),
16
autoplay: get<boolean>('autoplay', true),
17
ignore_emotes: get<boolean>('ignore_emotes', false),
18
chat_sound: get<boolean>('chat_sound', true),
19
keyboard_layout: get<string>('keyboard_layout', 'us'),
20
21
keyboard_layouts_list: {} as KeyboardLayouts,
22
23
broadcast_is_active: false,
24
broadcast_url: '',
25
}
26
}
27
28
export const getters = getterTree(state, {})
29
30
export const mutations = mutationTree(state, {
31
setScroll(state, scroll: number) {
32
state.scroll = scroll
33
set('scroll', scroll)
34
},
35
36
setInvert(state, value: boolean) {
37
state.scroll_invert = value
38
set('scroll_invert', value)
39
},
40
41
setAutoplay(state, value: boolean) {
42
state.autoplay = value
43
set('autoplay', value)
44
},
45
46
setIgnore(state, value: boolean) {
47
state.ignore_emotes = value
48
set('ignore_emotes', value)
49
},
50
51
setSound(state, value: boolean) {
52
state.chat_sound = value
53
set('chat_sound', value)
54
},
55
56
setKeyboardLayout(state, value: string) {
57
state.keyboard_layout = value
58
set('keyboard_layout', value)
59
},
60
61
setKeyboardLayoutsList(state, value: KeyboardLayouts) {
62
state.keyboard_layouts_list = value
63
},
64
setBroadcastStatus(state, { url, isActive }) {
65
state.broadcast_url = url
66
state.broadcast_is_active = isActive
67
},
68
})
69
70
export const actions = actionTree(
71
{ state, getters, mutations },
72
{
73
async initialise() {
74
try {
75
const req = await $http.get<KeyboardLayouts>('keyboard_layouts.json')
76
accessor.settings.setKeyboardLayoutsList(req.data)
77
} catch (err: any) {
78
console.error(err)
79
}
80
},
81
82
broadcastStatus(store, { url, isActive }) {
83
accessor.settings.setBroadcastStatus({ url, isActive })
84
},
85
broadcastCreate(store, url: string) {
86
$client.sendMessage(EVENT.BROADCAST.CREATE, { url })
87
},
88
broadcastDestroy() {
89
$client.sendMessage(EVENT.BROADCAST.DESTROY)
90
},
91
},
92
)
93
94