From 79ea2e1c69942748594fa975ec55b6de3fc7d203 Mon Sep 17 00:00:00 2001 From: Diogo Date: Mon, 16 Dec 2024 23:21:28 +0000 Subject: [PATCH] in memory list --- .../Views/ChatList/ChatListNavLink.swift | 30 ++++++++++++++++++- .../Shared/Views/ChatList/ChatListView.swift | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/apps/ios/Shared/Views/ChatList/ChatListNavLink.swift b/apps/ios/Shared/Views/ChatList/ChatListNavLink.swift index 5de4ff1a59..0847d2ba7c 100644 --- a/apps/ios/Shared/Views/ChatList/ChatListNavLink.swift +++ b/apps/ios/Shared/Views/ChatList/ChatListNavLink.swift @@ -574,6 +574,7 @@ struct TagEditorNavParams { struct ChatListTag: View { var chat: Chat? = nil + var editMode: Bool = false @Environment(\.dismiss) var dismiss: DismissAction @EnvironmentObject var theme: AppTheme @EnvironmentObject var chatTagsModel: ChatTagsModel @@ -583,7 +584,7 @@ struct ChatListTag: View { var chatTagsIds: [Int64] { chat?.chatInfo.contact?.chatTags ?? chat?.chatInfo.groupInfo?.chatTags ?? [] } var body: some View { - List { + let v = List { ForEach(chatTagsModel.userTags, id: \.id) { tag in let text = tag.chatTagText let emoji = tag.chatTagEmoji @@ -661,6 +662,7 @@ struct ChatListTag: View { .opacity(0) ) } + .onMove(perform: moveItem) NavigationLink { ChatListTagEditor(chat: chat) @@ -669,6 +671,16 @@ struct ChatListTag: View { } } .listStyle(.insetGrouped) + + if editMode { + v.toolbar { + ToolbarItem(placement: .topBarTrailing) { + EditButton() + } + } + } else { + v + } } @ViewBuilder private func radioButton(selected: Bool) -> some View { @@ -676,6 +688,22 @@ struct ChatListTag: View { .imageScale(.large) .foregroundStyle(selected ? Color.accentColor : Color(.tertiaryLabel)) } + + private func moveItem(from source: IndexSet, to destination: Int) { + // TODO: API for reordering tags + Task { + do { + await MainActor.run { + chatTagsModel.userTags.move(fromOffsets: source, toOffset: destination) + } + } catch let error { + showAlert( + NSLocalizedString("Error reordering lists", comment: "alert title"), + message: responseError(error) + ) + } + } + } private func tagChat(tagId: Int64, chat: Chat) { Task { diff --git a/apps/ios/Shared/Views/ChatList/ChatListView.swift b/apps/ios/Shared/Views/ChatList/ChatListView.swift index c9f5652bf5..26835d60f7 100644 --- a/apps/ios/Shared/Views/ChatList/ChatListView.swift +++ b/apps/ios/Shared/Views/ChatList/ChatListView.swift @@ -732,7 +732,7 @@ struct ChatTagsView: View { content: { AnyView( NavigationView { - ChatListTag() + ChatListTag(chat: nil, editMode: true) } ) },