diff --git a/MastodonSDK/Sources/MastodonCore/Model/Compose/CustomEmojiPickerSection.swift b/MastodonSDK/Sources/MastodonCore/Model/Compose/CustomEmojiPickerSection.swift index 5556a41ee..8a07c2678 100644 --- a/MastodonSDK/Sources/MastodonCore/Model/Compose/CustomEmojiPickerSection.swift +++ b/MastodonSDK/Sources/MastodonCore/Model/Compose/CustomEmojiPickerSection.swift @@ -8,5 +8,6 @@ import Foundation public enum CustomEmojiPickerSection: Equatable, Hashable { + case uncategorized case emoji(name: String) } diff --git a/MastodonSDK/Sources/MastodonUI/DataSource/CustomEmojiPickerSection+Diffable.swift b/MastodonSDK/Sources/MastodonUI/DataSource/CustomEmojiPickerSection+Diffable.swift index 4c142b532..e351a846e 100644 --- a/MastodonSDK/Sources/MastodonUI/DataSource/CustomEmojiPickerSection+Diffable.swift +++ b/MastodonSDK/Sources/MastodonUI/DataSource/CustomEmojiPickerSection+Diffable.swift @@ -11,6 +11,7 @@ import MastodonCore extension CustomEmojiPickerSection { static func collectionViewDiffableDataSource( collectionView: UICollectionView, + authContext: AuthContext, context: AppContext ) -> UICollectionViewDiffableDataSource { let dataSource = UICollectionViewDiffableDataSource(collectionView: collectionView) { [weak context] collectionView, indexPath, item -> UICollectionViewCell? in @@ -44,6 +45,8 @@ extension CustomEmojiPickerSection { case String(describing: CustomEmojiPickerHeaderCollectionReusableView.self): let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: String(describing: CustomEmojiPickerHeaderCollectionReusableView.self), for: indexPath) as! CustomEmojiPickerHeaderCollectionReusableView switch section { + case .uncategorized: + header.titleLabel.text = authContext.mastodonAuthenticationBox.domain.uppercased() case .emoji(let name): header.titleLabel.text = name } diff --git a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel+DataSource.swift b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel+DataSource.swift index fd9cc9d07..0cf093339 100644 --- a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel+DataSource.swift +++ b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel+DataSource.swift @@ -102,11 +102,11 @@ extension ComposeContentViewModel { ) { let diffableDataSource = CustomEmojiPickerSection.collectionViewDiffableDataSource( collectionView: collectionView, + authContext: authContext, context: context ) self.customEmojiPickerDiffableDataSource = diffableDataSource - let domain = authContext.mastodonAuthenticationBox.domain.uppercased() customEmojiViewModel?.emojis // Don't block the main queue .receive(on: DispatchQueue.global(qos: .userInteractive)) @@ -144,11 +144,13 @@ extension ComposeContentViewModel { .map({ (emojiMap) -> NSDiffableDataSourceSnapshot in var snapshot = NSDiffableDataSourceSnapshot() - let customEmojiSection = CustomEmojiPickerSection.emoji(name: domain) - snapshot.appendSections([customEmojiSection]) - snapshot.appendItems(emojiMap.noCategory.map({ emoji in - CustomEmojiPickerItem.emoji(attribute: CustomEmojiPickerItem.CustomEmojiAttribute(emoji: emoji)) - }), toSection: customEmojiSection) + if !emojiMap.noCategory.isEmpty { + let customEmojiSection = CustomEmojiPickerSection.uncategorized + snapshot.appendSections([customEmojiSection]) + snapshot.appendItems(emojiMap.noCategory.map({ emoji in + CustomEmojiPickerItem.emoji(attribute: CustomEmojiPickerItem.CustomEmojiAttribute(emoji: emoji)) + }), toSection: customEmojiSection) + } emojiMap.categorised.keys.sorted().forEach { category in let section = CustomEmojiPickerSection.emoji(name: category) snapshot.appendSections([section])