Skip to content

Commit adda1d0

Browse files
Improve app sorting and unified icon interactions
1 parent 7438a73 commit adda1d0

4 files changed

Lines changed: 185 additions & 9 deletions

File tree

‎Sources/CategoryViews.swift‎

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,141 @@ struct CategoryMembershipItems: View {
1919
}
2020
}
2121

22+
struct CategoryPickerButton: View {
23+
@EnvironmentObject private var preferences: AppPreferences
24+
let app: AppEntry
25+
@ObservedObject var store: CustomCategoryStore
26+
let onCreate: () -> Void
27+
@State private var isPresented = false
28+
29+
var body: some View {
30+
Button {
31+
isPresented.toggle()
32+
} label: {
33+
Label(preferences.text("category.addTo"), systemImage: "folder.badge.plus")
34+
}
35+
.buttonStyle(IconButtonStyle())
36+
.help(preferences.text("category.addTo"))
37+
.accessibilityLabel(preferences.text("category.addTo"))
38+
.popover(isPresented: $isPresented, arrowEdge: .top) {
39+
CategoryPickerPanel(app: app, store: store) {
40+
isPresented = false
41+
onCreate()
42+
}
43+
}
44+
}
45+
}
46+
47+
private struct CategoryPickerPanel: View {
48+
@EnvironmentObject private var preferences: AppPreferences
49+
let app: AppEntry
50+
@ObservedObject var store: CustomCategoryStore
51+
let onCreate: () -> Void
52+
53+
var body: some View {
54+
VStack(alignment: .leading, spacing: 12) {
55+
Text(preferences.text("category.addTo"))
56+
.font(.callout.weight(.semibold))
57+
.foregroundStyle(.primary)
58+
59+
if store.categories.isEmpty {
60+
Text(preferences.text("category.editorHelp"))
61+
.font(.caption).foregroundStyle(.secondary)
62+
} else {
63+
VStack(spacing: 5) {
64+
ForEach(store.categories) { category in
65+
CategoryPickerRow(
66+
app: app,
67+
category: category,
68+
isSelected: store.contains(app, in: category)
69+
) {
70+
store.setMembership(
71+
app,
72+
in: category,
73+
included: !store.contains(app, in: category)
74+
)
75+
}
76+
}
77+
}
78+
}
79+
80+
Divider()
81+
82+
Button(action: onCreate) {
83+
HStack(spacing: 8) {
84+
Image(systemName: "plus.circle.fill")
85+
Text(preferences.text("category.new"))
86+
.font(.callout.weight(.medium))
87+
Spacer(minLength: 0)
88+
}
89+
.foregroundStyle(Color.accentColor)
90+
.padding(.horizontal, 10)
91+
.padding(.vertical, 8)
92+
.background(Color.accentColor.opacity(0.08), in: RoundedRectangle(cornerRadius: 8))
93+
.contentShape(RoundedRectangle(cornerRadius: 8))
94+
}
95+
.buttonStyle(.plain)
96+
.accessibilityLabel(preferences.text("category.new"))
97+
}
98+
.padding(14)
99+
.frame(width: 272)
100+
.background(Color(nsColor: .controlBackgroundColor), in: RoundedRectangle(cornerRadius: 12))
101+
.overlay {
102+
RoundedRectangle(cornerRadius: 12)
103+
.strokeBorder(Color.primary.opacity(0.07), lineWidth: 1)
104+
.allowsHitTesting(false)
105+
}
106+
}
107+
}
108+
109+
private struct CategoryPickerRow: View {
110+
let app: AppEntry
111+
let category: CustomAppCategory
112+
let isSelected: Bool
113+
let action: () -> Void
114+
@State private var isHovering = false
115+
116+
private var emblemTint: Color { isSelected ? .accentColor : .secondary }
117+
118+
var body: some View {
119+
Button(action: action) {
120+
HStack(spacing: 9) {
121+
Image(systemName: isSelected ? "folder.fill" : "folder")
122+
.font(.system(size: 11, weight: .semibold))
123+
.foregroundStyle(emblemTint)
124+
.frame(width: 22, height: 22)
125+
.background(emblemTint.opacity(0.10), in: RoundedRectangle(cornerRadius: 6))
126+
127+
Text(category.name)
128+
.font(.callout.weight(isSelected ? .medium : .regular))
129+
.foregroundStyle(.primary)
130+
.lineLimit(1)
131+
132+
Spacer(minLength: 8)
133+
134+
Image(systemName: "checkmark")
135+
.font(.system(size: 11, weight: .semibold))
136+
.foregroundStyle(Color.accentColor)
137+
.opacity(isSelected ? 1 : 0)
138+
}
139+
.padding(.horizontal, 9)
140+
.padding(.vertical, 7)
141+
.background(
142+
RoundedRectangle(cornerRadius: 8)
143+
.fill(isSelected ? Color.accentColor.opacity(isHovering ? 0.13 : 0.09)
144+
: Color.primary.opacity(isHovering ? 0.05 : 0.02))
145+
)
146+
.contentShape(RoundedRectangle(cornerRadius: 8))
147+
}
148+
.buttonStyle(.plain)
149+
.onHover { isHovering = $0 }
150+
.animation(.easeOut(duration: 0.16), value: isHovering)
151+
.animation(.easeOut(duration: 0.16), value: isSelected)
152+
.accessibilityLabel(category.name)
153+
.accessibilityValue(isSelected ? "1" : "0")
154+
}
155+
}
156+
22157
struct CategoryEditor: View {
23158
@EnvironmentObject private var preferences: AppPreferences
24159
@Environment(\.dismiss) private var dismiss

‎Sources/Components.swift‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,48 @@ struct AppIcon: View {
1111
}
1212
}
1313

14+
struct IconButtonChrome: ViewModifier {
15+
var tint: Color = .accentColor
16+
var isPressed = false
17+
@State private var isHovering = false
18+
@Environment(\.isEnabled) private var isEnabled
19+
20+
func body(content: Content) -> some View {
21+
content
22+
.labelStyle(.iconOnly)
23+
.font(.system(size: 13, weight: .medium))
24+
.foregroundStyle(isEnabled ? tint : Color(nsColor: .tertiaryLabelColor))
25+
.frame(width: 28, height: 28)
26+
.background(
27+
RoundedRectangle(cornerRadius: 8)
28+
.fill(tint.opacity(isPressed ? 0.16 : isHovering ? 0.12 : 0.07))
29+
)
30+
.overlay {
31+
RoundedRectangle(cornerRadius: 8)
32+
.strokeBorder(tint.opacity(isPressed ? 0.28 : isHovering ? 0.22 : 0.12), lineWidth: 1)
33+
}
34+
.contentShape(RoundedRectangle(cornerRadius: 8))
35+
.onHover { isHovering = $0 && isEnabled }
36+
.animation(.easeOut(duration: 0.18), value: isHovering)
37+
.animation(.easeOut(duration: 0.12), value: isPressed)
38+
}
39+
}
40+
41+
extension View {
42+
func iconButtonChrome(tint: Color = .accentColor, isPressed: Bool = false) -> some View {
43+
modifier(IconButtonChrome(tint: tint, isPressed: isPressed))
44+
}
45+
}
46+
47+
struct IconButtonStyle: ButtonStyle {
48+
var tint: Color = .accentColor
49+
50+
func makeBody(configuration: Configuration) -> some View {
51+
configuration.label
52+
.iconButtonChrome(tint: tint, isPressed: configuration.isPressed)
53+
}
54+
}
55+
1456
struct EmptyState: View {
1557
let symbol: String
1658
let title: String

‎Sources/DetailView.swift‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ struct DetailView: View {
3838
Label(preferences.text("info.refresh"), systemImage: "arrow.clockwise")
3939
.labelStyle(.iconOnly)
4040
}
41-
.buttonStyle(.borderless).help(preferences.text("info.refresh"))
41+
.buttonStyle(IconButtonStyle()).help(preferences.text("info.refresh"))
42+
.accessibilityLabel(preferences.text("info.refresh"))
4243
}
4344
}
4445
.padding(.horizontal, 24).padding(.bottom, 18)
@@ -78,13 +79,7 @@ struct DetailView: View {
7879
}
7980
}
8081
Spacer(minLength: 0)
81-
Menu {
82-
CategoryMembershipItems(app: app, store: categoryStore, onCreate: onCreateCategory)
83-
} label: {
84-
Label(preferences.text("category.addTo"), systemImage: "folder.badge.plus").labelStyle(.iconOnly)
85-
}
86-
.menuStyle(.borderlessButton).fixedSize()
87-
.help(preferences.text("category.addTo")).accessibilityLabel(preferences.text("category.addTo"))
82+
CategoryPickerButton(app: app, store: categoryStore, onCreate: onCreateCategory)
8883
}
8984
ViewThatFits(in: .horizontal) {
9085
HStack(spacing: 8) {
@@ -208,6 +203,7 @@ struct CopyButton: View {
208203
systemImage: copied ? "checkmark" : "doc.on.doc")
209204
.labelStyle(.iconOnly)
210205
}
206+
.buttonStyle(IconButtonStyle(tint: copied ? .green : .accentColor))
211207
.disabled(text.isEmpty)
212208
.help(preferences.text(copied ? "info.copied" : "info.copy"))
213209
.task(id: copied) {
@@ -259,6 +255,7 @@ struct AppIntroductionCard: View {
259255
systemImage: translation == nil ? "character.bubble" : "text.bubble")
260256
.labelStyle(.iconOnly)
261257
}
258+
.buttonStyle(IconButtonStyle())
262259
.disabled(original.isEmpty)
263260
.help(preferences.text(translation == nil ? "info.translate" : "info.original"))
264261
}

‎Sources/Views.swift‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ struct ManagerView: View {
5151
}
5252
private var filtered: [AppEntry] {
5353
let term = query.trimmingCharacters(in: .whitespacesAndNewlines)
54-
return library.apps.filter { app in
54+
let matchingApps = library.apps.filter { app in
5555
let belongs = activeFilter?.contains(app, store: store) ?? (activeCustomCategory.map { categoryStore.contains(app, in: $0) } ?? false)
5656
return belongs && (term.isEmpty || app.matches(term, note: store.note(for: app.path)))
5757
}
58+
return matchingApps.sorted { $0.name.localizedCaseInsensitiveCompare($1.name) == .orderedAscending }
5859
}
5960
private var selectedApp: AppEntry? { library.apps.first { $0.id == selection } }
6061

@@ -362,6 +363,7 @@ struct ManagerBottomBar: View {
362363
Label(preferences.text("library.scan"), systemImage: "arrow.clockwise")
363364
.labelStyle(.iconOnly)
364365
}
366+
.buttonStyle(IconButtonStyle())
365367
.help(preferences.text("library.scan")).disabled(isScanning)
366368
}
367369
.buttonStyle(.borderless).font(.callout)

0 commit comments

Comments
 (0)