UNPKG

@steambrew/client

Version:
54 lines (53 loc) 2.04 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { createElement, useEffect, useState } from 'react'; import { fakeRenderComponent, findInReactTree, sleep } from '../utils'; import { findModuleByExport } from '../webpack'; import { SteamSpinner } from './SteamSpinner'; let tabsComponent; const getTabs = async () => { if (tabsComponent) return tabsComponent; // @ts-ignore while (!window?.DeckyPluginLoader?.routerHook?.routes) { console.debug('[Millennium:Tabs]: Waiting for Millennium router...'); await sleep(500); } return (tabsComponent = fakeRenderComponent(() => { return findInReactTree(findInReactTree( // @ts-ignore window.DeckyPluginLoader.routerHook.routes.find((x) => x.props.path == '/library/app/:appid/achievements').props.children.type(), (x) => x?.props?.scrollTabsTop).type({ appid: 1 }), (x) => x?.props?.tabs).type; }, { useRef: () => ({ current: { reaction: { track: () => { } } } }), useContext: () => ({ match: { params: { appid: 1 } } }), useMemo: () => ({ data: {} }), })); }; let oldTabs; try { const oldTabsModule = findModuleByExport((e) => e.Unbleed); if (oldTabsModule) oldTabs = Object.values(oldTabsModule).find((x) => x?.type?.toString()?.includes('((function(){')); } catch (e) { console.error('Error finding oldTabs:', e); } /** * Tabs component as used in the library and media tabs. See {@link TabsProps}. */ export const Tabs = (oldTabs || ((props) => { const found = tabsComponent; const [tc, setTC] = useState(found); useEffect(() => { if (found) return; (async () => { console.debug('[DFL:Tabs]: Finding component...'); const t = await getTabs(); console.debug('[DFL:Tabs]: Found!'); setTC(t); })(); }, []); console.log('tc', tc); return tc ? createElement(tc, props) : _jsx(SteamSpinner, {}); }));