edit tag (broken menu inside swiftui list)

This commit is contained in:
Diogo
2024-12-14 00:19:27 +00:00
parent b9b43c8260
commit cd16fd7a00
2 changed files with 44 additions and 16 deletions
@@ -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 {
@@ -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<AnyView>? = 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))
}
}