From 15ef27b42f68e7f7c2292ddeb5ca170ad253bd55 Mon Sep 17 00:00:00 2001 From: cheykrym Date: Tue, 7 Oct 2025 05:12:53 +0300 Subject: [PATCH] add mock global search --- yobble/Resources/Localizable.xcstrings | 8 +- yobble/Views/Tab/ChatsTab.swift | 119 ++++++++++++++++--------- 2 files changed, 83 insertions(+), 44 deletions(-) diff --git a/yobble/Resources/Localizable.xcstrings b/yobble/Resources/Localizable.xcstrings index 9df8ea2..5c039fc 100644 --- a/yobble/Resources/Localizable.xcstrings +++ b/yobble/Resources/Localizable.xcstrings @@ -201,6 +201,9 @@ "Где найти сохранённые черновики?" : { "comment" : "FAQ question: drafts" }, + "Глобальный поиск" : { + "comment" : "Global search section" + }, "Данные" : { }, @@ -480,6 +483,9 @@ } } }, + "Локальные чаты" : { + "comment" : "Local search section" + }, "Мини-приложения" : { "comment" : "Applets", "localizations" : { @@ -730,7 +736,7 @@ } }, "Ничего не найдено" : { - + "comment" : "Global search placeholder" }, "Новый пароль" : { "comment" : "Новый пароль", diff --git a/yobble/Views/Tab/ChatsTab.swift b/yobble/Views/Tab/ChatsTab.swift index dbbc224..31d2b74 100644 --- a/yobble/Views/Tab/ChatsTab.swift +++ b/yobble/Views/Tab/ChatsTab.swift @@ -79,53 +79,36 @@ struct ChatsTab: View { .listRowInsets(EdgeInsets(top: 8, leading: 16, bottom: 8, trailing: 16)) } - if filteredChats.isEmpty && isSearching { - Section { - emptySearchResultView + if isSearching { + Section(header: localSearchHeader) { + if localSearchResults.isEmpty { + emptySearchResultView + .listRowInsets(EdgeInsets(top: 24, leading: 16, bottom: 24, trailing: 16)) + .listRowSeparator(.hidden) + } else { + ForEach(localSearchResults) { chat in + chatRowItem(for: chat) + } + } + } + + Section(header: globalSearchHeader) { + Text(NSLocalizedString("Ничего не найдено", comment: "Global search placeholder")) + .font(.footnote) + .foregroundColor(.secondary) + .padding(.vertical, 12) + .frame(maxWidth: .infinity, alignment: .leading) + .listRowInsets(EdgeInsets(top: 12, leading: 16, bottom: 12, trailing: 16)) + .listRowSeparator(.hidden) } - .listRowInsets(EdgeInsets(top: 24, leading: 16, bottom: 24, trailing: 16)) - .listRowSeparator(.hidden) } else { - ForEach(filteredChats) { chat in - Button { - selectedChatId = chat.chatId - } label: { - ChatRowView(chat: chat, currentUserId: currentUserId) - .contentShape(Rectangle()) - } - .buttonStyle(.plain) - .contextMenu { - Button(action: {}) { - Label(NSLocalizedString("Закрепить (скоро)", comment: ""), systemImage: "pin") - } - - Button(action: {}) { - Label(NSLocalizedString("Без звука (скоро)", comment: ""), systemImage: "speaker.slash") - } - - Button(role: .destructive, action: {}) { - Label(NSLocalizedString("Удалить чат (скоро)", comment: ""), systemImage: "trash") - } - } - .background( - NavigationLink( - destination: ChatPlaceholderView(chat: chat), - tag: chat.chatId, - selection: $selectedChatId - ) { - EmptyView() - } - .hidden() - ) - .onAppear { - guard !isSearching else { return } - viewModel.loadMoreIfNeeded(currentItem: chat) - } + ForEach(viewModel.chats) { chat in + chatRowItem(for: chat) } - } - if viewModel.isLoadingMore && !isSearching { - loadingMoreRow + if viewModel.isLoadingMore { + loadingMoreRow + } } } .listStyle(.plain) @@ -201,6 +184,18 @@ struct ChatsTab: View { } } + private var localSearchResults: [PrivateChatListItem] { + Array(filteredChats.prefix(5)) + } + + private var localSearchHeader: some View { + Text(NSLocalizedString("Локальные чаты", comment: "Local search section")) + } + + private var globalSearchHeader: some View { + Text(NSLocalizedString("Глобальный поиск", comment: "Global search section")) + } + private var emptySearchResultView: some View { VStack(spacing: 8) { Image(systemName: "text.magnifyingglass") @@ -271,6 +266,44 @@ struct ChatsTab: View { } .listRowSeparator(.hidden) } + + @ViewBuilder + private func chatRowItem(for chat: PrivateChatListItem) -> some View { + Button { + selectedChatId = chat.chatId + } label: { + ChatRowView(chat: chat, currentUserId: currentUserId) + .contentShape(Rectangle()) + } + .buttonStyle(.plain) + .contextMenu { + Button(action: {}) { + Label(NSLocalizedString("Закрепить (скоро)", comment: ""), systemImage: "pin") + } + + Button(action: {}) { + Label(NSLocalizedString("Без звука (скоро)", comment: ""), systemImage: "speaker.slash") + } + + Button(role: .destructive, action: {}) { + Label(NSLocalizedString("Удалить чат (скоро)", comment: ""), systemImage: "trash") + } + } + .background( + NavigationLink( + destination: ChatPlaceholderView(chat: chat), + tag: chat.chatId, + selection: $selectedChatId + ) { + EmptyView() + } + .hidden() + ) + .onAppear { + guard !isSearching else { return } + viewModel.loadMoreIfNeeded(currentItem: chat) + } + } } private extension ChatsTab {