Skip to content

Commit

Permalink
Merge pull request #722 from Infomaniak/folders
Browse files Browse the repository at this point in the history
feat(MoveMessage): Searchable folder list
  • Loading branch information
valentinperignon authored May 4, 2023
2 parents dc9274d + 84d1e25 commit 0475f97
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
25 changes: 19 additions & 6 deletions Mail/Views/Thread/MoveEmailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,33 @@ struct MoveEmailView: View {
typealias MoveHandler = (Folder) -> Void

// swiftlint:disable empty_count
@ObservedResults(Folder.self, where: { $0.role != .draft && $0.parents.count == 0 && $0.toolType == nil }) var folders
@ObservedResults(Folder.self, where: { $0.role != .draft && $0.toolType == nil }) var folders
@State private var isShowingCreateFolderAlert = false

private var filteredFolders: [NestableFolder] {
guard !searchFilter.isEmpty else {
return NestableFolder.createFoldersHierarchy(from: Array(folders.where { $0.parents.count == 0 }))
}
return folders.filter {
let filter = searchFilter.folding(options: [.caseInsensitive, .diacriticInsensitive], locale: .current)
return $0.verifyFilter(filter)
}.map { NestableFolder(content: $0, children: []) }
}

@State private var searchFilter = ""

let moveAction: MoveAction

var body: some View {
ScrollView {
LazyVStack(spacing: 0) {
listOfFolders(nestableFolders: NestableFolder
.createFoldersHierarchy(from: Array(folders.where { $0.role != nil })))
IKDivider(horizontalPadding: 8)
listOfFolders(nestableFolders: NestableFolder
.createFoldersHierarchy(from: Array(folders.where { $0.role == nil })))
listOfFolders(nestableFolders: filteredFolders.filter { $0.content.role != nil })
if searchFilter.isEmpty {
IKDivider(horizontalPadding: 8)
}
listOfFolders(nestableFolders: filteredFolders.filter { $0.content.role == nil })
}
.searchable(text: $searchFilter, placement: .navigationBarDrawer(displayMode: .always))
}
.navigationTitle(MailResourcesStrings.Localizable.actionMove)
.navigationBarTitleDisplayMode(.inline)
Expand Down
4 changes: 4 additions & 0 deletions MailCore/Models/Folder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ public class Folder: Object, Codable, Comparable, Identifiable {
}
return true
}

public func verifyFilter(_ filter: String) -> Bool {
return localizedName.folding(options: [.caseInsensitive, .diacriticInsensitive], locale: .current).contains(filter)
}

enum CodingKeys: String, CodingKey {
case _id = "id"
Expand Down

0 comments on commit 0475f97

Please sign in to comment.