forked from Zackriya-Solutions/meetily
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.tsx
More file actions
260 lines (233 loc) · 9.9 KB
/
Copy pathpage.tsx
File metadata and controls
260 lines (233 loc) · 9.9 KB
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
'use client';
import { useState, useEffect } from 'react';
import { motion } from 'framer-motion';
import { RecordingControls } from '@/components/RecordingControls';
import { useSidebar } from '@/components/Sidebar/SidebarProvider';
import { usePermissionCheck } from '@/hooks/usePermissionCheck';
import { useRecordingState, RecordingStatus } from '@/contexts/RecordingStateContext';
import { useTranscripts } from '@/contexts/TranscriptContext';
import { useConfig } from '@/contexts/ConfigContext';
import { StatusOverlays } from '@/app/_components/StatusOverlays';
import { SettingsModals } from './_components/SettingsModal';
import { TranscriptPanel } from './_components/TranscriptPanel';
import { useModalState } from '@/hooks/useModalState';
import { useRecordingStateSync } from '@/hooks/useRecordingStateSync';
import { useRecordingStart } from '@/hooks/useRecordingStart';
import { useRecordingStop } from '@/hooks/useRecordingStop';
import { useTranscriptRecovery } from '@/hooks/useTranscriptRecovery';
import { TranscriptRecovery } from '@/components/TranscriptRecovery';
import { indexedDBService } from '@/services/indexedDBService';
import { toast } from 'sonner';
import { useRouter } from 'next/navigation';
export default function Home() {
// Local page state (not moved to contexts)
const [isRecording, setIsRecordingState] = useState(false);
const [barHeights, setBarHeights] = useState(['58%', '76%', '58%']);
const [showRecoveryDialog, setShowRecoveryDialog] = useState(false);
// Use contexts for state management
const { meetingTitle } = useTranscripts();
const { transcriptModelConfig, selectedDevices } = useConfig();
const recordingState = useRecordingState();
// Extract status from global state
const { status, isStopping, isProcessing, isSaving } = recordingState;
// Hooks
const { hasMicrophone } = usePermissionCheck();
const { setIsMeetingActive, isCollapsed: sidebarCollapsed, refetchMeetings } = useSidebar();
const { modals, messages, showModal, hideModal } = useModalState(transcriptModelConfig);
const { isRecordingDisabled, setIsRecordingDisabled } = useRecordingStateSync(isRecording, setIsRecordingState, setIsMeetingActive);
const { handleRecordingStart } = useRecordingStart(isRecording, setIsRecordingState, showModal);
// Get handleRecordingStop function and setIsStopping (state comes from global context)
const { handleRecordingStop, setIsStopping } = useRecordingStop(
setIsRecordingState,
setIsRecordingDisabled
);
// Recovery hook
const {
recoverableMeetings,
isLoading: isLoadingRecovery,
isRecovering,
checkForRecoverableTranscripts,
recoverMeeting,
loadMeetingTranscripts,
deleteRecoverableMeeting
} = useTranscriptRecovery();
const router = useRouter();
// Startup recovery check
useEffect(() => {
const performStartupChecks = async () => {
try {
// Skip recovery check if currently recording or processing stop
// This prevents the recovery dialog from showing when:
if (recordingState.isRecording ||
status === RecordingStatus.STOPPING ||
status === RecordingStatus.PROCESSING_TRANSCRIPTS ||
status === RecordingStatus.SAVING) {
console.log('Skipping recovery check - recording in progress or processing');
return;
}
// 1. Clean up old meetings (7+ days)
try {
await indexedDBService.deleteOldMeetings(7);
} catch (error) {
console.warn('⚠️ Failed to clean up old meetings:', error);
}
// 2. Clean up saved meetings (24+ hours after save)
try {
await indexedDBService.deleteSavedMeetings(24);
} catch (error) {
console.warn('⚠️ Failed to clean up saved meetings:', error);
}
// 3. Always check for recoverable meetings on startup
// Don't skip based on sessionStorage - we need to check every time
await checkForRecoverableTranscripts();
} catch (error) {
console.error('Failed to perform startup checks:', error);
}
};
performStartupChecks();
}, [checkForRecoverableTranscripts, recordingState.isRecording, status]);
// Watch for recoverable meetings changes and show dialog once per session
useEffect(() => {
// Only show dialog if we have meetings and haven't shown it yet this session
if (recoverableMeetings.length > 0) {
const shownThisSession = sessionStorage.getItem('recovery_dialog_shown');
if (!shownThisSession) {
setShowRecoveryDialog(true);
sessionStorage.setItem('recovery_dialog_shown', 'true');
}
}
}, [recoverableMeetings]);
// Handle recovery with toast notifications and navigation
const handleRecovery = async (meetingId: string) => {
try {
const result = await recoverMeeting(meetingId);
if (result.success) {
toast.success('Meeting recovered successfully!', {
description: result.audioRecoveryStatus?.status === 'success'
? 'Transcripts and audio recovered'
: 'Transcripts recovered (no audio available)',
action: result.meetingId ? {
label: 'View Meeting',
onClick: () => {
router.push(`/meeting-details?id=${result.meetingId}`);
}
} : undefined,
duration: 10000,
});
// Refresh sidebar to show the newly recovered meeting
await refetchMeetings();
// If no more recoverable meetings, clear session flag so dialog can show again
if (recoverableMeetings.length === 0) {
sessionStorage.removeItem('recovery_dialog_shown');
}
// Auto-navigate after a short delay
if (result.meetingId) {
setTimeout(() => {
router.push(`/meeting-details?id=${result.meetingId}`);
}, 2000);
}
}
} catch (error) {
toast.error('Failed to recover meeting', {
description: error instanceof Error ? error.message : 'Unknown error occurred',
});
throw error;
}
};
// Handle dialog close - clear session flag if no meetings left
const handleDialogClose = () => {
setShowRecoveryDialog(false);
// If user closes dialog and there are no more meetings, clear the flag
// This allows the dialog to show again next session if new meetings appear
if (recoverableMeetings.length === 0) {
sessionStorage.removeItem('recovery_dialog_shown');
}
};
useEffect(() => {
if (recordingState.isRecording) {
const interval = setInterval(() => {
setBarHeights(prev => {
const newHeights = [...prev];
newHeights[0] = Math.random() * 20 + 10 + 'px';
newHeights[1] = Math.random() * 20 + 10 + 'px';
newHeights[2] = Math.random() * 20 + 10 + 'px';
return newHeights;
});
}, 300);
return () => clearInterval(interval);
}
}, [recordingState.isRecording]);
// Computed values using global status
const isProcessingStop = status === RecordingStatus.PROCESSING_TRANSCRIPTS || isProcessing;
return (
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.3, ease: 'easeOut' }}
className="flex flex-col h-screen bg-gray-50"
>
{/* All Modals supported*/}
<SettingsModals
modals={modals}
messages={messages}
onClose={hideModal}
/>
{/* Recovery Dialog */}
<TranscriptRecovery
isOpen={showRecoveryDialog}
onClose={handleDialogClose}
recoverableMeetings={recoverableMeetings}
onRecover={handleRecovery}
onDelete={deleteRecoverableMeeting}
onLoadPreview={loadMeetingTranscripts}
/>
<div className="flex flex-1 overflow-hidden">
<TranscriptPanel
isProcessingStop={isProcessingStop}
isStopping={isStopping}
showModal={showModal}
/>
{/* Recording controls - only show when permissions are granted or already recording and not showing status messages */}
{(hasMicrophone || isRecording) &&
status !== RecordingStatus.PROCESSING_TRANSCRIPTS &&
status !== RecordingStatus.SAVING && (
<div className="fixed bottom-12 left-0 right-0 z-10">
<div
className="flex justify-center pl-8 transition-[margin] duration-300"
style={{
marginLeft: sidebarCollapsed ? '4rem' : '16rem'
}}
>
<div className="w-2/3 max-w-[750px] flex justify-center">
<div className="bg-white rounded-full shadow-lg flex items-center">
<RecordingControls
isRecording={recordingState.isRecording}
onRecordingStop={(callApi = true) => handleRecordingStop(callApi)}
onRecordingStart={handleRecordingStart}
onTranscriptReceived={() => { }} // Not actually used by RecordingControls
onStopInitiated={() => setIsStopping(true)}
barHeights={barHeights}
onTranscriptionError={(message) => {
showModal('errorAlert', message);
}}
isRecordingDisabled={isRecordingDisabled}
isParentProcessing={isProcessingStop}
selectedDevices={selectedDevices}
meetingName={meetingTitle}
/>
</div>
</div>
</div>
</div>
)}
{/* Status Overlays - Processing and Saving */}
<StatusOverlays
isProcessing={status === RecordingStatus.PROCESSING_TRANSCRIPTS && !recordingState.isRecording}
isSaving={status === RecordingStatus.SAVING}
processingMessage={recordingState.statusMessage}
sidebarCollapsed={sidebarCollapsed}
/>
</div>
</motion.div>
);
}