Skip to content

Commit

Permalink
upload prompts button
Browse files Browse the repository at this point in the history
  • Loading branch information
cdreetz committed Aug 26, 2024
1 parent 4e76b30 commit 394a40b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts
registry.local.ts
registry.local.ts


*.csv
*.txt
29 changes: 26 additions & 3 deletions components/PromptInputForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// components/PromptInputForm.tsx
'use client'

import { useState } from 'react'
import { useState, useRef } from 'react'
import { Textarea } from "@/components/ui/textarea"
import { Button } from "@/components/ui/button"
import { ScrollArea } from "@/components/ui/scroll-area"
Expand All @@ -11,9 +11,9 @@ interface PromptInputFormProps {
onPromptsChange: (prompts: string[]) => void
}


export default function PromptInputForm({ prompts, onPromptsChange }: PromptInputFormProps) {
const [currentPrompt, setCurrentPrompt] = useState('')
const fileInputRef = useRef<HTMLInputElement>(null)

const addPrompt = () => {
if (currentPrompt.trim()) {
Expand All @@ -22,6 +22,19 @@ export default function PromptInputForm({ prompts, onPromptsChange }: PromptInpu
}
}

const handleFileUpload = (event: React.ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0]
if (file) {
const reader = new FileReader()
reader.onload = (e) => {
const content = e.target?.result as string
const newPrompts = content.split('\n').filter(prompt => prompt.trim() !== '')
onPromptsChange([...prompts, ...newPrompts])
}
reader.readAsText(file)
}
}

return (
<div className="space-y-4 w-full">
<h2 className="text-xl font-semibold">Enter Prompts</h2>
Expand All @@ -31,7 +44,17 @@ export default function PromptInputForm({ prompts, onPromptsChange }: PromptInpu
value={currentPrompt}
onChange={(e) => setCurrentPrompt(e.target.value)}
/>
<Button onClick={addPrompt}>Add Prompt</Button>
<div className="flex space-x-2">
<Button onClick={addPrompt}>Add Prompt</Button>
<Button onClick={() => fileInputRef.current?.click()}>Upload Prompts</Button>
<input
type="file"
ref={fileInputRef}
className="hidden"
accept=".txt"
onChange={handleFileUpload}
/>
</div>
{prompts.length > 0 && (
<div>
<h3 className="text-lg font-meduim mb-2">Added Prompts:</h3>
Expand Down

0 comments on commit 394a40b

Please sign in to comment.