in memory list

This commit is contained in:
Diogo
2024-12-16 23:21:28 +00:00
parent 9676c0bfe7
commit 79ea2e1c69
2 changed files with 30 additions and 2 deletions
@@ -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 {
@@ -732,7 +732,7 @@ struct ChatTagsView: View {
content: {
AnyView(
NavigationView {
ChatListTag()
ChatListTag(chat: nil, editMode: true)
}
)
},