From cd16fd7a00c6b948209fbc968ffbaad381d6dfd4 Mon Sep 17 00:00:00 2001 From: Diogo Date: Sat, 14 Dec 2024 00:19:27 +0000 Subject: [PATCH] edit tag (broken menu inside swiftui list) --- .../Views/ChatList/ChatListNavLink.swift | 21 +++++----- .../Shared/Views/ChatList/ChatListView.swift | 39 ++++++++++++++++--- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/apps/ios/Shared/Views/ChatList/ChatListNavLink.swift b/apps/ios/Shared/Views/ChatList/ChatListNavLink.swift index 0100eac30d..ad9574f760 100644 --- a/apps/ios/Shared/Views/ChatList/ChatListNavLink.swift +++ b/apps/ios/Shared/Views/ChatList/ChatListNavLink.swift @@ -345,7 +345,7 @@ struct ChatListNavLink: View { AnyView( NavigationView { if chatTagsModel.tags.isEmpty { - CreateChatListTag(chat: chat) + ChatListTagEditor(chat: chat) } else { ChatListTag(chat: chat) } @@ -574,7 +574,7 @@ struct ChatListTag: View { var body: some View { List { NavigationLink { - CreateChatListTag(chat: chat) + ChatListTagEditor(chat: chat) } label: { Label("Create list", systemImage: "plus") } @@ -683,7 +683,7 @@ struct ChatListTag: View { } struct EmojiPickerView: UIViewControllerRepresentable { - @Binding var selectedEmoji: Emoji? + @Binding var selectedEmoji: String? @Binding var showingPicker: Bool @Environment(\.presentationMode) var presentationMode @@ -695,7 +695,7 @@ struct EmojiPickerView: UIViewControllerRepresentable { } func emojiPicker(_ picker: ElegantEmojiPicker, didSelectEmoji emoji: Emoji?) { - parent.selectedEmoji = emoji + parent.selectedEmoji = emoji?.emoji parent.showingPicker = false picker.dismiss(animated: true) } @@ -731,13 +731,14 @@ struct EmojiPickerView: UIViewControllerRepresentable { } } -struct CreateChatListTag: View { +struct ChatListTagEditor: View { var chat: Chat? + var editMode = false @Environment(\.dismiss) var dismiss: DismissAction @EnvironmentObject var chatTagsModel: ChatTagsModel @EnvironmentObject var m: ChatModel - @State private var emoji: Emoji? = nil - @State private var name: String = "" + @State var emoji: String? = nil + @State var name: String = "" @State private var isPickerPresented = false var body: some View { @@ -748,7 +749,7 @@ struct CreateChatListTag: View { isPickerPresented = true } label: { if let emoji { - Text(emoji.emoji) + Text(emoji) } else { Image(systemName: "face.smiling") .resizable() @@ -763,7 +764,7 @@ struct CreateChatListTag: View { Button { createChatTag() } label: { - Text("Create list") + Text(NSLocalizedString(editMode ? "Change list" : "Create List", comment: "list editor button")) } .disabled(name.isEmpty) } @@ -782,7 +783,7 @@ struct CreateChatListTag: View { let (userTags, chatTags) = try await apiCreateChatTag( type: chat.chatInfo.chatType, id: chat.chatInfo.apiId, - tag: ChatTagData(emoji: emoji?.emoji ?? "😂", text: name) + tag: ChatTagData(emoji: emoji ?? "😂", text: name) ) await MainActor.run { diff --git a/apps/ios/Shared/Views/ChatList/ChatListView.swift b/apps/ios/Shared/Views/ChatList/ChatListView.swift index 089ea56203..9ce257edb0 100644 --- a/apps/ios/Shared/Views/ChatList/ChatListView.swift +++ b/apps/ios/Shared/Views/ChatList/ChatListView.swift @@ -688,7 +688,8 @@ struct ChatTagsView: View { @EnvironmentObject var chatTagsModel: ChatTagsModel @EnvironmentObject var chatModel: ChatModel @State private var showChatListTagCreate = false - + @State private var sheet: SomeSheet? = nil + var body: some View { HStack { let presetFilters = presetTagFilters() @@ -717,6 +718,33 @@ struct ChatTagsView: View { .onTapGesture { setSelectedTag(tag) } + .contextMenu { + Button { + sheet = SomeSheet( + content: { + AnyView( + NavigationView { + ChatListTagEditor(editMode: true, emoji: emoji, name: text) + } + ) + }, + id: "list edit sheet" + ) + } label: { + Label( + NSLocalizedString("Edit", comment: "tag action"), + systemImage: "pencil" + ) + } + Button(role: .destructive) { + print("Delete \(text)") + } label: { + Label( + NSLocalizedString("Delete", comment: "tag action"), + systemImage: "trash" + ) + } + } } } } @@ -735,19 +763,18 @@ struct ChatTagsView: View { .onChange(of: chatModel.currentUser?.userId) { _ in getChatTags() } - .sheet(isPresented: $showChatListTagCreate) { + .sheet(item: $sheet) { if #available(iOS 16.0, *) { - createChatListTagView() - .presentationDetents([.fraction(0.3)]) + $0.content.presentationDetents([.fraction(0.3)]) } else { - createChatListTagView() + $0.content } } } @ViewBuilder private func createChatListTagView() -> some View { NavigationView { - CreateChatListTag() + ChatListTagEditor() .modifier(ThemedBackground(grouped: true)) } }