From e32c1d39bcb9617146cde9f0bb7ba31825ff3ebe Mon Sep 17 00:00:00 2001 From: Francesco <100066266+cranci1@users.noreply.github.com> Date: Sun, 25 May 2025 11:03:17 +0200 Subject: [PATCH] test --- Sora/Views/SearchView.swift | 69 +++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 38 deletions(-) diff --git a/Sora/Views/SearchView.swift b/Sora/Views/SearchView.swift index 4677ee4..8fae271 100644 --- a/Sora/Views/SearchView.swift +++ b/Sora/Views/SearchView.swift @@ -83,59 +83,51 @@ struct SearchView: View { } } - if isSearchFieldFocused && !searchHistory.isEmpty && searchText.isEmpty { - VStack(alignment: .leading, spacing: 0) { + if !searchHistory.isEmpty && searchText.isEmpty { + VStack(alignment: .leading, spacing: 8) { HStack { - Text("Recent Searches") - .font(.subheadline) + Text("Recent") + .font(.caption) .foregroundColor(.secondary) Spacer() Button("Clear") { clearSearchHistory() } - .font(.caption) + .font(.caption2) .foregroundColor(.accentColor) } .padding(.horizontal) - .padding(.top, 8) - ForEach(Array(searchHistory.enumerated()), id: \.offset) { index, searchTerm in - Button(action: { - searchText = searchTerm - isSearchFieldFocused = false - performSearch() - }) { - HStack { - Image(systemName: "clock") - .foregroundColor(.secondary) - .font(.caption) - Text(searchTerm) - .foregroundColor(.primary) - Spacer() + ScrollView(.horizontal, showsIndicators: false) { + HStack(spacing: 8) { + ForEach(Array(searchHistory.prefix(5).enumerated()), id: \.offset) { index, searchTerm in Button(action: { - removeFromHistory(at: index) + searchText = searchTerm + performSearch() }) { - Image(systemName: "xmark.circle.fill") - .foregroundColor(.secondary) - .font(.caption) + HStack(spacing: 4) { + Text(searchTerm) + .font(.caption) + .lineLimit(1) + Button(action: { + removeFromHistory(at: index) + }) { + Image(systemName: "xmark") + .font(.caption2) + } + } + .padding(.horizontal, 12) + .padding(.vertical, 6) + .background(Color(.systemGray5)) + .cornerRadius(16) } + .buttonStyle(PlainButtonStyle()) } - .padding(.horizontal) - .padding(.vertical, 8) - } - .buttonStyle(PlainButtonStyle()) - - if index < searchHistory.count - 1 { - Divider() - .padding(.leading, 40) } + .padding(.horizontal) } } - .background(Color(.systemBackground)) - .cornerRadius(8) - .shadow(color: Color.black.opacity(0.1), radius: 2, y: 1) - .padding(.horizontal) - .padding(.top, 4) + .padding(.top, 8) } if selectedModule == nil { @@ -361,8 +353,9 @@ struct SearchView: View { searchHistory.removeAll { $0.lowercased() == trimmedTerm.lowercased() } searchHistory.insert(trimmedTerm, at: 0) - if searchHistory.count > 10 { - searchHistory = Array(searchHistory.prefix(10)) + // Keep only last 5 searches for more practical display + if searchHistory.count > 5 { + searchHistory = Array(searchHistory.prefix(5)) } saveSearchHistory()