wip
This commit is contained in:
parent
9e07aed5fd
commit
c4d70ef77d
|
@ -0,0 +1,80 @@
|
|||
import SwiftUI
|
||||
|
||||
struct ChatsCreateScreenMain: View {
|
||||
@Environment(\.router) var router
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
// Background color
|
||||
Color.Material.Background.light
|
||||
.ignoresSafeArea()
|
||||
|
||||
// Content
|
||||
VStack(spacing: 0) {
|
||||
// Header
|
||||
SharedNavigationBar(
|
||||
leftButton: .init(
|
||||
image: Image(systemName: "xmark"),
|
||||
action: {
|
||||
router.dismissScreen()
|
||||
}
|
||||
),
|
||||
centerText: .init(text: L10n.Chats.Create.Main.title)
|
||||
)
|
||||
|
||||
// List
|
||||
List {
|
||||
// Groups creation buttons
|
||||
SharedListRow(
|
||||
iconType: .image(Image(systemName: "person.2.fill"), .Material.Elements.active),
|
||||
text: L10n.Chats.Create.Main.createGroup,
|
||||
controlType: .none
|
||||
)
|
||||
.onTapGesture {
|
||||
print("Tapped createGroup")
|
||||
}
|
||||
|
||||
SharedListRow(
|
||||
iconType: .image(Image(systemName: "person.2.fill"), .Material.Elements.active),
|
||||
text: L10n.Chats.Create.Main.createPrivateGroup,
|
||||
controlType: .none
|
||||
).onTapGesture {
|
||||
print("Tapped createPrivateGroup")
|
||||
}
|
||||
|
||||
// Channel buttons
|
||||
SharedListRow(
|
||||
iconType: .image(Image(systemName: "globe.americas"), .Material.Elements.active),
|
||||
text: L10n.Chats.Create.Main.createChannel,
|
||||
controlType: .none
|
||||
).onTapGesture {
|
||||
print("Tapped createChannel")
|
||||
}
|
||||
|
||||
SharedListRow(
|
||||
iconType: .image(Image(systemName: "magnifyingglass"), .Material.Elements.active),
|
||||
text: L10n.Chats.Create.Main.findChannel,
|
||||
controlType: .none
|
||||
).onTapGesture {
|
||||
print("Tapped findChannel")
|
||||
}
|
||||
|
||||
// for contacts list (later)
|
||||
// let rosters = store.state.rostersState.rosters.filter { !$0.locallyDeleted }
|
||||
// if rosters.isEmpty {
|
||||
// ChatsCreateRowSeparator()
|
||||
// }
|
||||
}
|
||||
.listStyle(.plain)
|
||||
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct ChatsCreateRowSeparator: View {
|
||||
var body: some View {
|
||||
Text("aa")
|
||||
}
|
||||
}
|
103
Monal/another.im/Views/Main/ChatList/ChatsListScreen.swift
Normal file
103
Monal/another.im/Views/Main/ChatList/ChatsListScreen.swift
Normal file
|
@ -0,0 +1,103 @@
|
|||
import SwiftUI
|
||||
|
||||
struct ChatsListScreen: View {
|
||||
@Environment(\.router) var router
|
||||
@EnvironmentObject var clientsStore: ClientsStore
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
// Background color
|
||||
Color.Material.Background.light
|
||||
.ignoresSafeArea()
|
||||
|
||||
// Content
|
||||
VStack(spacing: 0) {
|
||||
// Header
|
||||
SharedNavigationBar(
|
||||
centerText: .init(text: L10n.ChatsList.title),
|
||||
rightButton: .init(
|
||||
image: Image(systemName: "square.and.pencil"),
|
||||
action: {
|
||||
router.showScreen(.fullScreenCover) { _ in
|
||||
ChatsCreateScreenMain()
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
// Chats list
|
||||
if !clientsStore.actualChats.isEmpty {
|
||||
List {
|
||||
ForEach(elements.indices, id: \.self) { index in
|
||||
let element = elements[index]
|
||||
if let chat = element as? Chat {
|
||||
ChatsRow(chat: chat)
|
||||
} else if let account = element as? String {
|
||||
SharedSectionTitle(text: account)
|
||||
}
|
||||
}
|
||||
}
|
||||
.listStyle(.plain)
|
||||
.background(Color.Material.Background.light)
|
||||
} else {
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var elements: [Any] {
|
||||
if clientsStore.clients.filter({ $0.credentials.isActive }).count == 1 {
|
||||
return clientsStore.actualChats
|
||||
} else {
|
||||
var result: [Any] = []
|
||||
for chat in clientsStore.actualChats {
|
||||
if result.isEmpty {
|
||||
result.append(chat.account)
|
||||
} else if let last = result.last as? Chat, last.account != chat.account {
|
||||
result.append(chat.account)
|
||||
}
|
||||
result.append(chat)
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct ChatsRow: View {
|
||||
@Environment(\.router) var router
|
||||
@EnvironmentObject var clientsStore: ClientsStore
|
||||
|
||||
var chat: Chat
|
||||
|
||||
var body: some View {
|
||||
SharedListRow(iconType: .charCircle(chat.participant), text: chat.participant, controlType: .none)
|
||||
.onTapGesture {
|
||||
Task {
|
||||
router.showModal {
|
||||
LoadingScreen()
|
||||
}
|
||||
defer {
|
||||
router.dismissModal()
|
||||
}
|
||||
|
||||
do {
|
||||
try? await clientsStore.addRosterForNewChatIfNeeded(chat)
|
||||
let (messages, attachments, settings) = try await clientsStore.conversationStores(for: chat)
|
||||
router.showScreen(.push) { _ in
|
||||
ConversationScreen(messagesStore: messages, attachments: attachments, settings: settings)
|
||||
.navigationBarHidden(true)
|
||||
}
|
||||
} catch {
|
||||
router.showAlert(
|
||||
.alert,
|
||||
title: L10n.Global.Error.title,
|
||||
subtitle: L10n.Conversation.startError
|
||||
) {
|
||||
Button(L10n.Global.ok, role: .cancel) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue