Compare commits
2 Commits
b49281de91
...
15ef27b42f
| Author | SHA1 | Date | |
|---|---|---|---|
| 15ef27b42f | |||
| 3d5ba0538f |
@ -13,8 +13,7 @@ struct TopBarView: View {
|
|||||||
// Привязка для управления боковым меню
|
// Привязка для управления боковым меню
|
||||||
@Binding var isSideMenuPresented: Bool
|
@Binding var isSideMenuPresented: Bool
|
||||||
@Binding var chatSearchRevealProgress: CGFloat
|
@Binding var chatSearchRevealProgress: CGFloat
|
||||||
|
@Binding var chatSearchText: String
|
||||||
@State private var searchText: String = ""
|
|
||||||
|
|
||||||
var isHomeTab: Bool {
|
var isHomeTab: Bool {
|
||||||
return title == "Home"
|
return title == "Home"
|
||||||
@ -154,12 +153,12 @@ private extension TopBarView {
|
|||||||
HStack(spacing: 8) {
|
HStack(spacing: 8) {
|
||||||
Image(systemName: "magnifyingglass")
|
Image(systemName: "magnifyingglass")
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
TextField(NSLocalizedString("Поиск", comment: ""), text: $searchText)
|
TextField(NSLocalizedString("Поиск", comment: ""), text: $chatSearchText)
|
||||||
.textFieldStyle(.plain)
|
.textFieldStyle(.plain)
|
||||||
.textInputAutocapitalization(.never)
|
.textInputAutocapitalization(.never)
|
||||||
.autocorrectionDisabled()
|
.autocorrectionDisabled()
|
||||||
if !searchText.isEmpty {
|
if !chatSearchText.isEmpty {
|
||||||
Button(action: { searchText = "" }) {
|
Button(action: { chatSearchText = "" }) {
|
||||||
Image(systemName: "xmark.circle.fill")
|
Image(systemName: "xmark.circle.fill")
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
}
|
}
|
||||||
@ -182,6 +181,7 @@ struct TopBarView_Previews: PreviewProvider {
|
|||||||
@State private var isSideMenuPresented = false
|
@State private var isSideMenuPresented = false
|
||||||
@State private var revealProgress: CGFloat = 1
|
@State private var revealProgress: CGFloat = 1
|
||||||
@StateObject private var viewModel = LoginViewModel()
|
@StateObject private var viewModel = LoginViewModel()
|
||||||
|
@State private var searchText: String = ""
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
TopBarView(
|
TopBarView(
|
||||||
@ -190,7 +190,8 @@ struct TopBarView_Previews: PreviewProvider {
|
|||||||
accounts: [selectedAccount],
|
accounts: [selectedAccount],
|
||||||
viewModel: viewModel,
|
viewModel: viewModel,
|
||||||
isSideMenuPresented: $isSideMenuPresented,
|
isSideMenuPresented: $isSideMenuPresented,
|
||||||
chatSearchRevealProgress: $revealProgress
|
chatSearchRevealProgress: $revealProgress,
|
||||||
|
chatSearchText: $searchText
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -201,6 +201,9 @@
|
|||||||
"Где найти сохранённые черновики?" : {
|
"Где найти сохранённые черновики?" : {
|
||||||
"comment" : "FAQ question: drafts"
|
"comment" : "FAQ question: drafts"
|
||||||
},
|
},
|
||||||
|
"Глобальный поиск" : {
|
||||||
|
"comment" : "Global search section"
|
||||||
|
},
|
||||||
"Данные" : {
|
"Данные" : {
|
||||||
|
|
||||||
},
|
},
|
||||||
@ -480,6 +483,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"Локальные чаты" : {
|
||||||
|
"comment" : "Local search section"
|
||||||
|
},
|
||||||
"Мини-приложения" : {
|
"Мини-приложения" : {
|
||||||
"comment" : "Applets",
|
"comment" : "Applets",
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
@ -730,7 +736,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Ничего не найдено" : {
|
"Ничего не найдено" : {
|
||||||
|
"comment" : "Global search placeholder"
|
||||||
},
|
},
|
||||||
"Новый пароль" : {
|
"Новый пароль" : {
|
||||||
"comment" : "Новый пароль",
|
"comment" : "Новый пароль",
|
||||||
|
|||||||
@ -13,17 +13,18 @@ import UIKit
|
|||||||
struct ChatsTab: View {
|
struct ChatsTab: View {
|
||||||
var currentUserId: String?
|
var currentUserId: String?
|
||||||
@Binding var searchRevealProgress: CGFloat
|
@Binding var searchRevealProgress: CGFloat
|
||||||
|
@Binding var searchText: String
|
||||||
@StateObject private var viewModel = PrivateChatsViewModel()
|
@StateObject private var viewModel = PrivateChatsViewModel()
|
||||||
@State private var selectedChatId: String?
|
@State private var selectedChatId: String?
|
||||||
@State private var searchText: String = ""
|
|
||||||
@State private var searchDragStartProgress: CGFloat = 0
|
@State private var searchDragStartProgress: CGFloat = 0
|
||||||
@State private var isSearchGestureActive: Bool = false
|
@State private var isSearchGestureActive: Bool = false
|
||||||
|
|
||||||
private let searchRevealDistance: CGFloat = 90
|
private let searchRevealDistance: CGFloat = 90
|
||||||
|
|
||||||
init(currentUserId: String? = nil, searchRevealProgress: Binding<CGFloat>) {
|
init(currentUserId: String? = nil, searchRevealProgress: Binding<CGFloat>, searchText: Binding<String>) {
|
||||||
self.currentUserId = currentUserId
|
self.currentUserId = currentUserId
|
||||||
self._searchRevealProgress = searchRevealProgress
|
self._searchRevealProgress = searchRevealProgress
|
||||||
|
self._searchText = searchText
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@ -78,53 +79,36 @@ struct ChatsTab: View {
|
|||||||
.listRowInsets(EdgeInsets(top: 8, leading: 16, bottom: 8, trailing: 16))
|
.listRowInsets(EdgeInsets(top: 8, leading: 16, bottom: 8, trailing: 16))
|
||||||
}
|
}
|
||||||
|
|
||||||
if filteredChats.isEmpty && isSearching {
|
if isSearching {
|
||||||
Section {
|
Section(header: localSearchHeader) {
|
||||||
emptySearchResultView
|
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 {
|
} else {
|
||||||
ForEach(filteredChats) { chat in
|
ForEach(viewModel.chats) { chat in
|
||||||
Button {
|
chatRowItem(for: chat)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if viewModel.isLoadingMore && !isSearching {
|
if viewModel.isLoadingMore {
|
||||||
loadingMoreRow
|
loadingMoreRow
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.listStyle(.plain)
|
.listStyle(.plain)
|
||||||
@ -143,31 +127,6 @@ struct ChatsTab: View {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private var searchBar: some View {
|
|
||||||
HStack(spacing: 8) {
|
|
||||||
Image(systemName: "magnifyingglass")
|
|
||||||
.foregroundColor(.secondary)
|
|
||||||
TextField(NSLocalizedString("Поиск", comment: ""), text: $searchText)
|
|
||||||
.textFieldStyle(.plain)
|
|
||||||
.textInputAutocapitalization(.never)
|
|
||||||
.autocorrectionDisabled()
|
|
||||||
if !searchText.isEmpty {
|
|
||||||
Button(action: { searchText = "" }) {
|
|
||||||
Image(systemName: "xmark.circle.fill")
|
|
||||||
.foregroundColor(.secondary)
|
|
||||||
}
|
|
||||||
.buttonStyle(.plain)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(.horizontal, 12)
|
|
||||||
.padding(.vertical, 6)
|
|
||||||
.frame(minHeight: 36)
|
|
||||||
.background(
|
|
||||||
RoundedRectangle(cornerRadius: 12, style: .continuous)
|
|
||||||
.fill(Color(UIColor.secondarySystemBackground))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private var searchBarGesture: some Gesture {
|
private var searchBarGesture: some Gesture {
|
||||||
DragGesture(minimumDistance: 10, coordinateSpace: .local)
|
DragGesture(minimumDistance: 10, coordinateSpace: .local)
|
||||||
.onChanged { value in
|
.onChanged { value in
|
||||||
@ -225,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 {
|
private var emptySearchResultView: some View {
|
||||||
VStack(spacing: 8) {
|
VStack(spacing: 8) {
|
||||||
Image(systemName: "text.magnifyingglass")
|
Image(systemName: "text.magnifyingglass")
|
||||||
@ -295,6 +266,44 @@ struct ChatsTab: View {
|
|||||||
}
|
}
|
||||||
.listRowSeparator(.hidden)
|
.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 {
|
private extension ChatsTab {
|
||||||
@ -624,9 +633,10 @@ private struct ChatRowView: View {
|
|||||||
struct ChatsTab_Previews: PreviewProvider {
|
struct ChatsTab_Previews: PreviewProvider {
|
||||||
struct Wrapper: View {
|
struct Wrapper: View {
|
||||||
@State private var progress: CGFloat = 1
|
@State private var progress: CGFloat = 1
|
||||||
|
@State private var searchText: String = ""
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ChatsTab(searchRevealProgress: $progress)
|
ChatsTab(searchRevealProgress: $progress, searchText: $searchText)
|
||||||
.environmentObject(ThemeManager())
|
.environmentObject(ThemeManager())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,7 @@ struct MainView: View {
|
|||||||
@State private var isSideMenuPresented = false
|
@State private var isSideMenuPresented = false
|
||||||
@State private var menuOffset: CGFloat = 0
|
@State private var menuOffset: CGFloat = 0
|
||||||
@State private var chatSearchRevealProgress: CGFloat = 0
|
@State private var chatSearchRevealProgress: CGFloat = 0
|
||||||
|
@State private var chatSearchText: String = ""
|
||||||
|
|
||||||
private var tabTitle: String {
|
private var tabTitle: String {
|
||||||
switch selectedTab {
|
switch selectedTab {
|
||||||
@ -40,7 +41,8 @@ struct MainView: View {
|
|||||||
accounts: accounts,
|
accounts: accounts,
|
||||||
viewModel: viewModel,
|
viewModel: viewModel,
|
||||||
isSideMenuPresented: $isSideMenuPresented,
|
isSideMenuPresented: $isSideMenuPresented,
|
||||||
chatSearchRevealProgress: $chatSearchRevealProgress
|
chatSearchRevealProgress: $chatSearchRevealProgress,
|
||||||
|
chatSearchText: $chatSearchText
|
||||||
)
|
)
|
||||||
|
|
||||||
ZStack {
|
ZStack {
|
||||||
@ -52,7 +54,8 @@ struct MainView: View {
|
|||||||
|
|
||||||
ChatsTab(
|
ChatsTab(
|
||||||
currentUserId: viewModel.userId.isEmpty ? nil : viewModel.userId,
|
currentUserId: viewModel.userId.isEmpty ? nil : viewModel.userId,
|
||||||
searchRevealProgress: $chatSearchRevealProgress
|
searchRevealProgress: $chatSearchRevealProgress,
|
||||||
|
searchText: $chatSearchText
|
||||||
)
|
)
|
||||||
.opacity(selectedTab == 2 ? 1 : 0)
|
.opacity(selectedTab == 2 ? 1 : 0)
|
||||||
.allowsHitTesting(selectedTab == 2)
|
.allowsHitTesting(selectedTab == 2)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user