Files
discord-decomp/modules/client_themes/SavedCustomThemeStore.tsx
T
2026-11-01 12:12:55 +02:00

96 lines
2.8 KiB
TypeScript

// Metro module 4123 (f4124).
import { PROTO_THEME_MAP_MOBILE, PROTO_THEME_MAP_WEB_REFRESH } from "../user_settings/ThemeConstants";
import SentryUtils_native from "../../utils/SentryUtils.native";
import Module589 from "../../_bundle/Module589";
import Dispatcher from "../../Dispatcher";
let c2376_3, savedCustomThemes, NOT_FETCHED;
const validateSavedTheme = function validateSavedTheme(a0) {
let r10;
try {
const r6 = PROTO_THEME_MAP_MOBILE[a0.base_theme];
r10 = a0.colors.length > 0 && typeof a0.gradient_angle === "number" && typeof a0.base_mix === "number" && r6 != null;
} catch ($e) {
SentryUtils_native.captureMessage("Invalid saved custom theme: " + $e, {
tags: {
app_context: "SavedCustomThemeStore"
}
});
return false;
}
return r10;
};
PROTO_THEME_MAP_WEB_REFRESH;
c2376_3 = {
NOT_FETCHED: 0,
0: "NOT_FETCHED",
IS_FETCHING: 1,
1: "IS_FETCHING",
HAS_FETCHED: 2,
2: "HAS_FETCHED",
ERROR: 3,
3: "ERROR"
};
savedCustomThemes = [];
NOT_FETCHED = c2376_3.NOT_FETCHED;
class SavedCustomThemeStore extends Module589.PersistedStore {
static displayName = "SavedCustomThemeStore";
static persistKey = "SavedCustomThemeStore";
initialize(a0) {
if (a0 != null) {
savedCustomThemes = a0.savedCustomThemes;
}
NOT_FETCHED = c2376_3.NOT_FETCHED;
}
getState() {
let savedCustomThemes2 = savedCustomThemes;
if (savedCustomThemes2 == null) {
savedCustomThemes2 = [];
}
return {
savedCustomThemes: savedCustomThemes2
};
}
getSavedCustomTheme() {
return savedCustomThemes?.length > 0 ? savedCustomThemes[0].colors.length > 0 ? savedCustomThemes[0] : null : null;
}
getFetchState() {
return NOT_FETCHED;
}
hasSavedCustomThemes() {
return savedCustomThemes?.length > 0;
}
isFetching() {
return NOT_FETCHED === c2376_3.IS_FETCHING;
}
hasFetched() {
return NOT_FETCHED === c2376_3.HAS_FETCHED;
}
hasError() {
return NOT_FETCHED === c2376_3.ERROR;
}
}
const savedCustomThemeStore = new SavedCustomThemeStore(Dispatcher, {
SAVED_CUSTOM_THEMES_FETCH_START: function handleCustomThemesFetchStart() {
NOT_FETCHED = c2376_3.IS_FETCHING;
},
SAVED_CUSTOM_THEMES_FETCH_SUCCESS: function handleCustomThemesFetchSuccess({ themes }) {
NOT_FETCHED = c2376_3.HAS_FETCHED;
savedCustomThemes = themes.filter(validateSavedTheme).map((item) => ({
colors: item.colors,
gradient_angle: item.gradient_angle,
base_mix: item.base_mix,
base_theme: PROTO_THEME_MAP_MOBILE[item.base_theme]
}));
},
SAVED_CUSTOM_THEMES_FETCH_FAILURE: function handleCustomThemesFetchFailure({ error }) {
NOT_FETCHED = c2376_3.ERROR;
SentryUtils_native.captureException(error, {
tags: {
app_context: "SavedCustomThemeStore"
}
});
}
});
export default savedCustomThemeStore;
export { c2376_3 as FetchState };