idea-manager 0.6.1 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,487 +1,21 @@
1
1
  'use client';
2
2
 
3
- import { useState, useEffect, useCallback, useRef, use, Suspense } from 'react';
4
- import { useRouter, useSearchParams } from 'next/navigation';
5
- import Editor from '@/components/brainstorm/Editor';
6
- import ProjectTree from '@/components/task/ProjectTree';
7
- import TaskDetail from '@/components/task/TaskDetail';
8
- import DirectoryPicker from '@/components/DirectoryPicker';
9
- import ConfirmDialog from '@/components/ui/ConfirmDialog';
10
- import AiPolicyModal from '@/components/ui/AiPolicyModal';
11
- import type { ISubProject, ITask, TaskStatus, ISubProjectWithStats } from '@/types';
3
+ import { useEffect, use } from 'react';
4
+ import { useRouter } from 'next/navigation';
12
5
 
13
- interface IProject {
14
- id: string;
15
- name: string;
16
- description: string;
17
- project_path: string | null;
18
- ai_context: string;
19
- watch_enabled: boolean;
20
- }
21
-
22
- function WorkspaceInner({ id }: { id: string }) {
6
+ export default function ProjectRedirect({ params }: { params: Promise<{ id: string }> }) {
7
+ const { id } = use(params);
23
8
  const router = useRouter();
24
- const searchParams = useSearchParams();
25
- const initialUrlSub = useRef(searchParams.get('sub'));
26
- const initialUrlTask = useRef(searchParams.get('task'));
27
-
28
- const [project, setProject] = useState<IProject | null>(null);
29
- const [subProjects, setSubProjects] = useState<ISubProjectWithStats[]>([]);
30
- const [selectedSubId, setSelectedSubId] = useState<string | null>(null);
31
- const [tasks, setTasks] = useState<ITask[]>([]);
32
- const [selectedTaskId, setSelectedTaskId] = useState<string | null>(null);
33
- const [showDirPicker, setShowDirPicker] = useState(false);
34
- const [confirmAction, setConfirmAction] = useState<{ type: 'delete-sub' | 'delete-task'; id: string } | null>(null);
35
- const [showAddSub, setShowAddSub] = useState(false);
36
- const [showBrainstorm, setShowBrainstorm] = useState(true);
37
- const [newSubName, setNewSubName] = useState('');
38
- const [showAiPolicy, setShowAiPolicy] = useState(false);
39
-
40
- // Resizable panel widths
41
- const [leftWidth, setLeftWidth] = useState(500);
42
- const [centerWidth, setCenterWidth] = useState(500);
43
- const containerRef = useRef<HTMLDivElement>(null);
44
- const draggingRef = useRef<'left' | 'center' | null>(null);
45
- const startXRef = useRef(0);
46
- const startWidthRef = useRef(0);
47
-
48
- const handleMouseDown = useCallback((panel: 'left' | 'center', e: React.MouseEvent) => {
49
- e.preventDefault();
50
- draggingRef.current = panel;
51
- startXRef.current = e.clientX;
52
- startWidthRef.current = panel === 'left' ? leftWidth : centerWidth;
53
- }, [leftWidth, centerWidth]);
54
9
 
55
10
  useEffect(() => {
56
- const handleMouseMove = (e: MouseEvent) => {
57
- if (!draggingRef.current) return;
58
- const delta = e.clientX - startXRef.current;
59
- const newWidth = Math.max(180, Math.min(500, startWidthRef.current + delta));
60
- if (draggingRef.current === 'left') setLeftWidth(newWidth);
61
- else setCenterWidth(newWidth);
62
- };
63
- const handleMouseUp = () => { draggingRef.current = null; };
64
- window.addEventListener('mousemove', handleMouseMove);
65
- window.addEventListener('mouseup', handleMouseUp);
66
- return () => {
67
- window.removeEventListener('mousemove', handleMouseMove);
68
- window.removeEventListener('mouseup', handleMouseUp);
69
- };
70
- }, []);
71
-
72
- // Load project
73
- useEffect(() => {
74
- fetch(`/api/projects/${id}`)
75
- .then(r => { if (!r.ok) { router.push('/'); return null; } return r.json(); })
76
- .then(data => data && setProject(data));
11
+ // Store project ID for TabProvider to pick up, then redirect to root
12
+ sessionStorage.setItem('im-open-project', id);
13
+ router.replace('/');
77
14
  }, [id, router]);
78
15
 
79
- // Load sub-projects (stable callback, no deps on selection state)
80
- const loadSubProjects = useCallback(async () => {
81
- const res = await fetch(`/api/projects/${id}/sub-projects`);
82
- if (!res.ok) return;
83
- const data: ISubProjectWithStats[] = await res.json();
84
- setSubProjects(data);
85
- return data;
86
- }, [id]);
87
-
88
- // Initial load: sub-projects + auto-select from URL
89
- useEffect(() => {
90
- loadSubProjects().then(data => {
91
- if (!data || data.length === 0) return;
92
- const urlSub = initialUrlSub.current;
93
- if (urlSub && data.some(s => s.id === urlSub)) {
94
- setSelectedSubId(urlSub);
95
- } else {
96
- setSelectedSubId(data[0].id);
97
- }
98
- });
99
- }, [loadSubProjects]);
100
-
101
- // Load tasks when sub-project changes
102
- useEffect(() => {
103
- if (!selectedSubId) { setTasks([]); return; }
104
- fetch(`/api/projects/${id}/sub-projects/${selectedSubId}/tasks`)
105
- .then(r => r.json())
106
- .then((data: ITask[]) => {
107
- setTasks(data);
108
- // Auto-select from URL on first load only
109
- const urlTask = initialUrlTask.current;
110
- if (urlTask && data.some(t => t.id === urlTask)) {
111
- setSelectedTaskId(urlTask);
112
- initialUrlTask.current = null; // consume once
113
- }
114
- });
115
- }, [id, selectedSubId]);
116
-
117
- const selectedTask = tasks.find(t => t.id === selectedTaskId) ?? null;
118
-
119
- const handleCreateSubProject = async () => {
120
- if (!newSubName.trim()) return;
121
- const res = await fetch(`/api/projects/${id}/sub-projects`, {
122
- method: 'POST',
123
- headers: { 'Content-Type': 'application/json' },
124
- body: JSON.stringify({ name: newSubName.trim() }),
125
- });
126
- if (res.ok) {
127
- const sp: ISubProject = await res.json();
128
- setNewSubName('');
129
- setShowAddSub(false);
130
- await loadSubProjects();
131
- setSelectedSubId(sp.id);
132
- }
133
- };
134
-
135
- const handleDeleteSubProject = (subId: string) => {
136
- setConfirmAction({ type: 'delete-sub', id: subId });
137
- };
138
-
139
- const handleCreateTask = async (title: string) => {
140
- if (!selectedSubId) return;
141
- const res = await fetch(`/api/projects/${id}/sub-projects/${selectedSubId}/tasks`, {
142
- method: 'POST',
143
- headers: { 'Content-Type': 'application/json' },
144
- body: JSON.stringify({ title }),
145
- });
146
- if (res.ok) {
147
- const task: ITask = await res.json();
148
- setTasks(prev => [...prev, task]);
149
- setSelectedTaskId(task.id);
150
- loadSubProjects();
151
- }
152
- };
153
-
154
- const handleTaskStatusChange = async (taskId: string, status: TaskStatus) => {
155
- const res = await fetch(`/api/projects/${id}/sub-projects/${selectedSubId}/tasks/${taskId}`, {
156
- method: 'PUT',
157
- headers: { 'Content-Type': 'application/json' },
158
- body: JSON.stringify({ status }),
159
- });
160
- if (res.ok) {
161
- const updated: ITask = await res.json();
162
- setTasks(prev => prev.map(t => t.id === taskId ? updated : t));
163
- loadSubProjects();
164
- }
165
- };
166
-
167
- const handleTaskTodayToggle = async (taskId: string, isToday: boolean) => {
168
- const res = await fetch(`/api/projects/${id}/sub-projects/${selectedSubId}/tasks/${taskId}`, {
169
- method: 'PUT',
170
- headers: { 'Content-Type': 'application/json' },
171
- body: JSON.stringify({ is_today: isToday }),
172
- });
173
- if (res.ok) {
174
- const updated: ITask = await res.json();
175
- setTasks(prev => prev.map(t => t.id === taskId ? updated : t));
176
- }
177
- };
178
-
179
- const handleTaskUpdate = async (data: Partial<ITask>) => {
180
- if (!selectedTaskId || !selectedSubId) return;
181
- const res = await fetch(`/api/projects/${id}/sub-projects/${selectedSubId}/tasks/${selectedTaskId}`, {
182
- method: 'PUT',
183
- headers: { 'Content-Type': 'application/json' },
184
- body: JSON.stringify(data),
185
- });
186
- if (res.ok) {
187
- const updated: ITask = await res.json();
188
- setTasks(prev => prev.map(t => t.id === selectedTaskId ? updated : t));
189
- loadSubProjects();
190
- }
191
- };
192
-
193
- const handleTaskDelete = (taskId?: string) => {
194
- const id = taskId || selectedTaskId;
195
- if (!id) return;
196
- setConfirmAction({ type: 'delete-task', id });
197
- };
198
-
199
- const handleConfirmAction = async () => {
200
- if (!confirmAction) return;
201
- if (confirmAction.type === 'delete-sub') {
202
- await fetch(`/api/projects/${id}/sub-projects/${confirmAction.id}`, { method: 'DELETE' });
203
- if (selectedSubId === confirmAction.id) {
204
- setSelectedSubId(null);
205
- setSelectedTaskId(null);
206
- }
207
- loadSubProjects();
208
- } else if (confirmAction.type === 'delete-task') {
209
- await fetch(`/api/projects/${id}/sub-projects/${selectedSubId}/tasks/${confirmAction.id}`, { method: 'DELETE' });
210
- setTasks(prev => prev.filter(t => t.id !== confirmAction.id));
211
- if (selectedTaskId === confirmAction.id) setSelectedTaskId(null);
212
- loadSubProjects();
213
- }
214
- setConfirmAction(null);
215
- };
216
-
217
- const handleSetPath = async (selectedPath: string) => {
218
- const res = await fetch(`/api/projects/${id}`, {
219
- method: 'PUT',
220
- headers: { 'Content-Type': 'application/json' },
221
- body: JSON.stringify({ project_path: selectedPath }),
222
- });
223
- if (res.ok) {
224
- setProject(await res.json());
225
- setShowDirPicker(false);
226
- }
227
- };
228
-
229
- const handleSaveAiPolicy = async (aiContext: string) => {
230
- const res = await fetch(`/api/projects/${id}`, {
231
- method: 'PUT',
232
- headers: { 'Content-Type': 'application/json' },
233
- body: JSON.stringify({ ai_context: aiContext }),
234
- });
235
- if (res.ok) {
236
- setProject(await res.json());
237
- setShowAiPolicy(false);
238
- }
239
- };
240
-
241
- const handleToggleWatch = async () => {
242
- if (!project) return;
243
- const res = await fetch(`/api/projects/${id}`, {
244
- method: 'PUT',
245
- headers: { 'Content-Type': 'application/json' },
246
- body: JSON.stringify({ watch_enabled: !project.watch_enabled }),
247
- });
248
- if (res.ok) {
249
- setProject(await res.json());
250
- }
251
- };
252
-
253
- // Keyboard shortcuts (use e.code for Korean IME compatibility)
254
- useEffect(() => {
255
- const handler = (e: KeyboardEvent) => {
256
- const isInput = e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement;
257
-
258
- // B — toggle brainstorming panel
259
- if (!isInput && e.code === 'KeyB' && !e.metaKey && !e.ctrlKey) {
260
- e.preventDefault();
261
- setShowBrainstorm(prev => !prev);
262
- return;
263
- }
264
-
265
- // N — new sub-project (when not in input)
266
- if (!isInput && e.code === 'KeyN' && !e.metaKey && !e.ctrlKey) {
267
- e.preventDefault();
268
- setShowAddSub(true);
269
- return;
270
- }
271
-
272
- // T — new task (when sub-project selected, not in input)
273
- if (!isInput && e.code === 'KeyT' && !e.metaKey && !e.ctrlKey && selectedSubId) {
274
- e.preventDefault();
275
- const addBtn = document.querySelector('[data-add-task]') as HTMLButtonElement;
276
- addBtn?.click();
277
- return;
278
- }
279
-
280
- // Cmd+1~6 — status change
281
- if (selectedTaskId && selectedSubId && !isInput) {
282
- const statusMap: Record<string, TaskStatus> = {
283
- 'Digit1': 'idea', 'Digit2': 'writing', 'Digit3': 'submitted',
284
- 'Digit4': 'testing', 'Digit5': 'done', 'Digit6': 'problem',
285
- };
286
-
287
- if ((e.metaKey || e.ctrlKey) && statusMap[e.code]) {
288
- e.preventDefault();
289
- handleTaskStatusChange(selectedTaskId, statusMap[e.code]);
290
- }
291
- }
292
- };
293
- window.addEventListener('keydown', handler);
294
- return () => window.removeEventListener('keydown', handler);
295
- });
296
-
297
- if (!project) {
298
- return <div className="min-h-screen flex items-center justify-center text-muted-foreground">Loading...</div>;
299
- }
300
-
301
16
  return (
302
- <div className="h-screen flex flex-col">
303
- {/* Header */}
304
- <header className="flex items-center justify-between px-4 py-2 border-b border-border bg-card flex-shrink-0">
305
- <div className="flex items-center gap-3">
306
- <button
307
- onClick={() => router.push('/')}
308
- className="text-muted-foreground hover:text-foreground hover:bg-muted transition-colors text-sm px-2 py-1 rounded-md"
309
- >
310
- &larr; Back
311
- </button>
312
- <span className="text-border">|</span>
313
- <h1 className="text-sm font-semibold">{project.name}</h1>
314
- {project.project_path && (
315
- <span className="text-xs text-muted-foreground font-mono truncate max-w-48" title={project.project_path}>
316
- {project.project_path}
317
- </span>
318
- )}
319
- </div>
320
- <div className="flex items-center gap-2">
321
- <button
322
- onClick={handleToggleWatch}
323
- className={`px-3 py-1.5 text-xs border rounded-md transition-colors flex items-center gap-1.5 ${
324
- project.watch_enabled
325
- ? 'bg-success/15 text-success border-success/30 hover:bg-success/25'
326
- : 'bg-muted hover:bg-card-hover text-muted-foreground border-border'
327
- }`}
328
- title={project.watch_enabled ? 'Watch ON — submitted 태스크 자동 실행' : 'Watch OFF'}
329
- >
330
- <span className={`inline-block w-2 h-2 rounded-full ${project.watch_enabled ? 'bg-success animate-pulse' : 'bg-muted-foreground/40'}`} />
331
- Watch
332
- </button>
333
- <button
334
- onClick={() => setShowAiPolicy(true)}
335
- className={`px-3 py-1.5 text-xs border rounded-md transition-colors ${
336
- project.ai_context
337
- ? 'bg-accent/15 text-accent border-accent/30 hover:bg-accent/25'
338
- : 'bg-muted hover:bg-card-hover text-muted-foreground border-border'
339
- }`}
340
- >
341
- AI Policy{project.ai_context ? ' *' : ''}
342
- </button>
343
- {!project.project_path && (
344
- <button
345
- onClick={() => setShowDirPicker(true)}
346
- className="px-3 py-1.5 text-xs bg-muted hover:bg-card-hover text-foreground
347
- border border-border rounded-md transition-colors"
348
- >
349
- Link folder
350
- </button>
351
- )}
352
- </div>
353
- </header>
354
-
355
- {/* 3-Panel Layout with resize handles */}
356
- <div ref={containerRef} className="flex-1 flex overflow-hidden">
357
- {/* Left: Brainstorming (collapsible) */}
358
- {showBrainstorm ? (
359
- <>
360
- <div style={{ width: leftWidth }} className="border-r border-border flex flex-col flex-shrink-0">
361
- <Editor
362
- projectId={id}
363
- onCollapse={() => setShowBrainstorm(false)}
364
- />
365
- </div>
366
- {/* Resize handle: left */}
367
- <div
368
- className="panel-resize-handle"
369
- onMouseDown={(e) => handleMouseDown('left', e)}
370
- >
371
- <div className="panel-resize-handle-bar" />
372
- </div>
373
- </>
374
- ) : (
375
- <button
376
- onClick={() => setShowBrainstorm(true)}
377
- className="w-8 border-r border-border flex-shrink-0 flex items-center justify-center
378
- text-muted-foreground hover:text-foreground hover:bg-card-hover transition-colors
379
- text-xs"
380
- title="Show brainstorming (B)"
381
- style={{ writingMode: 'vertical-rl' }}
382
- >
383
- Brainstorm
384
- </button>
385
- )}
386
-
387
- {/* Center: Tree (Sub-projects + Tasks) */}
388
- <div style={{ width: centerWidth }} className="border-r border-border flex flex-col flex-shrink-0">
389
- {/* Add sub-project input */}
390
- {showAddSub && (
391
- <div className="px-3 py-2 border-b border-border">
392
- <input
393
- type="text"
394
- value={newSubName}
395
- onChange={(e) => setNewSubName(e.target.value)}
396
- onKeyDown={(e) => {
397
- if (e.key === 'Enter') handleCreateSubProject();
398
- if (e.key === 'Escape') { setNewSubName(''); setShowAddSub(false); }
399
- }}
400
- placeholder="Sub-project name..."
401
- className="w-full bg-input border border-border rounded px-2 py-1 text-xs
402
- focus:border-primary focus:outline-none text-foreground"
403
- autoFocus
404
- />
405
- </div>
406
- )}
407
-
408
- <ProjectTree
409
- subProjects={subProjects}
410
- tasks={tasks}
411
- selectedSubId={selectedSubId}
412
- selectedTaskId={selectedTaskId}
413
- onSelectSub={(subId) => { setSelectedSubId(subId); setSelectedTaskId(null); }}
414
- onSelectTask={setSelectedTaskId}
415
- onCreateSub={() => setShowAddSub(true)}
416
- onDeleteSub={handleDeleteSubProject}
417
- onCreateTask={handleCreateTask}
418
- onStatusChange={handleTaskStatusChange}
419
- onTodayToggle={handleTaskTodayToggle}
420
- onDeleteTask={handleTaskDelete}
421
- />
422
- </div>
423
-
424
- {/* Resize handle: center */}
425
- <div
426
- className="panel-resize-handle"
427
- onMouseDown={(e) => handleMouseDown('center', e)}
428
- >
429
- <div className="panel-resize-handle-bar" />
430
- </div>
431
-
432
- {/* Right: Task Detail */}
433
- <div className="flex-1 min-w-0">
434
- {selectedTask ? (
435
- <TaskDetail
436
- task={selectedTask}
437
- projectId={id}
438
- subProjectId={selectedSubId!}
439
- onUpdate={handleTaskUpdate}
440
- onDelete={handleTaskDelete}
441
- />
442
- ) : (
443
- <div className="flex items-center justify-center h-full text-muted-foreground text-sm">
444
- {tasks.length > 0 ? 'Select a task' : selectedSubId ? 'Create a task to get started' : 'Select a sub-project'}
445
- </div>
446
- )}
447
- </div>
448
- </div>
449
-
450
- {showDirPicker && (
451
- <DirectoryPicker
452
- onSelect={handleSetPath}
453
- onCancel={() => setShowDirPicker(false)}
454
- initialPath={project.project_path || undefined}
455
- />
456
- )}
457
-
458
- <ConfirmDialog
459
- open={!!confirmAction}
460
- title={confirmAction?.type === 'delete-sub' ? 'Delete sub-project?' : 'Delete task?'}
461
- description={confirmAction?.type === 'delete-sub'
462
- ? 'This will delete the sub-project and all its tasks.'
463
- : 'This task will be permanently deleted.'}
464
- confirmLabel="Delete"
465
- variant="danger"
466
- onConfirm={handleConfirmAction}
467
- onCancel={() => setConfirmAction(null)}
468
- />
469
-
470
- <AiPolicyModal
471
- open={showAiPolicy}
472
- content={project.ai_context || ''}
473
- onSave={handleSaveAiPolicy}
474
- onClose={() => setShowAiPolicy(false)}
475
- />
17
+ <div className="min-h-screen flex items-center justify-center text-muted-foreground">
18
+ Loading...
476
19
  </div>
477
20
  );
478
21
  }
479
-
480
- export default function ProjectWorkspace({ params }: { params: Promise<{ id: string }> }) {
481
- const { id } = use(params);
482
- return (
483
- <Suspense fallback={<div className="min-h-screen flex items-center justify-center text-muted-foreground">Loading...</div>}>
484
- <WorkspaceInner id={id} />
485
- </Suspense>
486
- );
487
- }