File size: 5,915 Bytes
d9a16d6 3b88621 5686111 d9a16d6 cf76e1a d9a16d6 486eff6 3b88621 d9a16d6 5686111 d9a16d6 cf76e1a 486eff6 d9a16d6 486eff6 5686111 d9a16d6 486eff6 eb7f5ba cf76e1a 486eff6 d9a16d6 cf76e1a d9a16d6 486eff6 3b88621 5686111 d9a16d6 245c727 cf76e1a 486eff6 d9a16d6 5686111 d9a16d6 cf76e1a d9a16d6 eb7f5ba 3b88621 eb7f5ba 3b88621 eb7f5ba d9a16d6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
import React, { useState, useEffect } from 'react';
import TopicSelector from './components/TopicSelector';
import PuzzleGrid from './components/PuzzleGrid';
import ClueList from './components/ClueList';
import DebugTab from './components/DebugTab';
import AdvancedSettings from './components/AdvancedSettings';
import LoadingSpinner from './components/LoadingSpinner';
import useCrossword from './hooks/useCrossword';
import './styles/puzzle.css';
function App() {
const [selectedTopics, setSelectedTopics] = useState([]);
const [customTopics, setCustomTopics] = useState([]);
const [difficulty, setDifficulty] = useState('medium');
const [showSolution, setShowSolution] = useState(false);
const [customSentence, setCustomSentence] = useState('');
const [multiTheme, setMultiTheme] = useState(true);
const [activeTab, setActiveTab] = useState('puzzle');
// Advanced settings state
const [similarityTemperature, setSimilarityTemperature] = useState(0.2);
const [difficultyWeight, setDifficultyWeight] = useState(0.5);
const {
puzzle,
loading,
error,
topics,
fetchTopics,
generatePuzzle,
resetPuzzle
} = useCrossword();
useEffect(() => {
fetchTopics();
}, [fetchTopics]);
const handleGeneratePuzzle = async () => {
// Combine predefined and custom topics
const allTopics = [...selectedTopics, ...customTopics.filter(t => t.trim())];
if (allTopics.length === 0 && !customSentence.trim()) {
alert('Please select at least one topic or provide a custom sentence');
return;
}
setShowSolution(false);
await generatePuzzle(allTopics, difficulty, false, customSentence, multiTheme, {
similarityTemperature,
difficultyWeight
});
};
const handleTopicsChange = (topics) => {
setSelectedTopics(topics);
};
const handleSentenceChange = (sentence) => {
setCustomSentence(sentence);
};
const handleMultiThemeChange = (enabled) => {
setMultiTheme(enabled);
};
const handleCustomTopicsChange = (topics) => {
setCustomTopics(topics);
};
const handleReset = () => {
resetPuzzle();
setSelectedTopics([]);
setCustomTopics([]);
setShowSolution(false);
setDifficulty('medium');
setCustomSentence('');
setMultiTheme(true);
setActiveTab('puzzle');
setSimilarityTemperature(0.2);
setDifficultyWeight(0.5);
};
const handleRevealSolution = () => {
setShowSolution(true);
};
return (
<div className="crossword-app">
<header className="app-header">
<h1 className="app-title">Crossword Puzzle Generator</h1>
<p>Select topics and generate your custom crossword puzzle!</p>
</header>
<TopicSelector
onTopicsChange={handleTopicsChange}
availableTopics={topics}
selectedTopics={selectedTopics}
customTopics={customTopics}
onCustomTopicsChange={handleCustomTopicsChange}
customSentence={customSentence}
onSentenceChange={handleSentenceChange}
multiTheme={multiTheme}
onMultiThemeChange={handleMultiThemeChange}
/>
<AdvancedSettings
similarityTemperature={similarityTemperature}
onTemperatureChange={setSimilarityTemperature}
difficultyWeight={difficultyWeight}
onWeightChange={setDifficultyWeight}
/>
<div className="puzzle-controls">
<select
value={difficulty}
onChange={(e) => setDifficulty(e.target.value)}
className="control-btn"
>
<option value="easy">Easy</option>
<option value="medium">Medium</option>
<option value="hard">Hard</option>
</select>
<button
onClick={handleGeneratePuzzle}
disabled={loading || (selectedTopics.length === 0 && customTopics.filter(t => t.trim()).length === 0 && !customSentence.trim())}
className="control-btn generate-btn"
>
{loading ? 'Generating...' : 'Generate Puzzle'}
</button>
<button
onClick={handleReset}
className="control-btn reset-btn"
>
Reset
</button>
{puzzle && !showSolution && (
<button
onClick={handleRevealSolution}
className="control-btn reveal-btn"
>
Reveal Solution
</button>
)}
</div>
{error && (
<div className="error-message">
Error: {error}
</div>
)}
{loading && <LoadingSpinner />}
{puzzle && !loading && (
<>
{/* Tab Navigation */}
<div className="tab-nav">
<button
className={`tab-btn ${activeTab === 'puzzle' ? 'active' : ''}`}
onClick={() => setActiveTab('puzzle')}
>
Puzzle
</button>
{puzzle.debug && (
<button
className={`tab-btn ${activeTab === 'debug' ? 'active' : ''}`}
onClick={() => setActiveTab('debug')}
>
Debug
</button>
)}
</div>
{/* Tab Content */}
{activeTab === 'puzzle' && (
<div className="puzzle-layout">
<PuzzleGrid
grid={puzzle.grid}
clues={puzzle.clues}
showSolution={showSolution}
/>
<ClueList clues={puzzle.clues} />
</div>
)}
{activeTab === 'debug' && puzzle.debug && (
<DebugTab debugData={puzzle.debug} />
)}
</>
)}
{!puzzle && !loading && !error && (
<div style={{ textAlign: 'center', padding: '40px', color: '#7f8c8d' }}>
Select topics and click "Generate Puzzle" to start!
</div>
)}
</div>
);
}
export default App; |