Flesh out payment stuff

This commit is contained in:
Joey Yakimowich-Payne 2026-01-22 12:21:12 -07:00
commit acfed861ab
No known key found for this signature in database
GPG key ID: 6BFE655FA5ABD1E1
27 changed files with 938 additions and 173 deletions

17
App.tsx
View file

@ -1,9 +1,10 @@
import React, { useState } from 'react';
import { useAuth } from 'react-oidc-context';
import { useLocation } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router-dom';
import { useGame } from './hooks/useGame';
import { useQuizLibrary } from './hooks/useQuizLibrary';
import { useUserConfig } from './hooks/useUserConfig';
import { useUserPreferences } from './hooks/useUserPreferences';
import { Landing } from './components/Landing';
import { Lobby } from './components/Lobby';
import { GameScreen } from './components/GameScreen';
@ -50,8 +51,11 @@ const FloatingShapes = React.memo(() => {
function App() {
const auth = useAuth();
const location = useLocation();
const navigate = useNavigate();
const { saveQuiz, updateQuiz, saving } = useQuizLibrary();
const { defaultConfig } = useUserConfig();
const { subscription } = useUserPreferences();
const maxPlayersLimit = (!subscription || subscription.accessType === 'none') ? 10 : 150;
const [showSaveOptions, setShowSaveOptions] = useState(false);
const [pendingEditedQuiz, setPendingEditedQuiz] = useState<Quiz | null>(null);
const {
@ -99,7 +103,7 @@ function App() {
sendAdvance,
kickPlayer,
leaveGame
} = useGame();
} = useGame(defaultConfig);
const handleSaveQuiz = async () => {
if (!pendingQuizToSave) return;
@ -121,6 +125,7 @@ function App() {
const source = pendingQuizToSave?.topic ? 'ai_generated' : 'manual';
const topic = pendingQuizToSave?.topic || undefined;
await saveQuiz(editedQuiz, source, topic);
dismissSavePrompt();
}
}
};
@ -130,6 +135,7 @@ function App() {
await updateQuiz(sourceQuizId, pendingEditedQuiz);
setShowSaveOptions(false);
setPendingEditedQuiz(null);
dismissSavePrompt();
};
const handleSaveAsNew = async () => {
@ -137,6 +143,7 @@ function App() {
await saveQuiz(pendingEditedQuiz, 'manual');
setShowSaveOptions(false);
setPendingEditedQuiz(null);
dismissSavePrompt();
};
const currentQ = quiz?.questions[currentQuestionIndex];
@ -153,8 +160,7 @@ function App() {
const isPaymentCancelRoute = location.pathname === '/payment/cancel' && gameState === 'LANDING';
const navigateHome = () => {
window.history.replaceState({}, document.title, '/');
window.location.reload();
navigate('/', { replace: true });
};
if (isUpgradeRoute) {
@ -212,6 +218,7 @@ function App() {
onBack={backFromEditor}
showSaveButton={auth.isAuthenticated}
defaultConfig={defaultConfig}
maxPlayersLimit={maxPlayersLimit}
/>
) : null}
@ -362,4 +369,4 @@ function App() {
);
}
export default App;
export default App;