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

100 lines
5.3 KiB
TypeScript

// Metro module 14719 (f14720).
import { useCallback } from "react";
import { ScrollView, View } from "react-native";
import LocalAppDetectionStore from "../../local_app_detection/native/LocalAppDetectionStore";
import MobileGameCommunitiesStore from "./MobileGameCommunitiesStore";
import { createStyles } from "../../../design/components/Styles/native/createStyles";
import Module712 from "../../../_bundle/Module712";
import { useStateFromStores, useStateFromStoresObject } from "../../../_bundle/Module589";
import { DETECTABLE_GAME_TO_APPLICATION_ID_MAP } from "./GameCommunityConfig";
import { detectLocalApps } from "../../local_app_detection/native/LocalAppDetectionUtils";
import { ALL_DETECTABLE_APP_NAMES } from "../../local_app_detection/LocalAppDetectionTypes";
import { TableRowGroup } from "../../../design/components/TableRow/native/TableRowGroup.native";
import { TableRow } from "../../../design/components/TableRow/native/TableRow.native";
import { RefreshIcon } from "../../../design/components/Icon/native/redesign/generated/RefreshIcon";
import { TableRowArrow } from "../../../design/components/TableRow/native/TableRowArrow.native";
import { removeDismissedContent } from "../../user_settings/UserSettingsProtoActionCreators";
import { DismissibleContent } from "../../../_bundle/Module1358";
import { resetDismissibleContentFrameworkStore } from "../../dismissible_content/DismissibleContentFrameworkActionCreators";
let useStyles;
const MultiGuildDevTools = function MultiGuildDevTools() {
let callback;
const styles = useStyles();
const stateFromStores = useStateFromStores([LocalAppDetectionStore], () => LocalAppDetectionStore.getUserAgnosticState());
const stateFromStoresObject = useStateFromStoresObject([MobileGameCommunitiesStore], () => ({
guildsCount: MobileGameCommunitiesStore.getPresentableUpsellGuilds().length,
dismissedCount: MobileGameCommunitiesStore.getDismissedGuildIds().size,
lastFetchedAt: MobileGameCommunitiesStore.getLastFetchedAt()
}));
const { guildsCount, dismissedCount, lastFetchedAt } = stateFromStoresObject;
const r14 = Object.entries(DETECTABLE_GAME_TO_APPLICATION_ID_MAP).map((item) => {
const [detectableAppName, gameId] = item;
const r19 = stateFromStores.apps[detectableAppName];
let detected = r19?.detected;
if (detected == null) {
detected = false;
}
return {
detectableAppName,
gameId,
detected,
lastScannedAt: r19?.lastScannedAt
};
});
const subLabel = lastFetchedAt > 0 ? `${new Date(lastFetchedAt).toLocaleTimeString()}` : "Never";
callback = useCallback(() => {
LocalAppDetectionStore.DEV_resetState();
MobileGameCommunitiesStore.DEV_clearFetchCache();
detectLocalApps(ALL_DETECTABLE_APP_NAMES);
}, []);
return <View style={styles.container}>
<ScrollView style={styles.scrollView}>
<View style={styles.section}>
<TableRowGroup title="Detected Apps" hasIcons={false}>
{r14.length === 0 ? <TableRow label="No games configured" subLabel="MULTI_GUILD_GAME_CONFIGS is empty" disabled /> : r14.map((item) => <TableRow key={item.detectableAppName} label={item.detectableAppName} subLabel={`Game ID: ${item.gameId} — ${item.detected ? "Detected" : "Not detected"}${item.lastScannedAt != null ? ` (scanned ${new Date(item.lastScannedAt).toLocaleTimeString()})` : ""}`} disabled />)}
</TableRowGroup>
</View>
<View style={styles.section}>
<TableRowGroup title="Store State" hasIcons={false}>
<TableRow label="Presentable Guilds" subLabel={String(guildsCount)} disabled />
<TableRow label="Dismissed Guilds" subLabel={String(dismissedCount)} disabled />
<TableRow label="Last Fetched" subLabel={subLabel} disabled />
</TableRowGroup>
</View>
<View style={styles.section}>
<TableRowGroup title="Actions" hasIcons>
<TableRow label="Refresh Upsell Guilds" subLabel="Redects games and suggested guilds" onPress={callback} icon={<RefreshIcon />} trailing={<TableRowArrow />} />
<TableRow label="Clear Dismissed Guilds" subLabel="Reset dismissed guild IDs so all guilds show again" onPress={() => {
MobileGameCommunitiesStore.DEV_clearDismissedGuilds();
callback();
}} icon={<RefreshIcon />} trailing={<TableRowArrow />} />
<TableRow label="Clear All Store State" subLabel="Reset all MobileGameCommunitiesStore state (guilds, dismissed, fetch cache)" onPress={() => {
MobileGameCommunitiesStore.DEV_clearState();
}} icon={<RefreshIcon />} trailing={<TableRowArrow />} />
<TableRow label="Reset Upsell Animation" subLabel="Clear the dismissed state for the create button NUX animation so it can replay" onPress={() => {
removeDismissedContent(DismissibleContent.MOBILE_MULTI_GUILD_CREATE_UPSELL_ANIMATION);
resetDismissibleContentFrameworkStore();
}} icon={<RefreshIcon />} trailing={<TableRowArrow />} />
</TableRowGroup>
</View>
</ScrollView>
</View>;
};
useStyles = createStyles({
container: {
backgroundColor: Module712.colors.BACKGROUND_BASE_LOW,
flex: 1
},
scrollView: {
flex: 1
},
section: {
paddingHorizontal: Module712.space.PX_16,
paddingTop: Module712.space.PX_16,
paddingBottom: Module712.space.PX_8
}
});
export default function GameCommunityUpsellDevTools() {
return <MultiGuildDevTools />;
};