Skip to content

Commit d69e632

Browse files
Fix Preview component functions and enhance sidebar functionality
1 parent 9ac81c8 commit d69e632

File tree

2 files changed

+96
-20
lines changed

2 files changed

+96
-20
lines changed

app/[taskId]/not-found.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default function TaskNotFound() {
66
<div className="text-center max-w-md mx-auto px-4">
77
<AlertCircle className="h-16 w-16 text-muted-foreground mx-auto mb-4" />
88
<h1 className="text-2xl font-bold mb-2">Task Not Found</h1>
9-
<p className="text-muted-foreground">The task you're looking for doesn't exist or may have been deleted.</p>
9+
<p className="text-muted-foreground">The task you are looking for does not exist or may have been deleted.</p>
1010
</div>
1111
</div>
1212
)

app/page.tsx

Lines changed: 95 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { ViewType } from '@/components/auth';
44
import { AuthDialog } from '@/components/auth-dialog';
55
import { Chat } from '@/components/chat';
66
import { PromptInputBox } from '@/components/ui/ai-prompt-box';
7-
import { ChatPicker } from '@/components/chat-picker';
8-
import { ChatSettings } from '@/components/chat-settings';
97
import { NavBar } from '@/components/navbar';
108
import { Preview } from '@/components/preview';
119
import { Sidebar } from '@/components/sidebar';
@@ -22,7 +20,7 @@ import { cn } from '@/lib/utils';
2220
import { DeepPartial } from 'ai';
2321
import { experimental_useObject as useObject } from '@ai-sdk/react';
2422
import { usePostHog } from 'posthog-js/react';
25-
import { SetStateAction, useCallback, useEffect, useState } from 'react';
23+
import { useCallback, useEffect, useState } from 'react';
2624
import { useLocalStorage } from 'usehooks-ts';
2725
import { useUserTeam } from '@/lib/user-team-provider';
2826
import { HeroPillSecond } from '@/components/announcement';
@@ -50,11 +48,11 @@ export default function Home() {
5048
const [messages, setMessages] = useState<Message[]>([]);
5149
const [fragment, setFragment] = useState<DeepPartial<FragmentSchema>>();
5250
const [currentTab, setCurrentTab] = useState<'code' | 'fragment' | 'terminal' | 'interpreter' | 'editor'>('code');
53-
const [selectedFile] = useState<{ path: string; content: string } | null>(null);
51+
const [selectedFile, setSelectedFile] = useState<{ path: string; content: string } | null>(null);
5452
const [isPreviewLoading, setIsPreviewLoading] = useState(false);
5553
const [isAuthDialogOpen, setAuthDialog] = useState(false);
5654
const [authView, setAuthView] = useState<ViewType>('sign_in')
57-
const [isRateLimited, setIsRateLimited] = useState(false)
55+
const [, setIsRateLimited] = useState(false)
5856
const setAuthDialogCallback = useCallback((isOpen: boolean) => {
5957
setAuthDialog(isOpen)
6058
}, [setAuthDialog])
@@ -342,9 +340,7 @@ export default function Home() {
342340
if (selectedTemplate !== 'auto') {
343341
analytics.trackTemplateSelected(selectedTemplate, 'manual')
344342
}
345-
346-
// Revenue tracking handled by analytics service
347-
343+
348344
posthog.capture('chat_submit', {
349345
template: selectedTemplate,
350346
model: languageModel.model,
@@ -416,11 +412,94 @@ export default function Home() {
416412
setResult(preview.result)
417413
}
418414

415+
async function handleSaveFile(path: string, content: string) {
416+
if (!session) return
417+
418+
try {
419+
const response = await fetch('/api/files/content', {
420+
method: 'POST',
421+
headers: {
422+
'Content-Type': 'application/json',
423+
},
424+
body: JSON.stringify({
425+
sessionID: session.user.id,
426+
path,
427+
content
428+
}),
429+
})
430+
431+
if (response.ok) {
432+
// Update the selected file state if it matches the saved file
433+
if (selectedFile?.path === path) {
434+
setSelectedFile({ path, content })
435+
}
436+
} else {
437+
console.error('Failed to save file:', response.statusText)
438+
}
439+
} catch (error) {
440+
console.error('Error saving file:', error)
441+
}
442+
}
443+
444+
async function handleExecuteCode(code: string): Promise<any> {
445+
if (!session) {
446+
throw new Error('No active session')
447+
}
448+
449+
try {
450+
const response = await fetch('/api/execute', {
451+
method: 'POST',
452+
headers: {
453+
'Content-Type': 'application/json',
454+
},
455+
body: JSON.stringify({
456+
code,
457+
userID: session.user.id,
458+
teamID: userTeam?.id,
459+
accessToken: session.access_token,
460+
}),
461+
})
462+
463+
if (!response.ok) {
464+
const errorData = await response.json()
465+
throw new Error(errorData.error || 'Code execution failed')
466+
}
467+
468+
const result = await response.json()
469+
return result
470+
} catch (error) {
471+
console.error('Error executing code:', error)
472+
throw error
473+
}
474+
}
475+
419476
function handleUndo() {
420477
setMessages((previousMessages) => [...previousMessages.slice(0, -2)])
421478
setCurrentPreview({ fragment: undefined, result: undefined })
422479
}
423480

481+
function handleStartNewChat() {
482+
handleClearChat()
483+
}
484+
485+
function handleSearch(query: string) {
486+
// For now, just log the search query
487+
// This could be enhanced to filter chat history
488+
console.log('Search query:', query)
489+
}
490+
491+
function handleGetFreeTokens() {
492+
// This could open a modal for getting free tokens
493+
// For now, show a simple alert
494+
alert('Free tokens feature coming soon! Check back later for promotional offers.')
495+
}
496+
497+
function handleSelectAccount() {
498+
// This could open an account selection modal
499+
// For now, just show the auth dialog
500+
setAuthDialog(true)
501+
}
502+
424503
return (
425504
<main className="flex min-h-screen max-h-screen">
426505
{supabase && (
@@ -436,6 +515,11 @@ export default function Home() {
436515
<Sidebar
437516
userPlan={userTeam?.tier}
438517
onChatSelected={handleChatSelected}
518+
onStartNewChat={handleStartNewChat}
519+
onSearch={handleSearch}
520+
onGetFreeTokens={handleGetFreeTokens}
521+
onSelectAccount={handleSelectAccount}
522+
onSignOut={logout}
439523
/>
440524
)}
441525

@@ -481,12 +565,6 @@ export default function Home() {
481565
<span>{errorMessage}</span>
482566
<button onClick={retry} className="ml-4 p-1 rounded-md hover:bg-red-500/20">Retry</button>
483567
</div>
484-
)}
485-
{isLoading && (
486-
<div className="flex items-center justify-between p-2">
487-
<span className="text-muted-foreground">Generating response...</span>
488-
<button onClick={stop} className="ml-4 p-1 rounded-md border">Stop</button>
489-
</div>
490568
)}
491569
<PromptInputBox
492570
onSend={handleSendPrompt}
@@ -512,11 +590,9 @@ export default function Home() {
512590
result={result as ExecutionResult}
513591
onClose={() => setFragment(undefined)}
514592
code={fragment?.code || ''}
515-
selectedFile={selectedFile} onSave={function (): void {
516-
throw new Error('Function not implemented.');
517-
} } executeCode={function (): Promise<void> {
518-
throw new Error('Function not implemented.');
519-
} }
593+
selectedFile={selectedFile}
594+
onSave={handleSaveFile}
595+
executeCode={handleExecuteCode}
520596
/>
521597
</div>
522598
</main>

0 commit comments

Comments
 (0)