add dupli
This commit is contained in:
parent
93f38ab664
commit
7ccd6e80ca
@ -135,7 +135,7 @@ Required environment variables:
|
||||
- [x] Prompt Version Controll
|
||||
- [x] Generate a new version when save
|
||||
- [x] Save last [LIMIT] versions
|
||||
- [ ] [LIMIT] can setting in use profile
|
||||
- [x] [LIMIT] can setting in use profile
|
||||
- [ ] [LIMIT] max is by Subscribe
|
||||
- [ ] Delete Version Button
|
||||
- [x] Prompt Debugger run
|
||||
|
@ -14,6 +14,7 @@
|
||||
"delete": "Delete",
|
||||
"edit": "Edit",
|
||||
"create": "Create",
|
||||
"duplicate": "Duplicate",
|
||||
"search": "Search",
|
||||
"filter": "Filter",
|
||||
"close": "Close",
|
||||
|
@ -14,6 +14,7 @@
|
||||
"delete": "删除",
|
||||
"edit": "编辑",
|
||||
"create": "创建",
|
||||
"duplicate": "复制",
|
||||
"search": "搜索",
|
||||
"filter": "筛选",
|
||||
"close": "关闭",
|
||||
|
@ -15,9 +15,7 @@ import {
|
||||
Play,
|
||||
Save,
|
||||
Copy,
|
||||
Settings,
|
||||
Zap,
|
||||
History,
|
||||
ArrowLeft,
|
||||
FileText,
|
||||
Clock
|
||||
@ -71,6 +69,7 @@ export default function PromptPage({ params }: PromptPageProps) {
|
||||
const [originalContent, setOriginalContent] = useState('')
|
||||
const [originalTitle, setOriginalTitle] = useState('')
|
||||
const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false)
|
||||
const [isDuplicating, setIsDuplicating] = useState(false)
|
||||
const versionTimelineRef = useRef<VersionTimelineRef>(null)
|
||||
|
||||
useEffect(() => {
|
||||
@ -246,6 +245,40 @@ export default function PromptPage({ params }: PromptPageProps) {
|
||||
}
|
||||
}
|
||||
|
||||
const handleDuplicatePrompt = async () => {
|
||||
if (!user || !prompt) return
|
||||
|
||||
setIsDuplicating(true)
|
||||
try {
|
||||
// 创建新的prompt,使用当前显示的内容
|
||||
const duplicatedPrompt = {
|
||||
name: `${promptTitle} 副本`,
|
||||
content: promptContent,
|
||||
description: prompt.description,
|
||||
tags: prompt.tags,
|
||||
userId: user.id
|
||||
}
|
||||
|
||||
const response = await fetch('/api/prompts', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(duplicatedPrompt)
|
||||
})
|
||||
|
||||
if (response.ok) {
|
||||
const newPrompt = await response.json()
|
||||
// 跳转到新创建的prompt页面
|
||||
router.push(`/studio/${newPrompt.id}`)
|
||||
} else {
|
||||
console.error('Failed to duplicate prompt')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error duplicating prompt:', error)
|
||||
} finally {
|
||||
setIsDuplicating(false)
|
||||
}
|
||||
}
|
||||
|
||||
if (loading || isLoading) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center">
|
||||
@ -292,17 +325,19 @@ export default function PromptPage({ params }: PromptPageProps) {
|
||||
</div>
|
||||
|
||||
<div className="flex items-center space-x-2">
|
||||
<Button variant="outline" size="sm" className="flex items-center space-x-1">
|
||||
<History className="h-4 w-4" />
|
||||
<span className="hidden sm:inline">{t('versionHistory')}</span>
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" className="flex items-center space-x-1">
|
||||
<Copy className="h-4 w-4" />
|
||||
<span className="hidden sm:inline">Duplicate</span>
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" className="flex items-center space-x-1">
|
||||
<Settings className="h-4 w-4" />
|
||||
<span className="hidden sm:inline">Settings</span>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={handleDuplicatePrompt}
|
||||
disabled={!prompt || isLoading || isDuplicating}
|
||||
className="flex items-center space-x-1"
|
||||
>
|
||||
{isDuplicating ? (
|
||||
<LoadingSpinner size="sm" className="mr-1" />
|
||||
) : (
|
||||
<Copy className="h-4 w-4" />
|
||||
)}
|
||||
<span className="hidden sm:inline">{tCommon('duplicate')}</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user