From d7d4132b9bf3a41e503fe879263db15e8e78f267 Mon Sep 17 00:00:00 2001 From: dragongoose Date: Sat, 4 Nov 2023 19:39:22 -0400 Subject: [PATCH] Add comments and stuff --- src/settingsManager.ts | 43 +++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/settingsManager.ts b/src/settingsManager.ts index 3a6e254..19a611e 100644 --- a/src/settingsManager.ts +++ b/src/settingsManager.ts @@ -1,13 +1,6 @@ const locales = ['en-US', 'es-ES', 'nl-NL', 'pt-PT', 'fa-IR', 'he-IL', 'ru-RU', 'ko-KR', 'cs-CZ', 'pl-PL', 'it-IT', 'fr-FR', 'uk-UA', 'de-DE'] const languages = ['English', 'Español', 'Nederlands', 'Português', 'فارسی', 'עִבְרִית', 'Русский', '한국어', 'Česky', 'Polski', 'Italia', 'Français', 'Українська', 'Deutsch'] -export const setLanguage = (selectedLanguage: string, i18n: any) => { - // Locales and languages in arrays to match them - const locale = locales[languages.indexOf(selectedLanguage)] - localStorage.setItem("language", locale) - i18n.locale = locale -} - export interface SettingsCheckbox { name: string selected: boolean, @@ -34,7 +27,22 @@ export interface Settings { } } +/** + * Sets the language by locale + * @param selectedLanguage language to set + * @param i18n the i18n class in use + */ +export const setLanguage = (selectedLanguage: string, i18n: any) => { + // Locales and languages in arrays to match them + const locale = locales[languages.indexOf(selectedLanguage)] + localStorage.setItem("language", locale) + i18n.locale = locale +} +/** + * Returns the default settings + * @returns Settings + */ export function getDefaultSettings(): Settings { return { version: import.meta.env.SAFETWITCH_TAG, @@ -131,6 +139,13 @@ export function syncUserSettings(settings: Settings): {settings: Settings, chang return { settings: synced, changed: true } } +/** + * Gets a users' setting's value from the setting's key + * @param key Setting key to get + * @returns a boolean or string depending on setting type + * @example + * getSetting("audioOnly") // false + */ export function getSetting(key: string): boolean | string { const storage = localStorage.getItem('settings') let parsed @@ -143,18 +158,16 @@ export function getSetting(key: string): boolean | string { return parsed[key].selected } +/** + * Gets the current theme + * @returns the name of the current theme + * @default string light + */ export function getTheme() { return localStorage.getItem('theme') || "light" } -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 -} - +// every avaliable theme export const themeList = [ { // name your theme anything that could be a valid css class name