Compare commits
	
		
			1 Commits
		
	
	
		
			main
			...
			test-view-
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 5c0c24cff2 | 
@ -4,7 +4,6 @@ import Combine
 | 
			
		||||
final class IncomingMessageCenter: ObservableObject {
 | 
			
		||||
    @Published private(set) var banner: IncomingMessageBanner?
 | 
			
		||||
    @Published var presentedChat: PrivateChatListItem?
 | 
			
		||||
    @Published var pendingNavigation: ChatNavigationTarget?
 | 
			
		||||
    var currentUserId: String?
 | 
			
		||||
    var activeChatId: String?
 | 
			
		||||
 | 
			
		||||
@ -33,13 +32,7 @@ final class IncomingMessageCenter: ObservableObject {
 | 
			
		||||
        guard let banner else { return }
 | 
			
		||||
        activeChatId = banner.message.chatId
 | 
			
		||||
        let chatItem = makeChatItem(from: banner.message)
 | 
			
		||||
        if AppConfig.PRESENT_CHAT_AS_SHEET {
 | 
			
		||||
            presentedChat = chatItem
 | 
			
		||||
            pendingNavigation = nil
 | 
			
		||||
        } else {
 | 
			
		||||
            pendingNavigation = ChatNavigationTarget(chat: chatItem)
 | 
			
		||||
            presentedChat = nil
 | 
			
		||||
        }
 | 
			
		||||
        presentedChat = chatItem
 | 
			
		||||
        dismissBanner()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -52,8 +45,7 @@ final class IncomingMessageCenter: ObservableObject {
 | 
			
		||||
            return
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if AppConfig.PRESENT_CHAT_AS_SHEET,
 | 
			
		||||
           let presentedChat,
 | 
			
		||||
        if let presentedChat,
 | 
			
		||||
           presentedChat.chatId == message.chatId {
 | 
			
		||||
            return
 | 
			
		||||
        }
 | 
			
		||||
@ -122,9 +114,4 @@ final class IncomingMessageCenter: ObservableObject {
 | 
			
		||||
        dismissWorkItem = workItem
 | 
			
		||||
        DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: workItem)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    struct ChatNavigationTarget: Identifiable {
 | 
			
		||||
        let id = UUID()
 | 
			
		||||
        let chat: PrivateChatListItem
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -12,7 +12,6 @@ import UIKit
 | 
			
		||||
 | 
			
		||||
struct ChatsTab: View {
 | 
			
		||||
    @ObservedObject private var loginViewModel: LoginViewModel
 | 
			
		||||
    @Binding private var pendingNavigation: IncomingMessageCenter.ChatNavigationTarget?
 | 
			
		||||
    @Binding var searchRevealProgress: CGFloat
 | 
			
		||||
    @Binding var searchText: String
 | 
			
		||||
    private let searchService = SearchService()
 | 
			
		||||
@ -41,12 +40,10 @@ struct ChatsTab: View {
 | 
			
		||||
 | 
			
		||||
    init(
 | 
			
		||||
        loginViewModel: LoginViewModel,
 | 
			
		||||
        pendingNavigation: Binding<IncomingMessageCenter.ChatNavigationTarget?>,
 | 
			
		||||
        searchRevealProgress: Binding<CGFloat>,
 | 
			
		||||
        searchText: Binding<String>
 | 
			
		||||
    ) {
 | 
			
		||||
        self._loginViewModel = ObservedObject(wrappedValue: loginViewModel)
 | 
			
		||||
        self._pendingNavigation = pendingNavigation
 | 
			
		||||
        self._searchRevealProgress = searchRevealProgress
 | 
			
		||||
        self._searchText = searchText
 | 
			
		||||
    }
 | 
			
		||||
@ -100,13 +97,6 @@ struct ChatsTab: View {
 | 
			
		||||
                globalSearchTask?.cancel()
 | 
			
		||||
                globalSearchTask = nil
 | 
			
		||||
            }
 | 
			
		||||
            .onChange(of: pendingNavigation?.id) { _ in
 | 
			
		||||
                guard let target = pendingNavigation else { return }
 | 
			
		||||
                handleNavigationTarget(target.chat)
 | 
			
		||||
                DispatchQueue.main.async {
 | 
			
		||||
                    pendingNavigation = nil
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ViewBuilder
 | 
			
		||||
@ -552,30 +542,6 @@ private extension ChatsTab {
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    func handleNavigationTarget(_ chatItem: PrivateChatListItem) {
 | 
			
		||||
        dismissKeyboard()
 | 
			
		||||
        if !searchText.isEmpty {
 | 
			
		||||
            searchText = ""
 | 
			
		||||
        }
 | 
			
		||||
        if searchRevealProgress > 0 {
 | 
			
		||||
            withAnimation(.spring(response: 0.35, dampingFraction: 0.75)) {
 | 
			
		||||
                searchRevealProgress = 0
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        let existingChat = viewModel.chats.first(where: { $0.chatId == chatItem.chatId })
 | 
			
		||||
        pendingChatItem = existingChat ?? chatItem
 | 
			
		||||
        selectedChatId = chatItem.chatId
 | 
			
		||||
        isPendingChatActive = true
 | 
			
		||||
 | 
			
		||||
        if existingChat == nil {
 | 
			
		||||
            if loginViewModel.chatLoadingState != .loading {
 | 
			
		||||
                loginViewModel.chatLoadingState = .loading
 | 
			
		||||
            }
 | 
			
		||||
            viewModel.refresh()
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    func handleSearchQueryChange(_ query: String) {
 | 
			
		||||
        let trimmed = query.trimmingCharacters(in: .whitespacesAndNewlines)
 | 
			
		||||
 | 
			
		||||
@ -1195,12 +1161,10 @@ struct ChatsTab_Previews: PreviewProvider {
 | 
			
		||||
        @State private var progress: CGFloat = 1
 | 
			
		||||
        @State private var searchText: String = ""
 | 
			
		||||
        @StateObject private var loginViewModel = LoginViewModel()
 | 
			
		||||
        @State private var pendingNavigation: IncomingMessageCenter.ChatNavigationTarget?
 | 
			
		||||
 | 
			
		||||
        var body: some View {
 | 
			
		||||
            ChatsTab(
 | 
			
		||||
                loginViewModel: loginViewModel,
 | 
			
		||||
                pendingNavigation: $pendingNavigation,
 | 
			
		||||
                searchRevealProgress: $progress,
 | 
			
		||||
                searchText: $searchText
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
@ -2,7 +2,6 @@ import SwiftUI
 | 
			
		||||
 | 
			
		||||
struct MainView: View {
 | 
			
		||||
    @ObservedObject var viewModel: LoginViewModel
 | 
			
		||||
    @EnvironmentObject private var messageCenter: IncomingMessageCenter
 | 
			
		||||
    @State private var selectedTab: Int = 0
 | 
			
		||||
//    @StateObject private var newHomeTabViewModel = NewHomeTabViewModel()
 | 
			
		||||
    
 | 
			
		||||
@ -34,12 +33,6 @@ struct MainView: View {
 | 
			
		||||
 | 
			
		||||
    var body: some View {
 | 
			
		||||
        NavigationView {
 | 
			
		||||
            let pendingNavigationBinding: Binding<IncomingMessageCenter.ChatNavigationTarget?> = AppConfig.PRESENT_CHAT_AS_SHEET
 | 
			
		||||
                ? .constant(nil)
 | 
			
		||||
                : Binding(
 | 
			
		||||
                    get: { messageCenter.pendingNavigation },
 | 
			
		||||
                    set: { messageCenter.pendingNavigation = $0 }
 | 
			
		||||
                )
 | 
			
		||||
            ZStack(alignment: .top) {
 | 
			
		||||
                ZStack(alignment: .leading) { // Выравниваем ZStack по левому краю
 | 
			
		||||
                    // Основной контент
 | 
			
		||||
@ -64,7 +57,6 @@ struct MainView: View {
 | 
			
		||||
 | 
			
		||||
                            ChatsTab(
 | 
			
		||||
                                loginViewModel: viewModel,
 | 
			
		||||
                                pendingNavigation: pendingNavigationBinding,
 | 
			
		||||
                                searchRevealProgress: $chatSearchRevealProgress,
 | 
			
		||||
                                searchText: $chatSearchText
 | 
			
		||||
                            )
 | 
			
		||||
@ -145,15 +137,6 @@ struct MainView: View {
 | 
			
		||||
                menuOffset = presented ? menuWidth : 0
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        .onChange(of: messageCenter.pendingNavigation?.id) { _ in
 | 
			
		||||
            guard !AppConfig.PRESENT_CHAT_AS_SHEET,
 | 
			
		||||
                  messageCenter.pendingNavigation != nil else { return }
 | 
			
		||||
            withAnimation(.easeInOut) {
 | 
			
		||||
                selectedTab = 2
 | 
			
		||||
                isSideMenuPresented = false
 | 
			
		||||
                menuOffset = 0
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        .onChange(of: selectedTab) { newValue in
 | 
			
		||||
            if newValue != 3 {
 | 
			
		||||
                isSettingsPresented = false
 | 
			
		||||
@ -166,7 +149,6 @@ struct MainView_Previews: PreviewProvider {
 | 
			
		||||
    static var previews: some View {
 | 
			
		||||
        let mockViewModel = LoginViewModel()
 | 
			
		||||
        MainView(viewModel: mockViewModel)
 | 
			
		||||
            .environmentObject(IncomingMessageCenter())
 | 
			
		||||
            .environmentObject(ThemeManager())
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -55,6 +55,23 @@ struct yobbleApp: App {
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                }
 | 
			
		||||
                .environmentObject(messageCenter)
 | 
			
		||||
            }
 | 
			
		||||
            .fullScreenCover(item: AppConfig.PRESENT_CHAT_AS_SHEET ? .constant(nil) : $messageCenter.presentedChat) { chatItem in
 | 
			
		||||
                NavigationView {
 | 
			
		||||
                    PrivateChatView(
 | 
			
		||||
                        chat: chatItem,
 | 
			
		||||
                        currentUserId: messageCenter.currentUserId
 | 
			
		||||
                    )
 | 
			
		||||
                        .toolbar {
 | 
			
		||||
                            ToolbarItem(placement: .cancellationAction) {
 | 
			
		||||
                                Button(NSLocalizedString("Закрыть", comment: "")) {
 | 
			
		||||
                                    messageCenter.presentedChat = nil
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                }
 | 
			
		||||
                .environmentObject(messageCenter)
 | 
			
		||||
            }
 | 
			
		||||
            .environmentObject(messageCenter)
 | 
			
		||||
            .environmentObject(themeManager)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user