mirror of
https://github.com/wahyd4/links.git
synced 2026-08-09 05:06:16 +10:00
Fix quick link enter key event
This commit is contained in:
@@ -9,12 +9,24 @@ struct LinkListView: View {
|
||||
@State private var selectedLink: Link?
|
||||
@State private var showingMarkdownContent = false
|
||||
@State private var markdownLink: Link?
|
||||
@State private var showingTemplateParameters = false
|
||||
@State private var templateLink: Link?
|
||||
@State private var templateParameters: [String: String] = [:]
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
VStack {
|
||||
// Search bar
|
||||
SearchBar(text: $linkViewModel.searchText)
|
||||
SearchBar(text: $linkViewModel.searchText,
|
||||
onCustomContentTap: { link in
|
||||
markdownLink = link
|
||||
showingMarkdownContent = true
|
||||
},
|
||||
onTemplateParameterInput: { link in
|
||||
templateLink = link
|
||||
templateParameters = [:]
|
||||
showingTemplateParameters = true
|
||||
})
|
||||
.environmentObject(linkViewModel)
|
||||
.padding(.horizontal)
|
||||
|
||||
@@ -123,6 +135,18 @@ struct LinkListView: View {
|
||||
.sheet(isPresented: $showingFilterSheet) { FilterView().environmentObject(linkViewModel) }
|
||||
.sheet(item: $selectedLink) { link in LinkDetailView(link: link).environmentObject(linkViewModel) }
|
||||
.sheet(isPresented: $showingMarkdownContent) { if let markdownLink = markdownLink { MarkdownContentView(link: markdownLink) } }
|
||||
.sheet(isPresented: $showingTemplateParameters) {
|
||||
if let templateLink = templateLink {
|
||||
TemplateParameterView(
|
||||
link: templateLink,
|
||||
parameters: $templateParameters,
|
||||
onOpen: { params in
|
||||
linkViewModel.openLink(templateLink, with: params)
|
||||
showingTemplateParameters = false
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear { if linkViewModel.links.isEmpty { linkViewModel.fetchLinks() } }
|
||||
.alert("Error", isPresented: .constant(linkViewModel.errorMessage != nil)) { Button("OK") { linkViewModel.errorMessage = nil } } message: { Text(linkViewModel.errorMessage ?? "") }
|
||||
@@ -245,6 +269,8 @@ struct SearchBar: View {
|
||||
@Binding var text: String
|
||||
@State private var isEditing = false
|
||||
@EnvironmentObject var linkViewModel: LinkViewModel
|
||||
let onCustomContentTap: (Link) -> Void
|
||||
let onTemplateParameterInput: (Link) -> Void
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
@@ -306,10 +332,16 @@ struct SearchBar: View {
|
||||
private func triggerGo() {
|
||||
// Behavior: if first filtered link exists open it; else treat text as URL attempt
|
||||
if let first = linkViewModel.filteredLinks.first {
|
||||
if first.isTemplate {
|
||||
// For simplicity open without parameters (or could prompt)
|
||||
linkViewModel.openLink(first)
|
||||
} else {
|
||||
switch first.linkTypeEnum {
|
||||
case .custom:
|
||||
// Show markdown content for custom links
|
||||
linkViewModel.recordClick(for: first)
|
||||
onCustomContentTap(first)
|
||||
case .template:
|
||||
// Show template parameter input for template links
|
||||
onTemplateParameterInput(first)
|
||||
case .link:
|
||||
// Open URL directly for regular links
|
||||
linkViewModel.openLink(first)
|
||||
}
|
||||
} else if !text.isEmpty {
|
||||
|
||||
Reference in New Issue
Block a user