feat(space): 종료 결과 모달과 current session thought 복원 추가
This commit is contained in:
@@ -7,6 +7,20 @@ import type { RecentThought } from './types';
|
||||
|
||||
const MAX_THOUGHT_INBOX_ITEMS = 40;
|
||||
|
||||
const normalizeThought = (thought: {
|
||||
id: string;
|
||||
text: string;
|
||||
sceneName: string;
|
||||
isCompleted: boolean;
|
||||
capturedAt: string;
|
||||
}): RecentThought => ({
|
||||
id: thought.id,
|
||||
text: thought.text,
|
||||
sceneName: thought.sceneName,
|
||||
isCompleted: thought.isCompleted,
|
||||
capturedAt: thought.capturedAt,
|
||||
});
|
||||
|
||||
export const useThoughtInbox = () => {
|
||||
const [thoughts, setThoughts] = useState<RecentThought[]>([]);
|
||||
|
||||
@@ -16,15 +30,7 @@ export const useThoughtInbox = () => {
|
||||
inboxApi.getThoughts()
|
||||
.then((data) => {
|
||||
if (!mounted) return;
|
||||
setThoughts(
|
||||
data.map((d) => ({
|
||||
id: d.id,
|
||||
text: d.text,
|
||||
sceneName: d.sceneName,
|
||||
isCompleted: d.isCompleted,
|
||||
capturedAt: copy.session.justNow,
|
||||
}))
|
||||
);
|
||||
setThoughts(data.map(normalizeThought));
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Failed to load inbox thoughts:', err);
|
||||
@@ -35,7 +41,7 @@ export const useThoughtInbox = () => {
|
||||
};
|
||||
}, []);
|
||||
|
||||
const addThought = useCallback((text: string, sceneName: string) => {
|
||||
const addThought = useCallback(async (text: string, sceneName: string) => {
|
||||
const trimmedText = text.trim();
|
||||
|
||||
if (!trimmedText) {
|
||||
@@ -57,18 +63,20 @@ export const useThoughtInbox = () => {
|
||||
return next;
|
||||
});
|
||||
|
||||
inboxApi.addThought({ text: trimmedText, sceneName })
|
||||
.then((res) => {
|
||||
setThoughts((current) =>
|
||||
current.map((t) => (t.id === tempId ? { ...t, id: res.id } : t))
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Failed to add thought:', err);
|
||||
setThoughts((current) => current.filter((t) => t.id !== tempId));
|
||||
});
|
||||
try {
|
||||
const response = await inboxApi.addThought({ text: trimmedText, sceneName });
|
||||
const normalized = normalizeThought(response);
|
||||
|
||||
return thought;
|
||||
setThoughts((current) =>
|
||||
current.map((t) => (t.id === tempId ? normalized : t))
|
||||
);
|
||||
|
||||
return normalized;
|
||||
} catch (err) {
|
||||
console.error('Failed to add thought:', err);
|
||||
setThoughts((current) => current.filter((t) => t.id !== tempId));
|
||||
return null;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const removeThought = useCallback((thoughtId: string) => {
|
||||
@@ -140,15 +148,7 @@ export const useThoughtInbox = () => {
|
||||
return inboxApi.getThoughts();
|
||||
})
|
||||
.then((data) => {
|
||||
setThoughts(
|
||||
data.map((d) => ({
|
||||
id: d.id,
|
||||
text: d.text,
|
||||
sceneName: d.sceneName,
|
||||
isCompleted: d.isCompleted,
|
||||
capturedAt: copy.session.justNow,
|
||||
}))
|
||||
);
|
||||
setThoughts(data.map(normalizeThought));
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Failed to restore thoughts:', err);
|
||||
|
||||
@@ -31,6 +31,22 @@ interface RawAdvanceCurrentGoalResponse {
|
||||
updatedPlanToday: Parameters<typeof normalizeFocusPlanToday>[0];
|
||||
}
|
||||
|
||||
interface RawCurrentSessionThought {
|
||||
id: string;
|
||||
text: string;
|
||||
sceneName: string;
|
||||
isCompleted: boolean;
|
||||
capturedAt: string;
|
||||
}
|
||||
|
||||
interface RawCompletionResult {
|
||||
completedSessionId: string;
|
||||
completionSource: 'timer-complete' | 'manual-end';
|
||||
completedGoal: string;
|
||||
focusedSeconds: number;
|
||||
thoughts: RawCurrentSessionThought[];
|
||||
}
|
||||
|
||||
export interface FocusSession {
|
||||
id: string;
|
||||
sceneId: string;
|
||||
@@ -52,6 +68,22 @@ export interface FocusSession {
|
||||
serverNow: string;
|
||||
}
|
||||
|
||||
export interface CurrentSessionThought {
|
||||
id: string;
|
||||
text: string;
|
||||
sceneName: string;
|
||||
isCompleted: boolean;
|
||||
capturedAt: string;
|
||||
}
|
||||
|
||||
export interface CompletionResult {
|
||||
completedSessionId: string;
|
||||
completionSource: 'timer-complete' | 'manual-end';
|
||||
completedGoal: string;
|
||||
focusedSeconds: number;
|
||||
thoughts: CurrentSessionThought[];
|
||||
}
|
||||
|
||||
export interface StartFocusSessionRequest {
|
||||
sceneId: string;
|
||||
goal: string;
|
||||
@@ -126,6 +158,23 @@ const normalizeAdvanceGoalResponse = (
|
||||
};
|
||||
};
|
||||
|
||||
const normalizeCurrentSessionThought = (
|
||||
thought: RawCurrentSessionThought,
|
||||
): CurrentSessionThought => {
|
||||
return {
|
||||
...thought,
|
||||
};
|
||||
};
|
||||
|
||||
const normalizeCompletionResult = (
|
||||
result: RawCompletionResult,
|
||||
): CompletionResult => {
|
||||
return {
|
||||
...result,
|
||||
thoughts: result.thoughts.map(normalizeCurrentSessionThought),
|
||||
};
|
||||
};
|
||||
|
||||
export const focusSessionApi = {
|
||||
getCurrentSession: async (): Promise<FocusSession | null> => {
|
||||
const response = await apiClient<RawFocusSession | null>('api/v1/focus-sessions/current', {
|
||||
@@ -135,6 +184,14 @@ export const focusSessionApi = {
|
||||
return response ? normalizeFocusSession(response) : null;
|
||||
},
|
||||
|
||||
getCurrentSessionThoughts: async (): Promise<CurrentSessionThought[]> => {
|
||||
const response = await apiClient<RawCurrentSessionThought[]>('api/v1/focus-sessions/current/thoughts', {
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
return response.map(normalizeCurrentSessionThought);
|
||||
},
|
||||
|
||||
startSession: async (payload: StartFocusSessionRequest): Promise<FocusSession> => {
|
||||
const response = await apiClient<RawFocusSession>('api/v1/focus-sessions', {
|
||||
method: 'POST',
|
||||
@@ -202,13 +259,13 @@ export const focusSessionApi = {
|
||||
return normalizeFocusSession(response);
|
||||
},
|
||||
|
||||
completeSession: async (payload: CompleteFocusSessionRequest): Promise<FocusSession> => {
|
||||
const response = await apiClient<RawFocusSession>('api/v1/focus-sessions/current/complete', {
|
||||
completeSession: async (payload: CompleteFocusSessionRequest): Promise<CompletionResult> => {
|
||||
const response = await apiClient<RawCompletionResult>('api/v1/focus-sessions/current/complete', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
return normalizeFocusSession(response);
|
||||
return normalizeCompletionResult(response);
|
||||
},
|
||||
|
||||
advanceGoal: async (payload: AdvanceCurrentGoalRequest): Promise<AdvanceCurrentGoalResponse> => {
|
||||
|
||||
@@ -5,6 +5,7 @@ import { copy } from '@/shared/i18n';
|
||||
import {
|
||||
type AdvanceCurrentGoalRequest,
|
||||
type AdvanceCurrentGoalResponse,
|
||||
type CompletionResult,
|
||||
focusSessionApi,
|
||||
type CompleteFocusSessionRequest,
|
||||
type FocusSession,
|
||||
@@ -76,7 +77,7 @@ interface UseFocusSessionEngineResult {
|
||||
extendCurrentPhase: (payload: { additionalMinutes: number }) => Promise<FocusSession | null>;
|
||||
updateCurrentIntent: (payload: UpdateCurrentFocusSessionIntentRequest) => Promise<FocusSession | null>;
|
||||
updateCurrentSelection: (payload: UpdateCurrentFocusSessionSelectionRequest) => Promise<FocusSession | null>;
|
||||
completeSession: (payload: CompleteFocusSessionRequest) => Promise<FocusSession | null>;
|
||||
completeSession: (payload: CompleteFocusSessionRequest) => Promise<CompletionResult | null>;
|
||||
advanceGoal: (payload: AdvanceCurrentGoalRequest) => Promise<AdvanceCurrentGoalResponse | null>;
|
||||
abandonSession: () => Promise<boolean>;
|
||||
clearError: () => void;
|
||||
@@ -279,16 +280,16 @@ export const useFocusSessionEngine = (): UseFocusSessionEngineResult => {
|
||||
return null;
|
||||
}
|
||||
|
||||
const session = await runMutation(
|
||||
const result = await runMutation(
|
||||
() => focusSessionApi.completeSession(payload),
|
||||
copy.focusSession.completeFailed,
|
||||
);
|
||||
|
||||
if (session) {
|
||||
if (result) {
|
||||
applySession(null);
|
||||
}
|
||||
|
||||
return session;
|
||||
return result;
|
||||
},
|
||||
advanceGoal: async (payload) => {
|
||||
if (!currentSession) {
|
||||
|
||||
@@ -122,6 +122,17 @@ export const space = {
|
||||
confirmPending: '시작 중…',
|
||||
finishPending: '마무리 중…',
|
||||
},
|
||||
completionResult: {
|
||||
eyebrow: 'SESSION COMPLETE',
|
||||
title: '이번 세션을 조용히 닫아둘게요.',
|
||||
description: '얼마나 집중했는지, 무엇을 끝냈는지, 생각 캡슐에 남긴 것까지 한 번에 정리해둡니다.',
|
||||
focusedLabel: '집중한 시간',
|
||||
focusedValue: (minutes: number) => `${minutes}분`,
|
||||
goalLabel: '완료한 목표',
|
||||
thoughtsLabel: '이번 세션 생각 캡슐',
|
||||
thoughtCount: (count: number) => `${count}개`,
|
||||
confirmButton: '확인하고 돌아가기',
|
||||
},
|
||||
controlCenter: {
|
||||
sectionTitles: {
|
||||
background: 'Background',
|
||||
|
||||
138
src/widgets/space-focus-hud/ui/CompletionResultModal.tsx
Normal file
138
src/widgets/space-focus-hud/ui/CompletionResultModal.tsx
Normal file
@@ -0,0 +1,138 @@
|
||||
'use client';
|
||||
|
||||
import { copy } from '@/shared/i18n';
|
||||
import { cn } from '@/shared/lib/cn';
|
||||
import type { CompletionResult } from '@/features/focus-session';
|
||||
|
||||
interface CompletionResultModalProps {
|
||||
open: boolean;
|
||||
result: CompletionResult | null;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
const formatFocusedMinutes = (focusedSeconds: number) => {
|
||||
const safeSeconds = Math.max(0, focusedSeconds);
|
||||
return Math.round(safeSeconds / 60);
|
||||
};
|
||||
|
||||
export const CompletionResultModal = ({
|
||||
open,
|
||||
result,
|
||||
onClose,
|
||||
}: CompletionResultModalProps) => {
|
||||
if (!result) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const focusedMinutes = formatFocusedMinutes(result.focusedSeconds);
|
||||
const hasThoughts = result.thoughts.length > 0;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'pointer-events-none fixed inset-0 z-[70] flex items-center justify-center px-4 transition-all duration-300 ease-[cubic-bezier(0.16,1,0.3,1)]',
|
||||
open ? 'opacity-100' : 'opacity-0',
|
||||
)}
|
||||
aria-hidden={!open}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
'absolute inset-0 bg-[radial-gradient(circle_at_center,rgba(5,7,11,0.22)_0%,rgba(2,6,23,0.68)_52%,rgba(2,6,23,0.84)_100%)] backdrop-blur-[14px] transition-opacity duration-300',
|
||||
open ? 'opacity-100' : 'opacity-0',
|
||||
)}
|
||||
/>
|
||||
|
||||
<section
|
||||
className={cn(
|
||||
'relative w-full max-w-[38rem] overflow-hidden rounded-[32px] border border-white/12 bg-[linear-gradient(180deg,rgba(18,22,30,0.96)_0%,rgba(8,11,17,0.94)_100%)] text-white shadow-[0_30px_100px_rgba(2,6,23,0.5)] transition-all duration-300 ease-[cubic-bezier(0.16,1,0.3,1)]',
|
||||
open ? 'pointer-events-auto translate-y-0 scale-100' : 'pointer-events-none translate-y-4 scale-[0.975]',
|
||||
)}
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="completion-result-title"
|
||||
>
|
||||
<div
|
||||
aria-hidden
|
||||
className="pointer-events-none absolute inset-0 bg-[radial-gradient(100%_85%_at_50%_0%,rgba(255,255,255,0.12)_0%,rgba(255,255,255,0.02)_42%,rgba(255,255,255,0)_100%)]"
|
||||
/>
|
||||
<div className="relative px-7 py-7 md:px-9 md:py-8">
|
||||
<header className="text-center">
|
||||
<div className="mx-auto flex h-14 w-14 items-center justify-center rounded-[18px] border border-white/10 bg-white/[0.06] shadow-[inset_0_1px_0_rgba(255,255,255,0.08)]">
|
||||
<span className="text-[20px] text-white/88">✦</span>
|
||||
</div>
|
||||
<p className="mt-5 text-[11px] font-medium tracking-[0.14em] text-white/34">
|
||||
{copy.space.completionResult.eyebrow}
|
||||
</p>
|
||||
<h3
|
||||
id="completion-result-title"
|
||||
className="mx-auto mt-2 max-w-[24rem] text-[1.65rem] font-light leading-[1.16] tracking-[-0.03em] text-white/96 md:text-[1.9rem]"
|
||||
>
|
||||
{copy.space.completionResult.title}
|
||||
</h3>
|
||||
<p className="mx-auto mt-3 max-w-[28rem] text-[14px] leading-[1.7] text-white/56">
|
||||
{copy.space.completionResult.description}
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<div className="mt-7 grid gap-4">
|
||||
<div className="rounded-[28px] border border-white/8 bg-black/16 px-5 py-5 text-center shadow-[inset_0_1px_0_rgba(255,255,255,0.05)]">
|
||||
<p className="text-[11px] font-medium uppercase tracking-[0.18em] text-white/34">
|
||||
{copy.space.completionResult.focusedLabel}
|
||||
</p>
|
||||
<p className="mt-3 text-[2.6rem] font-light tracking-[-0.05em] text-white/96 md:text-[3.2rem]">
|
||||
{copy.space.completionResult.focusedValue(focusedMinutes)}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="rounded-[24px] border border-white/8 bg-black/14 px-5 py-4 shadow-[inset_0_1px_0_rgba(255,255,255,0.05)]">
|
||||
<p className="text-[10px] font-medium uppercase tracking-[0.22em] text-white/34">
|
||||
{copy.space.completionResult.goalLabel}
|
||||
</p>
|
||||
<p className="mt-2 text-[15px] font-medium leading-[1.45] tracking-[-0.01em] text-white/90">
|
||||
{result.completedGoal}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{hasThoughts ? (
|
||||
<div className="rounded-[24px] border border-white/8 bg-black/14 px-5 py-4 shadow-[inset_0_1px_0_rgba(255,255,255,0.05)]">
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<p className="text-[10px] font-medium uppercase tracking-[0.22em] text-white/34">
|
||||
{copy.space.completionResult.thoughtsLabel}
|
||||
</p>
|
||||
<p className="text-[11px] text-white/38">
|
||||
{copy.space.completionResult.thoughtCount(result.thoughts.length)}
|
||||
</p>
|
||||
</div>
|
||||
<div className="mt-3 space-y-2.5">
|
||||
{result.thoughts.map((thought) => (
|
||||
<div
|
||||
key={thought.id}
|
||||
className="rounded-[18px] border border-white/7 bg-white/[0.04] px-4 py-3"
|
||||
>
|
||||
<p className="text-[13px] leading-[1.6] text-white/84">
|
||||
{thought.text}
|
||||
</p>
|
||||
<p className="mt-2 text-[10px] uppercase tracking-[0.16em] text-white/32">
|
||||
{thought.sceneName}
|
||||
</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<footer className="mt-6 flex justify-center">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="inline-flex min-h-[3.5rem] min-w-[14rem] items-center justify-center rounded-[18px] border border-white/14 bg-white/[0.12] px-5 py-3 text-center text-[13px] font-medium tracking-[0.01em] text-white transition-all duration-200 hover:border-white/22 hover:bg-white/[0.17] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/12"
|
||||
>
|
||||
{copy.space.completionResult.confirmButton}
|
||||
</button>
|
||||
</footer>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { useCallback, useEffect, useRef } from 'react';
|
||||
import type { FocusSession } from '@/features/focus-session';
|
||||
import type { CompletionResult, FocusSession } from '@/features/focus-session';
|
||||
import { copy } from '@/shared/i18n';
|
||||
import type { HudStatusLinePayload } from '@/shared/lib/useHudStatusLine';
|
||||
import { findAtmosphereOptionForSelection } from '@/widgets/focus-dashboard/model/atmosphereEntry';
|
||||
@@ -47,7 +47,7 @@ interface UseSpaceWorkspaceSessionControlsParams {
|
||||
completedGoal?: string;
|
||||
focusScore?: number;
|
||||
distractionCount?: number;
|
||||
}) => Promise<FocusSession | null>;
|
||||
}) => Promise<CompletionResult | null>;
|
||||
advanceGoal: (input: {
|
||||
completedGoal: string;
|
||||
nextGoal: string;
|
||||
@@ -313,39 +313,33 @@ export const useSpaceWorkspaceSessionControls = ({
|
||||
const trimmedCurrentGoal = goalInput.trim();
|
||||
|
||||
if (!currentSession) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
const completedSession = await completeSession({
|
||||
const completionResult = await completeSession({
|
||||
completionType: 'goal-complete',
|
||||
completedGoal: trimmedCurrentGoal || undefined,
|
||||
});
|
||||
|
||||
if (!completedSession) {
|
||||
if (!completionResult) {
|
||||
pushStatusLine({
|
||||
message: copy.space.workspace.goalCompleteSyncFailed,
|
||||
});
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
setGoalInput('');
|
||||
setLinkedFocusPlanItemId(null);
|
||||
setSelectedGoalId(null);
|
||||
setShowResumePrompt(false);
|
||||
setPendingSessionEntryPoint('space-setup');
|
||||
setPreviewPlaybackState('paused');
|
||||
setWorkspaceMode('setup');
|
||||
return true;
|
||||
return completionResult;
|
||||
}, [
|
||||
completeSession,
|
||||
currentSession,
|
||||
goalInput,
|
||||
pushStatusLine,
|
||||
setGoalInput,
|
||||
setLinkedFocusPlanItemId,
|
||||
setPendingSessionEntryPoint,
|
||||
setPreviewPlaybackState,
|
||||
setSelectedGoalId,
|
||||
setShowResumePrompt,
|
||||
setWorkspaceMode,
|
||||
]);
|
||||
@@ -354,39 +348,33 @@ export const useSpaceWorkspaceSessionControls = ({
|
||||
const trimmedCurrentGoal = goalInput.trim();
|
||||
|
||||
if (!currentSession) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
const completedSession = await completeSession({
|
||||
const completionResult = await completeSession({
|
||||
completionType: 'timer-complete',
|
||||
completedGoal: trimmedCurrentGoal || undefined,
|
||||
});
|
||||
|
||||
if (!completedSession) {
|
||||
if (!completionResult) {
|
||||
pushStatusLine({
|
||||
message: copy.space.workspace.timerCompleteSyncFailed,
|
||||
});
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
setGoalInput('');
|
||||
setLinkedFocusPlanItemId(null);
|
||||
setSelectedGoalId(null);
|
||||
setShowResumePrompt(false);
|
||||
setPendingSessionEntryPoint('space-setup');
|
||||
setPreviewPlaybackState('paused');
|
||||
setWorkspaceMode('setup');
|
||||
return true;
|
||||
return completionResult;
|
||||
}, [
|
||||
completeSession,
|
||||
currentSession,
|
||||
goalInput,
|
||||
pushStatusLine,
|
||||
setGoalInput,
|
||||
setLinkedFocusPlanItemId,
|
||||
setPendingSessionEntryPoint,
|
||||
setPreviewPlaybackState,
|
||||
setSelectedGoalId,
|
||||
setShowResumePrompt,
|
||||
setWorkspaceMode,
|
||||
]);
|
||||
|
||||
@@ -9,7 +9,12 @@ import {
|
||||
import { usePlanTier } from "@/entities/plan";
|
||||
import { getSceneById, SCENE_THEMES } from "@/entities/scene";
|
||||
import { GOAL_CHIPS, SOUND_PRESETS, useThoughtInbox } from "@/entities/session";
|
||||
import { useFocusSessionEngine } from "@/features/focus-session";
|
||||
import {
|
||||
focusSessionApi,
|
||||
type CompletionResult,
|
||||
type CurrentSessionThought,
|
||||
useFocusSessionEngine,
|
||||
} from "@/features/focus-session";
|
||||
import { useFocusStats } from "@/features/stats";
|
||||
import {
|
||||
useSoundPlayback,
|
||||
@@ -19,6 +24,7 @@ import { useHudStatusLine } from "@/shared/lib/useHudStatusLine";
|
||||
import { copy } from "@/shared/i18n";
|
||||
import { SpaceFocusHudWidget } from "@/widgets/space-focus-hud";
|
||||
import { SpaceSetupDrawerWidget } from "@/widgets/space-setup-drawer";
|
||||
import { CompletionResultModal } from "@/widgets/space-focus-hud/ui/CompletionResultModal";
|
||||
import {
|
||||
findAtmosphereOptionForSelection,
|
||||
getRecommendedDurationMinutes,
|
||||
@@ -83,6 +89,8 @@ export const SpaceWorkspaceWidget = () => {
|
||||
const [pendingSessionEntryPoint, setPendingSessionEntryPoint] =
|
||||
useState<SessionEntryPoint>("space-setup");
|
||||
const [showReviewTeaserAfterComplete, setShowReviewTeaserAfterComplete] = useState(false);
|
||||
const [, setCurrentSessionThoughts] = useState<CurrentSessionThought[]>([]);
|
||||
const [pendingCompletionResult, setPendingCompletionResult] = useState<CompletionResult | null>(null);
|
||||
|
||||
const {
|
||||
selectedPresetId,
|
||||
@@ -107,10 +115,12 @@ export const SpaceWorkspaceWidget = () => {
|
||||
advanceGoal,
|
||||
abandonSession,
|
||||
} = useFocusSessionEngine();
|
||||
const isCompletionResultOpen = pendingCompletionResult !== null;
|
||||
|
||||
const isFocusMode = workspaceMode === "focus";
|
||||
const resolvedPlaybackState = currentSession?.state ?? previewPlaybackState;
|
||||
const shouldPlaySound = isFocusMode && resolvedPlaybackState === "running";
|
||||
const currentSessionId = currentSession?.id ?? null;
|
||||
|
||||
const { activeStatus, pushStatusLine, runActiveAction } =
|
||||
useHudStatusLine(isFocusMode);
|
||||
@@ -207,10 +217,10 @@ export const SpaceWorkspaceWidget = () => {
|
||||
: undefined;
|
||||
|
||||
useEffect(() => {
|
||||
if (!isBootstrapping && !currentSession) {
|
||||
if (!isBootstrapping && !currentSession && !pendingCompletionResult) {
|
||||
router.replace("/app");
|
||||
}
|
||||
}, [isBootstrapping, currentSession, router]);
|
||||
}, [isBootstrapping, currentSession, pendingCompletionResult, router]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isBootstrapping || didResolveEntryRouteRef.current) {
|
||||
@@ -224,6 +234,41 @@ export const SpaceWorkspaceWidget = () => {
|
||||
}
|
||||
}, [currentSession, isBootstrapping]);
|
||||
|
||||
useEffect(() => {
|
||||
let mounted = true;
|
||||
|
||||
const syncCurrentSessionThoughts = async () => {
|
||||
if (!currentSessionId) {
|
||||
if (!pendingCompletionResult && mounted) {
|
||||
setCurrentSessionThoughts([]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const thoughts = await focusSessionApi.getCurrentSessionThoughts();
|
||||
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
setCurrentSessionThoughts(thoughts);
|
||||
} catch {
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
setCurrentSessionThoughts([]);
|
||||
}
|
||||
};
|
||||
|
||||
void syncCurrentSessionThoughts();
|
||||
|
||||
return () => {
|
||||
mounted = false;
|
||||
};
|
||||
}, [currentSessionId, pendingCompletionResult]);
|
||||
|
||||
useEffect(() => {
|
||||
const preferMobile =
|
||||
typeof window !== "undefined"
|
||||
@@ -258,7 +303,7 @@ export const SpaceWorkspaceWidget = () => {
|
||||
</div>
|
||||
|
||||
<SpaceSetupDrawerWidget
|
||||
open={!isFocusMode}
|
||||
open={!isFocusMode && !isCompletionResultOpen}
|
||||
scenes={selection.setupScenes}
|
||||
sceneAssetMap={sceneAssetMap}
|
||||
selectedSceneId={selection.selectedScene.id}
|
||||
@@ -322,23 +367,63 @@ export const SpaceWorkspaceWidget = () => {
|
||||
sessionPhase={phase ?? 'focus'}
|
||||
onIntentUpdate={controls.handleIntentUpdate}
|
||||
onGoalFinish={async () => {
|
||||
const didFinish = await controls.handleGoalComplete();
|
||||
const completionResult = await controls.handleGoalComplete();
|
||||
|
||||
if (didFinish) {
|
||||
setShowReviewTeaserAfterComplete(true);
|
||||
if (completionResult) {
|
||||
setPendingCompletionResult(completionResult);
|
||||
setCurrentSessionThoughts([]);
|
||||
}
|
||||
|
||||
return didFinish;
|
||||
return Boolean(completionResult);
|
||||
}}
|
||||
onTimerFinish={async () => {
|
||||
const completionResult = await controls.handleTimerComplete();
|
||||
|
||||
if (completionResult) {
|
||||
setPendingCompletionResult(completionResult);
|
||||
setCurrentSessionThoughts([]);
|
||||
}
|
||||
|
||||
return Boolean(completionResult);
|
||||
}}
|
||||
onTimerFinish={controls.handleTimerComplete}
|
||||
onAddTenMinutes={() => controls.handleExtendCurrentPhase(10)}
|
||||
onGoalUpdate={controls.handleGoalAdvance}
|
||||
onStatusMessage={pushStatusLine}
|
||||
onCaptureThought={(note) => addThought(note, selection.selectedScene.name)}
|
||||
onCaptureThought={(note) => {
|
||||
void addThought(note, selection.selectedScene.name).then((savedThought) => {
|
||||
if (!savedThought) {
|
||||
return;
|
||||
}
|
||||
|
||||
setCurrentSessionThoughts((current) => {
|
||||
if (current.some((thought) => thought.id === savedThought.id)) {
|
||||
return current;
|
||||
}
|
||||
|
||||
return [...current, {
|
||||
id: savedThought.id,
|
||||
text: savedThought.text,
|
||||
sceneName: savedThought.sceneName,
|
||||
capturedAt: savedThought.capturedAt,
|
||||
isCompleted: savedThought.isCompleted ?? false,
|
||||
}];
|
||||
});
|
||||
});
|
||||
}}
|
||||
onExitRequested={() => void controls.handleExitRequested()}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
<CompletionResultModal
|
||||
open={isCompletionResultOpen}
|
||||
result={pendingCompletionResult}
|
||||
onClose={() => {
|
||||
setPendingCompletionResult(null);
|
||||
setCurrentSessionThoughts([]);
|
||||
router.replace('/app');
|
||||
}}
|
||||
/>
|
||||
|
||||
<FocusTopToast
|
||||
visible={isFocusMode && Boolean(activeStatus)}
|
||||
message={activeStatus?.message ?? ""}
|
||||
|
||||
Reference in New Issue
Block a user