Refactored prompt selection
This commit is contained in:
parent
7e2c5b4b16
commit
1b4ff63d1c
@ -559,38 +559,26 @@ struct ConfigurationView: View {
|
||||
|
||||
// Enhancement Prompts Section (reused from EnhancementSettingsView)
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text("Enhancement Prompts")
|
||||
.font(.subheadline)
|
||||
Text("Enhancement Prompt")
|
||||
.font(.headline)
|
||||
.foregroundColor(.primary)
|
||||
|
||||
if enhancementService.allPrompts.isEmpty {
|
||||
Text("No prompts available")
|
||||
.foregroundColor(.secondary)
|
||||
.font(.caption)
|
||||
} else {
|
||||
let columns = [
|
||||
GridItem(.adaptive(minimum: 80, maximum: 100), spacing: 36)
|
||||
]
|
||||
|
||||
LazyVGrid(columns: columns, spacing: 24) {
|
||||
ForEach(enhancementService.allPrompts) { prompt in
|
||||
prompt.promptIcon(
|
||||
isSelected: selectedPromptId == prompt.id,
|
||||
onTap: { selectedPromptId = prompt.id },
|
||||
onEdit: { selectedPromptForEdit = $0 },
|
||||
onDelete: { enhancementService.deletePrompt($0) }
|
||||
)
|
||||
}
|
||||
|
||||
// Plus icon using the same styling as prompt icons
|
||||
CustomPrompt.addNewButton {
|
||||
isEditingPrompt = true
|
||||
}
|
||||
.help("Add new prompt")
|
||||
}
|
||||
.padding(.vertical, 12)
|
||||
.padding(.horizontal, 16)
|
||||
}
|
||||
PromptSelectionGrid(
|
||||
selectedPromptId: selectedPromptId,
|
||||
onPromptTap: { prompt in
|
||||
selectedPromptId = prompt.id
|
||||
},
|
||||
onPromptEdit: { prompt in
|
||||
selectedPromptForEdit = prompt
|
||||
},
|
||||
onPromptDelete: { prompt in
|
||||
enhancementService.deletePrompt(prompt)
|
||||
},
|
||||
onAddNew: {
|
||||
isEditingPrompt = true
|
||||
},
|
||||
assistantTriggerWord: enhancementService.assistantTriggerWord
|
||||
)
|
||||
}
|
||||
|
||||
Divider()
|
||||
|
||||
68
VoiceInk/Views/Components/PromptSelectionGrid.swift
Normal file
68
VoiceInk/Views/Components/PromptSelectionGrid.swift
Normal file
@ -0,0 +1,68 @@
|
||||
import SwiftUI
|
||||
|
||||
/// A reusable grid component for selecting prompts with a plus button to add new ones
|
||||
struct PromptSelectionGrid: View {
|
||||
@EnvironmentObject private var enhancementService: AIEnhancementService
|
||||
|
||||
let selectedPromptId: UUID?
|
||||
let onPromptTap: (CustomPrompt) -> Void
|
||||
let onPromptEdit: (CustomPrompt) -> Void
|
||||
let onPromptDelete: (CustomPrompt) -> Void
|
||||
let onAddNew: () -> Void
|
||||
let assistantTriggerWord: String?
|
||||
|
||||
init(
|
||||
selectedPromptId: UUID?,
|
||||
onPromptTap: @escaping (CustomPrompt) -> Void,
|
||||
onPromptEdit: @escaping (CustomPrompt) -> Void = { _ in },
|
||||
onPromptDelete: @escaping (CustomPrompt) -> Void = { _ in },
|
||||
onAddNew: @escaping () -> Void,
|
||||
assistantTriggerWord: String? = nil
|
||||
) {
|
||||
self.selectedPromptId = selectedPromptId
|
||||
self.onPromptTap = onPromptTap
|
||||
self.onPromptEdit = onPromptEdit
|
||||
self.onPromptDelete = onPromptDelete
|
||||
self.onAddNew = onAddNew
|
||||
self.assistantTriggerWord = assistantTriggerWord
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
if enhancementService.allPrompts.isEmpty {
|
||||
Text("No prompts available")
|
||||
.foregroundColor(.secondary)
|
||||
.font(.caption)
|
||||
} else {
|
||||
let columns = [
|
||||
GridItem(.adaptive(minimum: 80, maximum: 100), spacing: 36)
|
||||
]
|
||||
|
||||
LazyVGrid(columns: columns, spacing: 24) {
|
||||
ForEach(enhancementService.allPrompts) { prompt in
|
||||
prompt.promptIcon(
|
||||
isSelected: selectedPromptId == prompt.id,
|
||||
onTap: {
|
||||
withAnimation(.spring(response: 0.3, dampingFraction: 0.7)) {
|
||||
onPromptTap(prompt)
|
||||
}
|
||||
},
|
||||
onEdit: onPromptEdit,
|
||||
onDelete: onPromptDelete,
|
||||
assistantTriggerWord: assistantTriggerWord
|
||||
)
|
||||
}
|
||||
|
||||
// Plus icon using the same styling as prompt icons
|
||||
CustomPrompt.addNewButton {
|
||||
onAddNew()
|
||||
}
|
||||
.help("Add new prompt")
|
||||
}
|
||||
.padding(.vertical, 12)
|
||||
.padding(.horizontal, 16)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,37 +91,22 @@ struct EnhancementSettingsView: View {
|
||||
|
||||
// Prompts Section
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
if enhancementService.allPrompts.isEmpty {
|
||||
Text("No prompts available")
|
||||
.foregroundColor(.secondary)
|
||||
.font(.caption)
|
||||
} else {
|
||||
let columns = [
|
||||
GridItem(.adaptive(minimum: 80, maximum: 100), spacing: 36)
|
||||
]
|
||||
|
||||
LazyVGrid(columns: columns, spacing: 24) {
|
||||
ForEach(enhancementService.allPrompts) { prompt in
|
||||
prompt.promptIcon(
|
||||
isSelected: enhancementService.selectedPromptId == prompt.id,
|
||||
onTap: { withAnimation(.spring(response: 0.3, dampingFraction: 0.7)) {
|
||||
enhancementService.setActivePrompt(prompt)
|
||||
}},
|
||||
onEdit: { selectedPromptForEdit = $0 },
|
||||
onDelete: { enhancementService.deletePrompt($0) },
|
||||
assistantTriggerWord: enhancementService.assistantTriggerWord
|
||||
)
|
||||
}
|
||||
|
||||
// Plus icon using the same styling as prompt icons
|
||||
CustomPrompt.addNewButton {
|
||||
isEditingPrompt = true
|
||||
}
|
||||
.help("Add new prompt")
|
||||
}
|
||||
.padding(.vertical, 12)
|
||||
.padding(.horizontal, 16)
|
||||
}
|
||||
PromptSelectionGrid(
|
||||
selectedPromptId: enhancementService.selectedPromptId,
|
||||
onPromptTap: { prompt in
|
||||
enhancementService.setActivePrompt(prompt)
|
||||
},
|
||||
onPromptEdit: { prompt in
|
||||
selectedPromptForEdit = prompt
|
||||
},
|
||||
onPromptDelete: { prompt in
|
||||
enhancementService.deletePrompt(prompt)
|
||||
},
|
||||
onAddNew: {
|
||||
isEditingPrompt = true
|
||||
},
|
||||
assistantTriggerWord: enhancementService.assistantTriggerWord
|
||||
)
|
||||
}
|
||||
|
||||
Divider()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user