add mock global search

This commit is contained in:
cheykrym 2025-10-07 05:12:53 +03:00
parent 3d5ba0538f
commit 15ef27b42f
2 changed files with 83 additions and 44 deletions

View File

@ -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" : "Новый пароль",

View File

@ -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 {