Archived
2
0
This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
neko-custom/client/src/store/settings.ts

94 lines
2.3 KiB
TypeScript
Raw Normal View History

2020-06-16 12:09:05 +12:00
import { getterTree, mutationTree, actionTree } from 'typed-vuex'
2020-01-24 04:23:26 +13:00
import { get, set } from '~/utils/localstorage'
2020-09-27 12:13:34 +13:00
import { EVENT } from '~/neko/events'
2020-06-16 12:09:05 +12:00
import { accessor } from '~/store'
2020-01-23 06:16:40 +13:00
export const namespaced = true
2020-06-16 12:09:05 +12:00
interface KeyboardLayouts {
[code: string]: string
}
2020-01-24 04:23:26 +13:00
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),
2020-06-16 08:09:01 +12:00
keyboard_layout: get<string>('keyboard_layout', 'us'),
2020-06-16 12:09:05 +12:00
keyboard_layouts_list: {} as KeyboardLayouts,
2020-09-27 12:13:34 +13:00
broadcast_is_active: false,
broadcast_url: "",
2020-01-24 04:23:26 +13:00
}
}
2020-01-23 06:16:40 +13:00
export const getters = getterTree(state, {})
export const mutations = mutationTree(state, {
setScroll(state, scroll: number) {
state.scroll = scroll
2020-01-24 04:23:26 +13:00
set('scroll', scroll)
2020-01-23 06:16:40 +13:00
},
2020-01-24 04:23:26 +13:00
setInvert(state, value: boolean) {
state.scroll_invert = value
set('scroll_invert', value)
2020-01-23 06:16:40 +13:00
},
2020-01-24 04:23:26 +13:00
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)
},
2020-06-16 08:09:01 +12:00
setKeyboardLayout(state, value: string) {
state.keyboard_layout = value
set('keyboard_layout', value)
},
2020-06-16 12:09:05 +12:00
setKeyboardLayoutsList(state, value: KeyboardLayouts) {
state.keyboard_layouts_list = value
},
2020-09-27 12:13:34 +13:00
setBroadcastStatus(state, { url, isActive }) {
state.broadcast_url = url,
state.broadcast_is_active = isActive
},
2020-01-24 04:23:26 +13:00
})
2020-06-16 12:09:05 +12:00
export const actions = actionTree(
{ state, getters, mutations },
{
initialise() {
$http
.get<KeyboardLayouts>('/keyboard_layouts.json')
.then((req) => {
accessor.settings.setKeyboardLayoutsList(req.data)
console.log(req.data)
})
.catch(console.error)
},
2020-09-27 12:13:34 +13:00
broadcastStatus({ getters }, { url, isActive }) {
accessor.settings.setBroadcastStatus({ url, isActive })
},
broadcastCreate({ getters }, url: string) {
$client.sendMessage(EVENT.BROADCAST.CREATE, { url })
},
broadcastDestroy({ getters }) {
$client.sendMessage(EVENT.BROADCAST.DESTROY)
},
2020-06-16 12:09:05 +12:00
},
)