fix(space): stabilize unfinished end session close
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { cn } from '@/shared/lib/cn';
|
||||
import type { CompletionResult } from '@/features/focus-session';
|
||||
|
||||
@@ -30,19 +30,25 @@ export const EndSessionConfirmModal = ({
|
||||
const [stage, setStage] = useState<EndSessionStage>('decision');
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [result, setResult] = useState<CompletionResult | null>(null);
|
||||
const resetTimerRef = useRef<number | null>(null);
|
||||
|
||||
const trimmedGoal = currentGoal.trim() || '목표 없음';
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) {
|
||||
setTimeout(() => {
|
||||
resetTimerRef.current = window.setTimeout(() => {
|
||||
setStage('decision');
|
||||
setResult(null);
|
||||
}, 500); // Reset after close animation
|
||||
}, 500);
|
||||
setIsSubmitting(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (resetTimerRef.current !== null) {
|
||||
window.clearTimeout(resetTimerRef.current);
|
||||
resetTimerRef.current = null;
|
||||
}
|
||||
|
||||
const handleEscape = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape' && !isSubmitting) {
|
||||
onClose();
|
||||
@@ -50,9 +56,19 @@ export const EndSessionConfirmModal = ({
|
||||
};
|
||||
|
||||
window.addEventListener('keydown', handleEscape);
|
||||
return () => window.removeEventListener('keydown', handleEscape);
|
||||
return () => {
|
||||
window.removeEventListener('keydown', handleEscape);
|
||||
};
|
||||
}, [open, isSubmitting, onClose]);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (resetTimerRef.current !== null) {
|
||||
window.clearTimeout(resetTimerRef.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
const handleFinish = async () => {
|
||||
if (isSubmitting) return;
|
||||
setIsSubmitting(true);
|
||||
@@ -263,4 +279,4 @@ export const EndSessionConfirmModal = ({
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -326,18 +326,21 @@ export const SpaceWorkspaceWidget = () => {
|
||||
if (pendingCompletionResult) {
|
||||
setPendingCompletionResult(null);
|
||||
setCurrentSessionThoughts([]);
|
||||
void router.replace('/app');
|
||||
return true;
|
||||
}
|
||||
|
||||
const completionResult = await controls.handleManualEnd();
|
||||
if (completionResult) {
|
||||
setPendingCompletionResult(completionResult);
|
||||
setCurrentSessionThoughts([]);
|
||||
void router.replace('/app');
|
||||
return true;
|
||||
} else {
|
||||
// If no result (cancelled or error), still try to go back if session is gone
|
||||
if (!currentSession) router.replace('/app');
|
||||
if (!currentSession) {
|
||||
void router.replace('/app');
|
||||
}
|
||||
}
|
||||
return Boolean(completionResult);
|
||||
return false;
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
Reference in New Issue
Block a user