mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-23 08:43:50 +02:00
refactor store
This commit is contained in:
@@ -20,8 +20,8 @@ import {
|
||||
getThemeMode,
|
||||
updateTrustColorClasses
|
||||
} from '../../shared/utils/base/ui';
|
||||
import { computeTrustLevel, getNameColour } from '../../shared/utils';
|
||||
import { database } from '../../service/database';
|
||||
import { getNameColour } from '../../shared/utils';
|
||||
import { languageCodes } from '../../localization';
|
||||
import { loadLocalizedStrings } from '../../plugin';
|
||||
import { useFeedStore } from '../feed';
|
||||
@@ -127,6 +127,9 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
: fallback;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function initAppearanceSettings() {
|
||||
const { initThemeMode, isDarkMode: initDarkMode } =
|
||||
await getThemeMode(configRepository);
|
||||
@@ -410,6 +413,10 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
updateTrustColorClasses(trustColor.value);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param customFunc
|
||||
*/
|
||||
async function userColourInit(customFunc) {
|
||||
let dictObject = null;
|
||||
if (typeof customFunc === 'function') {
|
||||
@@ -440,55 +447,13 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
* @param {object} ref
|
||||
*/
|
||||
function applyUserTrustLevel(ref) {
|
||||
ref.$isModerator =
|
||||
ref.developerType && ref.developerType !== 'none';
|
||||
ref.$isTroll = false;
|
||||
ref.$isProbableTroll = false;
|
||||
let trustColorTemp = '';
|
||||
const { tags } = ref;
|
||||
if (tags.includes('admin_moderator')) {
|
||||
ref.$isModerator = true;
|
||||
}
|
||||
if (tags.includes('system_troll')) {
|
||||
ref.$isTroll = true;
|
||||
}
|
||||
if (tags.includes('system_probable_troll') && !ref.$isTroll) {
|
||||
ref.$isProbableTroll = true;
|
||||
}
|
||||
if (tags.includes('system_trust_veteran')) {
|
||||
ref.$trustLevel = 'Trusted User';
|
||||
ref.$trustClass = 'x-tag-veteran';
|
||||
trustColorTemp = 'veteran';
|
||||
ref.$trustSortNum = 5;
|
||||
} else if (tags.includes('system_trust_trusted')) {
|
||||
ref.$trustLevel = 'Known User';
|
||||
ref.$trustClass = 'x-tag-trusted';
|
||||
trustColorTemp = 'trusted';
|
||||
ref.$trustSortNum = 4;
|
||||
} else if (tags.includes('system_trust_known')) {
|
||||
ref.$trustLevel = 'User';
|
||||
ref.$trustClass = 'x-tag-known';
|
||||
trustColorTemp = 'known';
|
||||
ref.$trustSortNum = 3;
|
||||
} else if (tags.includes('system_trust_basic')) {
|
||||
ref.$trustLevel = 'New User';
|
||||
ref.$trustClass = 'x-tag-basic';
|
||||
trustColorTemp = 'basic';
|
||||
ref.$trustSortNum = 2;
|
||||
} else {
|
||||
ref.$trustLevel = 'Visitor';
|
||||
ref.$trustClass = 'x-tag-untrusted';
|
||||
trustColorTemp = 'untrusted';
|
||||
ref.$trustSortNum = 1;
|
||||
}
|
||||
if (ref.$isTroll || ref.$isProbableTroll) {
|
||||
trustColorTemp = 'troll';
|
||||
ref.$trustSortNum += 0.1;
|
||||
}
|
||||
if (ref.$isModerator) {
|
||||
trustColorTemp = 'vip';
|
||||
ref.$trustSortNum += 0.3;
|
||||
}
|
||||
const trust = computeTrustLevel(ref.tags, ref.developerType);
|
||||
ref.$isModerator = trust.isModerator;
|
||||
ref.$isTroll = trust.isTroll;
|
||||
ref.$isProbableTroll = trust.isProbableTroll;
|
||||
ref.$trustLevel = trust.trustLevel;
|
||||
ref.$trustClass = trust.trustClass;
|
||||
ref.$trustSortNum = trust.trustSortNum;
|
||||
if (randomUserColours.value && watchState.isFriendsLoaded) {
|
||||
if (!ref.$userColour) {
|
||||
getNameColour(ref.id).then((colour) => {
|
||||
@@ -496,7 +461,7 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
});
|
||||
}
|
||||
} else {
|
||||
ref.$userColour = trustColor.value[trustColorTemp];
|
||||
ref.$userColour = trustColor.value[trust.trustColorKey];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -525,6 +490,9 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
updateTrustColor(undefined, undefined);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function toggleThemeMode() {
|
||||
const nextMode = isDarkMode.value
|
||||
? 'light'
|
||||
@@ -532,12 +500,20 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
setThemeMode(nextMode);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
function normalizeAppFontFamily(value) {
|
||||
return APP_FONT_FAMILIES.includes(value)
|
||||
? value
|
||||
: APP_FONT_DEFAULT_KEY;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
function setAppFontFamily(value) {
|
||||
const normalized = normalizeAppFontFamily(value);
|
||||
appFontFamily.value = normalized;
|
||||
@@ -545,6 +521,9 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
applyAppFontFamily(normalized);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function setDisplayVRCPlusIconsAsAvatar() {
|
||||
displayVRCPlusIconsAsAvatar.value =
|
||||
!displayVRCPlusIconsAsAvatar.value;
|
||||
@@ -553,6 +532,9 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
displayVRCPlusIconsAsAvatar.value
|
||||
);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function setNotificationIconDot() {
|
||||
notificationIconDot.value = !notificationIconDot.value;
|
||||
configRepository.setBool(
|
||||
@@ -561,10 +543,16 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
);
|
||||
uiStore.updateTrayIconNotify();
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function setHideNicknames() {
|
||||
hideNicknames.value = !hideNicknames.value;
|
||||
configRepository.setBool('VRCX_hideNicknames', hideNicknames.value);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function setShowInstanceIdInLocation() {
|
||||
showInstanceIdInLocation.value = !showInstanceIdInLocation.value;
|
||||
configRepository.setBool(
|
||||
@@ -572,6 +560,9 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
showInstanceIdInLocation.value
|
||||
);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function setIsAgeGatedInstancesVisible() {
|
||||
isAgeGatedInstancesVisible.value =
|
||||
!isAgeGatedInstancesVisible.value;
|
||||
@@ -580,10 +571,16 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
isAgeGatedInstancesVisible.value
|
||||
);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function setSortFavorites() {
|
||||
sortFavorites.value = !sortFavorites.value;
|
||||
configRepository.setBool('VRCX_sortFavorites', sortFavorites.value);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function setInstanceUsersSortAlphabetical() {
|
||||
instanceUsersSortAlphabetical.value =
|
||||
!instanceUsersSortAlphabetical.value;
|
||||
@@ -593,6 +590,10 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param size
|
||||
*/
|
||||
function setTablePageSize(size) {
|
||||
const processedSize = clampInt(size, 1, MAX_TABLE_PAGE_SIZE);
|
||||
tablePageSize.value = processedSize;
|
||||
@@ -601,6 +602,10 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
return processedSize;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param input
|
||||
*/
|
||||
function normalizeTablePageSizes(input) {
|
||||
const values = (
|
||||
Array.isArray(input) ? input : DEFAULT_TABLE_PAGE_SIZES
|
||||
@@ -629,10 +634,16 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
setTablePageSize(tablePageSizes.value[0]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function setDtHour12() {
|
||||
dtHour12.value = !dtHour12.value;
|
||||
configRepository.setBool('VRCX_dtHour12', dtHour12.value);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function setDtIsoFormat() {
|
||||
dtIsoFormat.value = !dtIsoFormat.value;
|
||||
configRepository.setBool('VRCX_dtIsoFormat', dtIsoFormat.value);
|
||||
@@ -668,13 +679,24 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
JSON.stringify(methods)
|
||||
);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param collapsed
|
||||
*/
|
||||
function setNavCollapsed(collapsed) {
|
||||
isNavCollapsed.value = collapsed;
|
||||
configRepository.setBool('VRCX_navIsCollapsed', collapsed);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function toggleNavCollapsed() {
|
||||
setNavCollapsed(!isNavCollapsed.value);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param widthOrArray
|
||||
*/
|
||||
function setNavWidth(widthOrArray) {
|
||||
let width = null;
|
||||
if (Array.isArray(widthOrArray) && widthOrArray.length) {
|
||||
@@ -692,6 +714,9 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function setIsSidebarGroupByInstance() {
|
||||
isSidebarGroupByInstance.value = !isSidebarGroupByInstance.value;
|
||||
configRepository.setBool(
|
||||
@@ -699,6 +724,9 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
isSidebarGroupByInstance.value
|
||||
);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function setIsHideFriendsInSameInstance() {
|
||||
isHideFriendsInSameInstance.value =
|
||||
!isHideFriendsInSameInstance.value;
|
||||
@@ -707,6 +735,9 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
isHideFriendsInSameInstance.value
|
||||
);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function setIsSidebarDivideByFriendGroup() {
|
||||
isSidebarDivideByFriendGroup.value =
|
||||
!isSidebarDivideByFriendGroup.value;
|
||||
@@ -735,18 +766,30 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
JSON.stringify(value)
|
||||
);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function setHideUserNotes() {
|
||||
hideUserNotes.value = !hideUserNotes.value;
|
||||
configRepository.setBool('VRCX_hideUserNotes', hideUserNotes.value);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function setHideUserMemos() {
|
||||
hideUserMemos.value = !hideUserMemos.value;
|
||||
configRepository.setBool('VRCX_hideUserMemos', hideUserMemos.value);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function setHideUnfriends() {
|
||||
hideUnfriends.value = !hideUnfriends.value;
|
||||
configRepository.setBool('VRCX_hideUnfriends', hideUnfriends.value);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function setRandomUserColours() {
|
||||
randomUserColours.value = !randomUserColours.value;
|
||||
configRepository.setBool(
|
||||
@@ -754,6 +797,10 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
randomUserColours.value
|
||||
);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
function normalizeTableDensity(value) {
|
||||
if (
|
||||
value === 'compact' ||
|
||||
@@ -765,6 +812,10 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
return 'standard';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param density
|
||||
*/
|
||||
function setTableDensity(density) {
|
||||
const normalized = normalizeTableDensity(density);
|
||||
tableDensity.value = normalized;
|
||||
@@ -772,6 +823,9 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
configRepository.setString('VRCX_tableDensity', tableDensity.value);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function toggleStripedDataTable() {
|
||||
isDataTableStriped.value = !isDataTableStriped.value;
|
||||
configRepository.setBool(
|
||||
@@ -781,6 +835,9 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
}
|
||||
|
||||
// FIXME: this is nasty, there should be a better way of doing this
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function applyPointerHoverClass() {
|
||||
const classList = document.documentElement.classList;
|
||||
classList.remove('force-pointer-on-hover');
|
||||
@@ -790,6 +847,9 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function togglePointerOnHover() {
|
||||
showPointerOnHover.value = !showPointerOnHover.value;
|
||||
configRepository.setBool(
|
||||
@@ -811,6 +871,9 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function handleSaveSidebarSortOrder() {
|
||||
if (sidebarSortMethod1.value === sidebarSortMethod2.value) {
|
||||
sidebarSortMethod2.value = '';
|
||||
@@ -835,6 +898,9 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
setSidebarSortMethods(sidebarSortMethods);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function mergeOldSortMethodsSettings() {
|
||||
const orderFriendsGroupPrivate = await configRepository.getBool(
|
||||
'orderFriendGroupPrivate'
|
||||
@@ -897,6 +963,9 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
return n;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function showTableLimitsDialog() {
|
||||
tableLimitsDialog.value.maxTableSize = Number(
|
||||
vrcxStore.maxTableSize ?? 500
|
||||
@@ -907,10 +976,16 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
tableLimitsDialog.value.visible = true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function closeTableLimitsDialog() {
|
||||
tableLimitsDialog.value.visible = false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function saveTableLimitsDialog() {
|
||||
const nextMaxTableSize = clampLimit(
|
||||
tableLimitsDialog.value.maxTableSize,
|
||||
@@ -949,6 +1024,9 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
tableLimitsDialog.value.visible = false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function tryInitUserColours() {
|
||||
if (!randomUserColours.value) {
|
||||
return;
|
||||
@@ -958,6 +1036,10 @@ export const useAppearanceSettingsStore = defineStore(
|
||||
await userColourInit();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param density
|
||||
*/
|
||||
function applyTableDensity(density) {
|
||||
const classList = document.documentElement.classList;
|
||||
classList.remove('is-compact-table', 'is-comfortable-table');
|
||||
|
||||
Reference in New Issue
Block a user