refactor: replace window.confirm with a double-click UI confirmation for the clear session button and enhance its styling.
All checks were successful
Build and Deploy / build (push) Successful in 1m38s
All checks were successful
Build and Deploy / build (push) Successful in 1m38s
This commit is contained in:
@@ -1 +1,7 @@
|
||||
# Development Status (Central)
|
||||
|
||||
## Active Tasks
|
||||
- [x] Enable Clear Session Button (2025-12-20)
|
||||
|
||||
## Devlog Index
|
||||
- [Enable Clear Session](./devlog/2025-12-20-014500_enable_clear_session.md) - Improved UI/UX for session clearing in CubeManager.
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
# Enable Clear Session Button in Pack Generator
|
||||
|
||||
## Object
|
||||
Enable and improve the "Clear Session" button in the Cube Manager (Pack Generator) to allow users to restart the generation process from a clean state.
|
||||
|
||||
## Changes
|
||||
- Modified `CubeManager.tsx`:
|
||||
- Updated `handleReset` logic (verified).
|
||||
- enhanced "Clear Session" button styling to be more visible (red border/text) and indicate its destructive nature.
|
||||
- Added `disabled={loading}` to prevent state conflicts during active operations.
|
||||
- **Replaced `window.confirm` with a double-click UI confirmation pattern** to ensure reliability and better UX (fixed issue where native confirmation dialog was failing).
|
||||
|
||||
## Status
|
||||
- [x] Implementation complete.
|
||||
- [x] Verified logic for `localStorage` clearing.
|
||||
- [x] Verified interaction in browser (button changes state, clears data on second click).
|
||||
@@ -26,6 +26,7 @@ export const CubeManager: React.FC<CubeManagerProps> = ({ packs, setPacks, avail
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [progress, setProgress] = useState('');
|
||||
const [copySuccess, setCopySuccess] = useState(false);
|
||||
const [confirmClear, setConfirmClear] = useState(false);
|
||||
|
||||
const [rawScryfallData, setRawScryfallData] = useState<ScryfallCard[] | null>(() => {
|
||||
try {
|
||||
@@ -442,46 +443,54 @@ export const CubeManager: React.FC<CubeManagerProps> = ({ packs, setPacks, avail
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
if (window.confirm("Are you sure you want to clear this session? All parsed cards and generated packs will be lost.")) {
|
||||
try {
|
||||
console.log("Clearing session...");
|
||||
if (!confirmClear) {
|
||||
setConfirmClear(true);
|
||||
// Auto-reset confirmation state after 3 seconds
|
||||
setTimeout(() => setConfirmClear(false), 3000);
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. Reset Parent State (App.tsx)
|
||||
setPacks([]);
|
||||
setAvailableLands([]);
|
||||
// Confirmed
|
||||
setConfirmClear(false);
|
||||
|
||||
// 2. Explicitly clear parent persistence keys to ensure they are gone immediately
|
||||
localStorage.removeItem('generatedPacks');
|
||||
localStorage.removeItem('availableLands');
|
||||
try {
|
||||
console.log("Clearing session...");
|
||||
|
||||
// 3. Reset Local State to Defaults
|
||||
// This will trigger the useEffect hooks to update localStorage accordingly
|
||||
setInputText('');
|
||||
setRawScryfallData(null);
|
||||
setProcessedData(null);
|
||||
setSelectedSets([]);
|
||||
setSearchTerm(''); // Clear search
|
||||
// 1. Reset Parent State (App.tsx)
|
||||
setPacks([]);
|
||||
setAvailableLands([]);
|
||||
|
||||
setFilters({
|
||||
ignoreBasicLands: false,
|
||||
ignoreCommander: false,
|
||||
ignoreTokens: false
|
||||
});
|
||||
// 2. Explicitly clear parent persistence keys to ensure they are gone immediately
|
||||
localStorage.removeItem('generatedPacks');
|
||||
localStorage.removeItem('availableLands');
|
||||
|
||||
setGenSettings({
|
||||
mode: 'mixed',
|
||||
rarityMode: 'peasant'
|
||||
});
|
||||
// 3. Reset Local State to Defaults
|
||||
// This will trigger the useEffect hooks to update localStorage accordingly
|
||||
setInputText('');
|
||||
setRawScryfallData(null);
|
||||
setProcessedData(null);
|
||||
setSelectedSets([]);
|
||||
setSearchTerm(''); // Clear search
|
||||
|
||||
setSourceMode('upload');
|
||||
setNumBoxes(1);
|
||||
setGameTypeFilter('all');
|
||||
setFilters({
|
||||
ignoreBasicLands: false,
|
||||
ignoreCommander: false,
|
||||
ignoreTokens: false
|
||||
});
|
||||
|
||||
showToast("Session cleared successfully.", "success");
|
||||
} catch (error) {
|
||||
console.error("Error clearing session:", error);
|
||||
showToast("Failed to clear session fully.", "error");
|
||||
}
|
||||
setGenSettings({
|
||||
mode: 'mixed',
|
||||
rarityMode: 'peasant'
|
||||
});
|
||||
|
||||
setSourceMode('upload');
|
||||
setNumBoxes(1);
|
||||
setGameTypeFilter('all');
|
||||
|
||||
showToast("Session cleared successfully.", "success");
|
||||
} catch (error) {
|
||||
console.error("Error clearing session:", error);
|
||||
showToast("Failed to clear session fully.", "error");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -782,10 +791,17 @@ export const CubeManager: React.FC<CubeManagerProps> = ({ packs, setPacks, avail
|
||||
{/* Reset Button */}
|
||||
<button
|
||||
onClick={handleReset}
|
||||
className="w-full mt-4 py-2 text-xs font-semibold text-slate-500 hover:text-red-400 hover:bg-red-900/10 rounded-lg transition-colors flex items-center justify-center gap-2"
|
||||
disabled={loading}
|
||||
className={`w-full mt-4 py-2.5 px-4 rounded-lg text-xs font-bold transition-all flex items-center justify-center gap-2 ${loading
|
||||
? 'opacity-50 cursor-not-allowed text-slate-600 border border-transparent'
|
||||
: confirmClear
|
||||
? 'bg-red-600 text-white border border-red-500 shadow-md animate-pulse'
|
||||
: 'text-red-400 border border-red-900/30 hover:bg-red-950/30 hover:border-red-500/50 hover:text-red-300 shadow-sm'
|
||||
}`}
|
||||
title="Clear all data and start over"
|
||||
>
|
||||
<Trash2 className="w-3 h-3" /> Clear Session
|
||||
{loading ? <Loader2 className="w-3 h-3 animate-spin" /> : <Trash2 className="w-3 h-3" />}
|
||||
{confirmClear ? "Click again to confirm!" : "Clear Session"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user