Files
wehub-resource-sync 2114b14ee0
Sync main into demo / sync (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:35:26 +08:00

55 lines
1.7 KiB
TypeScript

import React, { useCallback, useEffect, useRef } from 'react';
import { MemoryRouter, useLocation, UNSAFE_NavigationContext } from 'react-router-dom';
import { useAppNavigationHandler } from '../../os/hooks/useAppNavigationHandler';
import { themeToCssVars } from '../../os/utils/themeToCssVars';
import { applySkinToThemeColors } from '../../os/SkinService';
import { manifest } from './manifest';
import SheetPage from './pages/SheetPage';
// ── Navigation handler ──
const AnswerSheetNavigationHandler: React.FC = () => {
const location = useLocation();
const { navigator } = React.useContext(UNSAFE_NavigationContext);
const historyIndexRef = useRef(0);
useEffect(() => {
const memoryNavigator = navigator as any;
if (typeof memoryNavigator.index === 'number') {
historyIndexRef.current = memoryNavigator.index;
}
}, [location, navigator]);
const handleBackPress = useCallback((): boolean => {
const memoryNavigator = navigator as any;
const currentIndex =
typeof memoryNavigator.index === 'number'
? memoryNavigator.index
: historyIndexRef.current;
if (currentIndex > 0) {
memoryNavigator.go(-1);
return true;
}
return false;
}, [navigator]);
useAppNavigationHandler('answer_sheet', { onBack: handleBackPress });
return null;
};
// ── App entry point ──
const AnswerSheetApp: React.FC = () => {
const themeColors = manifest.theme.colors;
const cssVars = themeToCssVars(applySkinToThemeColors(themeColors));
return (
<div className="h-full w-full" style={cssVars as React.CSSProperties}>
<MemoryRouter>
<AnswerSheetNavigationHandler />
<SheetPage />
</MemoryRouter>
</div>
);
};
export default AnswerSheetApp;