Files
discord-decomp/modules/guild_themes/native/useRoutedActiveGuildTheme.tsx
T
2026-11-01 12:12:55 +02:00

120 lines
4.0 KiB
TypeScript

// Metro module 4039 (f4040).
import { useContext, useState, useEffect } from "react";
import { ME } from "../../../Constants";
import { coerceMainRoute } from "../../main_tabs_v2/helpers/NavigationRouteUtils.native";
import { getRootNavigationRef } from "../../main_tabs_v2/RootNavigationRef.native";
import GuildThemeGuildIdOverrideContext from "./GuildThemeGuildIdOverrideContext";
import { useActiveGuildThemeForGuildId } from "../GuildThemeResolver";
let getActiveGuildThemeGuildIdSnapshot;
const getGuildIdFromNavigationState = function getGuildIdFromNavigationState(a0) {
if (a0 != null) {
const routes = a0.routes;
if (routes != null) {
const r6 = routes[a0.index];
let r9 = r6 == null ? void 0 : r6.params?.guildId;
if (r9 == null) {
r9 = getGuildIdFromNavigationState(r6?.state);
}
return r9;
}
}
};
getActiveGuildThemeGuildIdSnapshot = function getActiveGuildThemeGuildIdSnapshot() {
const rootNavigationRef = getRootNavigationRef();
if (rootNavigationRef != null && rootNavigationRef.isReady()) {
const rootState = rootNavigationRef.getRootState();
const r3 = rootState != null;
let r20 = void 0;
if (r3) {
const routes = rootState.routes;
const r21 = routes != null;
r20 = void 0;
if (r21) {
const r23 = routes[rootState.index];
let r25 = r23 == null ? void 0 : r23.params?.guildId;
if (r25 == null) {
const state = r23?.state;
const r29 = state != null;
let r30 = void 0;
if (r29) {
const routes2 = state.routes;
const r31 = routes2 != null;
r30 = void 0;
if (r31) {
const r14 = routes2[state.index];
let r34 = r14 == null ? void 0 : r14.params?.guildId;
if (r34 == null) {
r34 = getGuildIdFromNavigationState(r14?.state);
}
r30 = r34;
}
}
r25 = r30;
}
r20 = r25;
}
}
if (r20 == null) {
const r39 = rootState == null;
let r40 = void 0;
if (!r39) {
const routes3 = rootState.routes;
r40 = routes3 == null ? void 0 : routes3.map(coerceMainRoute).find((item) => item != null);
}
const state2 = r40?.state;
const r52 = state2 != null;
let r53 = void 0;
if (r52) {
const routes4 = state2.routes;
const r55 = routes4 != null;
r53 = void 0;
if (r55) {
const r57 = routes4[state2.index];
let r59 = r57 == null ? void 0 : r57.params?.guildId;
if (r59 == null) {
const state3 = r57?.state;
const r64 = state3 != null;
let r65 = void 0;
if (r64) {
const routes5 = state3.routes;
const r67 = routes5 != null;
r65 = void 0;
if (r67) {
const r69 = routes5[state3.index];
let r71 = r69 == null ? void 0 : r69.params?.guildId;
if (r71 == null) {
r71 = getGuildIdFromNavigationState(r69?.state);
}
r65 = r71;
}
}
r59 = r65;
}
r53 = r59;
}
}
r20 = r53;
}
return r20 == null ? null : r20 !== ME ? r20 : null;
}
return null;
};
export default function useRoutedActiveGuildTheme() {
const context = useContext(GuildThemeGuildIdOverrideContext);
let [state, setState] = useState(getActiveGuildThemeGuildIdSnapshot);
useEffect(() => {
const rootNavigationRef = getRootNavigationRef();
if (rootNavigationRef != null) {
const handleStateChange = function handleStateChange() {
setState(getActiveGuildThemeGuildIdSnapshot());
};
setState(getActiveGuildThemeGuildIdSnapshot());
return rootNavigationRef.addListener("state", handleStateChange);
}
}, []);
if (context !== void 0) {
state = context !== ME ? context : null;
}
return useActiveGuildThemeForGuildId(state);
};