damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 92020e551b4d803b840f2ddd39e7768251ffcd8d
parent ccd52a09d8c852fd3e587e38277eed8c1832715f
Author: Suhail Saqan <suhail.saqan@gmail.com>
Date:   Sat,  5 Aug 2023 14:08:07 -0500

reactions: add ability to change order of emojis

Signed-off-by: William Casarin <jb55@jb55.com>
Changelog-Added: Add ability to change order of custom reactions

Diffstat:
Mdamus/Views/Settings/ReactionsSettingsView.swift | 15+++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/damus/Views/Settings/ReactionsSettingsView.swift b/damus/Views/Settings/ReactionsSettingsView.swift @@ -68,8 +68,11 @@ struct ReactionsSettingsView: View { } Section { - List(settings.emoji_reactions, id: \.self) { emoji in - EmojiListItemView(settings: settings, emoji: emoji, recommended: false, showActionButtons: $showActionButtons) + List { + ForEach(Array(zip(settings.emoji_reactions, 1...)), id: \.1) { tup in + EmojiListItemView(settings: settings, emoji: tup.0, recommended: false, showActionButtons: $showActionButtons) + } + .onMove(perform: showActionButtons ? move: nil) } } header: { Text("Emoji Reactions", comment: "Section title for emoji reactions that are currently added.") @@ -79,8 +82,8 @@ struct ReactionsSettingsView: View { if recommended.count > 0 { Section { - List(Array(recommended), id: \.self) { emoji in - EmojiListItemView(settings: settings, emoji: emoji, recommended: true, showActionButtons: $showActionButtons) + List(Array(zip(recommended, 1...)), id: \.1) { tup in + EmojiListItemView(settings: settings, emoji: tup.0, recommended: true, showActionButtons: $showActionButtons) } } header: { Text("Recommended Emojis", comment: "Section title for recommend emojis") @@ -104,6 +107,10 @@ struct ReactionsSettingsView: View { } } + private func move(from: IndexSet, to: Int) { + settings.emoji_reactions.move(fromOffsets: from, toOffset: to) + } + // Returns the emojis that are in the recommended list but the user has not added yet func getMissingRecommendedEmojis(added: [String], recommended: [String] = default_emoji_reactions) -> [String] { let addedSet = Set(added)