forked from stackblitz-labs/bolt.diy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from replayio/recording-button
Add button to save recording, assorted other UX changes
- Loading branch information
1 parent
1f938fc
commit c3e1764
Showing
22 changed files
with
1,598 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import React, { useState } from 'react'; | ||
import type { Message } from 'ai'; | ||
import { toast } from 'react-toastify'; | ||
import { createChatFromFolder, type FileArtifact } from '~/utils/folderImport'; | ||
import { logStore } from '~/lib/stores/logs'; // Assuming logStore is imported from this location | ||
import { sendCommandDedicatedClient } from '../workbench/ReplayProtocolClient'; | ||
import type { BoltProblem } from './Messages.client'; | ||
import JSZip from 'jszip'; | ||
|
||
interface LoadProblemButtonProps { | ||
className?: string; | ||
importChat?: (description: string, messages: Message[]) => Promise<void>; | ||
} | ||
|
||
export const LoadProblemButton: React.FC<LoadProblemButtonProps> = ({ className, importChat }) => { | ||
const [isLoading, setIsLoading] = useState(false); | ||
const [isInputOpen, setIsInputOpen] = useState(false); | ||
|
||
const handleSubmit = async (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setIsLoading(true); | ||
setIsInputOpen(false); | ||
|
||
const problemId = (document.getElementById('problem-input') as HTMLInputElement)?.value; | ||
|
||
let problem: BoltProblem | null = null; | ||
try { | ||
const rv = await sendCommandDedicatedClient({ | ||
method: "Recording.globalExperimentalCommand", | ||
params: { | ||
name: "fetchBoltProblem", | ||
params: { problemId }, | ||
}, | ||
}); | ||
console.log("FetchProblemRval", rv); | ||
problem = (rv as any).rval.problem; | ||
} catch (error) { | ||
console.error("Error fetching problem", error); | ||
toast.error("Failed to fetch problem"); | ||
} | ||
|
||
if (!problem) { | ||
return; | ||
} | ||
|
||
console.log("Problem", problem); | ||
|
||
const zip = new JSZip(); | ||
await zip.loadAsync(problem.prompt.content, { base64: true }); | ||
|
||
const fileArtifacts: FileArtifact[] = []; | ||
for (const [key, object] of Object.entries(zip.files)) { | ||
if (object.dir) continue; | ||
fileArtifacts.push({ | ||
content: await object.async('text'), | ||
path: key, | ||
}); | ||
} | ||
|
||
const folderName = problem.prompt.uniqueProjectName; | ||
|
||
try { | ||
const messages = await createChatFromFolder(fileArtifacts, [], folderName); | ||
|
||
if (importChat) { | ||
await importChat(folderName, [...messages]); | ||
} | ||
|
||
logStore.logSystem('Problem loaded successfully', { | ||
problemId, | ||
textFileCount: fileArtifacts.length, | ||
}); | ||
toast.success('Problem loaded successfully'); | ||
} catch (error) { | ||
logStore.logError('Failed to load problem', error); | ||
console.error('Failed to load problem:', error); | ||
toast.error('Failed to load problem'); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
{isInputOpen && ( | ||
<input | ||
id="problem-input" | ||
type="text" | ||
webkitdirectory="" | ||
directory="" | ||
onChange={() => {}} | ||
onKeyDown={(e) => { | ||
if (e.key === 'Enter') { | ||
handleSubmit(e as any); | ||
} | ||
}} | ||
className="border border-gray-300 rounded px-2 py-1" | ||
{...({} as any)} | ||
/> | ||
)} | ||
{!isInputOpen && ( | ||
<button | ||
onClick={() => { | ||
setIsInputOpen(true); | ||
}} | ||
className={className} | ||
disabled={isLoading} | ||
> | ||
<div className="i-ph:globe" /> | ||
{isLoading ? 'Loading...' : 'Load Problem'} | ||
</button> | ||
)} | ||
</> | ||
); | ||
}; |
Oops, something went wrong.