Compare commits

...

2 Commits

Author SHA1 Message Date
8c03574e6a add line limit 2025-10-08 06:49:25 +03:00
bef74e4ebd chatstab patch 2025-10-08 06:27:10 +03:00

View File

@ -15,6 +15,7 @@ struct ChatsTab: View {
@Binding var searchRevealProgress: CGFloat @Binding var searchRevealProgress: CGFloat
@Binding var searchText: String @Binding var searchText: String
private let searchService = SearchService() private let searchService = SearchService()
@AppStorage("chatRowMessageLineLimit") private var messageLineLimitSetting: Int = 2
@StateObject private var viewModel = PrivateChatsViewModel() @StateObject private var viewModel = PrivateChatsViewModel()
@State private var selectedChatId: String? @State private var selectedChatId: String?
@State private var searchDragStartProgress: CGFloat = 0 @State private var searchDragStartProgress: CGFloat = 0
@ -178,6 +179,17 @@ struct ChatsTab: View {
!searchText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty !searchText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
} }
private var messagePreviewLineLimit: Int {
switch messageLineLimitSetting {
case ..<1:
return 1
case 1...2:
return messageLineLimitSetting
default:
return 2
}
}
private var filteredChats: [PrivateChatListItem] { private var filteredChats: [PrivateChatListItem] {
let trimmedQuery = searchText.trimmingCharacters(in: .whitespacesAndNewlines) let trimmedQuery = searchText.trimmingCharacters(in: .whitespacesAndNewlines)
guard !trimmedQuery.isEmpty else { return viewModel.chats } guard !trimmedQuery.isEmpty else { return viewModel.chats }
@ -301,7 +313,11 @@ struct ChatsTab: View {
Button { Button {
selectedChatId = chat.chatId selectedChatId = chat.chatId
} label: { } label: {
ChatRowView(chat: chat, currentUserId: currentUserId) ChatRowView(
chat: chat,
currentUserId: currentUserId,
messageLimitLine: messagePreviewLineLimit
)
.contentShape(Rectangle()) .contentShape(Rectangle())
} }
.buttonStyle(.plain) .buttonStyle(.plain)
@ -328,6 +344,8 @@ struct ChatsTab: View {
} }
.hidden() .hidden()
) )
.listRowInsets(EdgeInsets(top: 8, leading: 16, bottom: 8, trailing: 16))
// .listRowSeparator(.hidden)
.onAppear { .onAppear {
guard !isSearching else { return } guard !isSearching else { return }
viewModel.loadMoreIfNeeded(currentItem: chat) viewModel.loadMoreIfNeeded(currentItem: chat)
@ -603,6 +621,8 @@ private struct SearchResultPlaceholderView: View {
private struct ChatRowView: View { private struct ChatRowView: View {
let chat: PrivateChatListItem let chat: PrivateChatListItem
let currentUserId: String? let currentUserId: String?
let messageLimitLine: Int
private let avatarSize: CGFloat = 52
private var title: String { private var title: String {
switch chat.chatType { switch chat.chatType {
@ -782,17 +802,17 @@ private struct ChatRowView: View {
HStack(spacing: 12) { HStack(spacing: 12) {
Circle() Circle()
.fill(avatarBackgroundColor) .fill(avatarBackgroundColor)
.frame(width: 44, height: 44) .frame(width: avatarSize, height: avatarSize)
.overlay( .overlay(
Group { Group {
if isDeletedUser { if isDeletedUser {
Image(systemName: deletedUserSymbolName) Image(systemName: deletedUserSymbolName)
.symbolRenderingMode(.hierarchical) .symbolRenderingMode(.hierarchical)
.font(.system(size: 20, weight: .semibold)) .font(.system(size: avatarSize * 0.45, weight: .semibold))
.foregroundColor(avatarTextColor) .foregroundColor(avatarTextColor)
} else { } else {
Text(initial) Text(initial)
.font(.headline) .font(.system(size: avatarSize * 0.5, weight: .semibold))
.foregroundColor(avatarTextColor) .foregroundColor(avatarTextColor)
} }
} }
@ -848,7 +868,7 @@ private struct ChatRowView: View {
Text(messagePreview) Text(messagePreview)
.font(.subheadline) .font(.subheadline)
.foregroundColor(subtitleColor) .foregroundColor(subtitleColor)
.lineLimit(2) .lineLimit(messageLimitLine)
.truncationMode(.tail) .truncationMode(.tail)
} }
.frame(maxWidth: .infinity, alignment: .leading) .frame(maxWidth: .infinity, alignment: .leading)