mirror of
https://codeberg.org/SafeTwitch/safetwitch.git
synced 2024-12-22 05:12:57 -05:00
Move settings related functions
This commit is contained in:
parent
63aff74e6b
commit
12d6bd2c38
5 changed files with 48 additions and 46 deletions
|
@ -39,46 +39,4 @@ export async function getEndpoint(endpoint: string) {
|
|||
const data = rawData.data
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
export function getDefaultSettings() {
|
||||
return {
|
||||
version: import.meta.env.SAFETWITCH_TAG,
|
||||
audioOnly: {
|
||||
name: 'Audio Only',
|
||||
selected: false,
|
||||
type: 'checkbox'
|
||||
},
|
||||
defaultQuality: {
|
||||
name: 'Default Quality',
|
||||
options: ['160p', '360p', '480p', '720p', '1080p'],
|
||||
selected: '480p',
|
||||
type: 'option'
|
||||
},
|
||||
chatVisible: {
|
||||
name: 'Hide Chat',
|
||||
selected: false,
|
||||
type: 'checkbox'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function getSetting(key: string): boolean | string {
|
||||
const storage = localStorage.getItem('settings')
|
||||
let parsed
|
||||
if (!storage) {
|
||||
parsed = getDefaultSettings()
|
||||
} else {
|
||||
parsed = JSON.parse(storage)
|
||||
}
|
||||
|
||||
return parsed[key].selected
|
||||
}
|
||||
|
||||
export function chatVisible() {
|
||||
const p = getSetting('chatVisible')
|
||||
// Flip becuase on the setting page it's
|
||||
// displayed as "Hide Chat", but the value
|
||||
// is chatVisible
|
||||
return !p
|
||||
}
|
||||
}
|
42
src/settingsManager.ts
Normal file
42
src/settingsManager.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
export function getDefaultSettings() {
|
||||
return {
|
||||
version: import.meta.env.SAFETWITCH_TAG,
|
||||
audioOnly: {
|
||||
name: 'Audio Only',
|
||||
selected: false,
|
||||
type: 'checkbox'
|
||||
},
|
||||
defaultQuality: {
|
||||
name: 'Default Quality',
|
||||
options: ['160p', '360p', '480p', '720p', '1080p'],
|
||||
selected: '480p',
|
||||
type: 'option'
|
||||
},
|
||||
chatVisible: {
|
||||
name: 'Hide Chat',
|
||||
selected: false,
|
||||
type: 'checkbox'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function getSetting(key: string): boolean | string {
|
||||
const storage = localStorage.getItem('settings')
|
||||
let parsed
|
||||
if (!storage) {
|
||||
parsed = getDefaultSettings()
|
||||
} else {
|
||||
parsed = JSON.parse(storage)
|
||||
}
|
||||
|
||||
return parsed[key].selected
|
||||
}
|
||||
|
||||
export function chatVisible() {
|
||||
const p = getSetting('chatVisible')
|
||||
// Flip becuase on the setting page it's
|
||||
// displayed as "Hide Chat", but the value
|
||||
// is chatVisible
|
||||
return !p
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<script lang="ts">
|
||||
import { getDefaultSettings } from '@/mixins'
|
||||
import { getDefaultSettings } from '@/settingsManager'
|
||||
|
||||
export default {
|
||||
setup() {
|
||||
|
|
|
@ -10,7 +10,8 @@ import LoadingScreen from '@/components/LoadingScreen.vue'
|
|||
import VideoTab from '@/components/user/VideoTab.vue'
|
||||
|
||||
import type { StreamerData } from '@/types'
|
||||
import { truncate, abbreviate, getEndpoint, chatVisible } from '@/mixins'
|
||||
import { truncate, abbreviate, getEndpoint } from '@/mixins'
|
||||
import { chatVisible } from '@/settingsManager'
|
||||
|
||||
export default {
|
||||
inject: ['rootBackendUrl'],
|
||||
|
|
|
@ -9,7 +9,8 @@ import FollowButton from '@/components/FollowButton.vue'
|
|||
import LoadingScreen from '@/components/LoadingScreen.vue'
|
||||
|
||||
import type { Video } from '@/types'
|
||||
import { truncate, abbreviate, getEndpoint, chatVisible } from '@/mixins'
|
||||
import { truncate, abbreviate, getEndpoint } from '@/mixins'
|
||||
import { chatVisible } from '@/settingsManager'
|
||||
|
||||
interface ChatComponent {
|
||||
updateVodComments: (time: number) => void
|
||||
|
|
Loading…
Reference in a new issue