Skip to content
Merged
Show file tree
Hide file tree
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
65 changes: 8 additions & 57 deletions Symi/Sources/Features/Capture/EntryFlowCoordinatorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,22 @@ private struct EntryHeadacheStepView: View {
PainGaugeView(value: $coordinator.draft.intensity)

InputFlowFieldGroup(title: "Wo spürst du den Schmerz?") {
HeadacheLocationGrid {
HeadacheOptionGrid {
ForEach(visiblePainLocations) { location in
PainLocationSelectionTile(
option: location,
isSelected: coordinator.draft.selectedPainLocations.contains(location.title),
theme: .pain,
accessibilityIdentifier: "entry-location-\(location.title)"
) {
toggle(location.title, in: &coordinator.draft.selectedPainLocations)
coordinator.draft.selectedPainLocations.toggleMembership(location.title)
}
}
}
}

InputFlowFieldGroup(title: "Tagesbereich") {
HeadacheDayPartGrid {
HeadacheOptionGrid {
ForEach(EntryDayPartPreset.allCases) { preset in
InputFlowSelectionTile(
title: preset.title,
Expand Down Expand Up @@ -225,14 +225,6 @@ private struct EntryHeadacheStepView: View {

coordinator.draft.selectedPainLocations = ["Schläfen"]
}

private func toggle(_ option: String, in selection: inout Set<String>) {
if selection.contains(option) {
selection.remove(option)
} else {
selection.insert(option)
}
}
}

private extension EntryDayPartPreset {
Expand Down Expand Up @@ -324,50 +316,17 @@ private struct PainLocationSelectionTile: View {
return SymiColors.subtleSeparator(for: colorScheme).opacity(SymiOpacity.strongSurface)
}
}
private struct HeadacheLocationGrid<Content: View>: View {
private struct HeadacheOptionGrid<Content: View>: View {
let content: Content

init(@ViewBuilder content: () -> Content) {
self.content = content()
}

var body: some View {
LazyVGrid(
columns: Array(
repeating: GridItem(
.flexible(minimum: SymiSize.headacheOptionGridMinWidth),
spacing: SymiSpacing.xs,
alignment: .top
),
count: SymiSize.headacheOptionGridColumnCount
),
alignment: .leading,
spacing: SymiSpacing.xs
) {
content
}
}
}

private struct HeadacheDayPartGrid<Content: View>: View {
let content: Content

init(@ViewBuilder content: () -> Content) {
self.content = content()
}

var body: some View {
LazyVGrid(
columns: Array(
repeating: GridItem(
.flexible(minimum: SymiSize.headacheOptionGridMinWidth),
spacing: SymiSpacing.xs,
alignment: .top
),
count: SymiSize.headacheOptionGridColumnCount
),
alignment: .leading,
spacing: SymiSpacing.xs
InputFlowFixedTileGrid(
minimumColumnWidth: SymiSize.headacheOptionGridMinWidth,
columnCount: SymiSize.headacheOptionGridColumnCount
) {
content
}
Expand Down Expand Up @@ -569,7 +528,7 @@ private struct EntryTriggersStepView: View {
theme: .trigger,
accessibilityIdentifier: "entry-trigger-\(option.title)"
) {
toggle(option.title, in: &coordinator.draft.selectedTriggers)
coordinator.draft.selectedTriggers.toggleMembership(option.title)
}
}
}
Expand All @@ -589,14 +548,6 @@ private struct EntryTriggersStepView: View {
)
}
}

private func toggle(_ option: String, in selection: inout Set<String>) {
if selection.contains(option) {
selection.remove(option)
} else {
selection.insert(option)
}
}
}

private struct EntryNoteStepView: View {
Expand Down
10 changes: 1 addition & 9 deletions Symi/Sources/Features/Capture/NewEntryDesignSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,12 @@ struct MultiSelectGrid: View {
isSelected: isSelected,
colorToken: colorToken
) {
toggle(option)
selection.toggleMembership(option)
}
.accessibilityLabel("\(accessibilityPrefix): \(option)")
.accessibilityValue(isSelected ? "Ausgewählt" : "Nicht ausgewählt")
.accessibilityHint(isSelected ? "Entfernt die Auswahl." : "Wählt diese Option aus.")
}
}
}

private func toggle(_ option: String) {
if selection.contains(option) {
selection.remove(option)
} else {
selection.insert(option)
}
}
}
36 changes: 36 additions & 0 deletions Symi/Sources/Features/InputFlow/Components/InputFlowLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,42 @@ struct InputFlowTileGrid<Content: View>: View {
}
}

struct InputFlowFixedTileGrid<Content: View>: View {
let minimumColumnWidth: CGFloat
let columnCount: Int
let spacing: CGFloat
let content: Content

init(
minimumColumnWidth: CGFloat,
columnCount: Int,
spacing: CGFloat = SymiSpacing.xs,
@ViewBuilder content: () -> Content
) {
self.minimumColumnWidth = minimumColumnWidth
self.columnCount = columnCount
self.spacing = spacing
self.content = content()
}

var body: some View {
LazyVGrid(
columns: Array(
repeating: GridItem(
.flexible(minimum: minimumColumnWidth),
spacing: spacing,
alignment: .top
),
count: columnCount
),
alignment: .leading,
spacing: spacing
) {
content
}
}
}

struct InputFlowPillGrid<Content: View>: View {
let minimumColumnWidth: CGFloat
let content: Content
Expand Down
9 changes: 9 additions & 0 deletions Symi/Sources/Shared/SetToggleMembership.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extension Set {
mutating func toggleMembership(_ member: Element) {
if contains(member) {
remove(member)
} else {
insert(member)
}
}
}
11 changes: 11 additions & 0 deletions SymiTests/NewEntryDesignSystemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,15 @@ struct NewEntryDesignSystemTests {
#expect(token.lightColorValue.hexString == expected[token, default: ""])
}
}

@Test
func setToggleMembershipAddsAndRemovesMembers() {
var selection: Set<String> = ["Stress"]

selection.toggleMembership("Wetter")
#expect(selection == ["Stress", "Wetter"])

selection.toggleMembership("Stress")
#expect(selection == ["Wetter"])
}
}
Loading