Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion PureMac/Views/CategoryDetailView.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import SwiftUI


struct CategoryDetailView: View {
@EnvironmentObject var vm: AppViewModel
let category: CleaningCategory

@State private var sortDescending: Bool = true

var result: CategoryResult? {
vm.categoryResults[category]
}
Expand Down Expand Up @@ -109,6 +112,14 @@ struct CategoryDetailView: View {
.font(.system(size: 11, weight: .medium))
.foregroundColor(.pmAccentLight)
.buttonStyle(.plain)

Button(action: { sortDescending.toggle() }) {
Image(systemName: "arrow.up.arrow.down")
.font(.system(size: 14))
.foregroundColor(.pmAccentLight)
}
.buttonStyle(.plain)
.help(sortDescending ? "Sorted: Largest First" : "Sorted: Smallest First")
}
.padding(.horizontal, 48)
.padding(.vertical, 8)
Expand All @@ -119,7 +130,7 @@ struct CategoryDetailView: View {

ScrollView {
LazyVStack(spacing: 4) {
ForEach(result.items) { item in
ForEach(sortedItems(result.items)) { item in
FileRow(item: item, color: category.color)
}
}
Expand Down Expand Up @@ -173,6 +184,12 @@ struct CategoryDetailView: View {
}
}

// MARK: - Sort

private func sortedItems(_ items: [CleanableItem]) -> [CleanableItem] {
items.sorted { sortDescending ? $0.size > $1.size : $0.size < $1.size }
}

// MARK: - Action Bar

private var categoryActionBar: some View {
Expand Down
Loading