Skip to content

Commit 74a267f

Browse files
authored
Merge pull request #7 from KhubaibKhan4/feature/sort
-Sorting Enhancement
2 parents 54bc732 + df24ef6 commit 74a267f

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

.DS_Store

0 Bytes
Binary file not shown.
Binary file not shown.

Notes/presentation/screens/HomeScreen.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,15 @@ struct HomeScreen: View {
100100
.navigationTitle(LocalizedStringKey("Notes"))
101101
.toolbar {
102102
ToolbarItem(placement: .topBarLeading) {
103-
Picker("", selection: $sortMode) {
104-
Label("Recent", systemImage: "clock.arrow.circlepath").tag(SortMode.recent)
105-
Label("Title", systemImage: "textformat").tag(SortMode.title)
103+
Menu {
104+
Picker("Sort by", selection: $sortMode) {
105+
Label("Recent", systemImage: "clock.arrow.circlepath").tag(SortMode.recent)
106+
Label("Title", systemImage: "textformat").tag(SortMode.title)
107+
}
108+
} label: {
109+
Image(systemName: "arrow.up.arrow.down.circle")
106110
}
107-
.pickerStyle(.segmented)
108-
.frame(maxWidth: 220)
111+
.accessibilityLabel("Sort")
109112
}
110113

111114
ToolbarItem(placement: .topBarTrailing) {

Notes/presentation/screens/NotesDetail.swift

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
//
77

88
import SwiftUI
9+
import SwiftData
910
import CoreLocation
1011
import MapKit
1112
import AVKit
1213

1314
struct NotesDetail: View {
14-
@State var notesItem: NotesItem
15+
@Environment(\.modelContext) private var context
16+
17+
@Bindable var notesItem: NotesItem
1518
@State private var imageSheetExpanded: Bool = false
1619
@State private var position: MapCameraPosition = .region(
1720
MKCoordinateRegion(
@@ -69,16 +72,22 @@ struct NotesDetail: View {
6972
.foregroundColor(.secondary)
7073
}
7174

72-
// Checklist details
75+
// Checklist details (interactive)
7376
if !notesItem.checklist.isEmpty {
7477
Section(header: Text("Checklist")) {
75-
ForEach(notesItem.checklist) { item in
76-
HStack {
77-
Image(systemName: item.isDone ? "checkmark.circle.fill" : "circle")
78-
.foregroundColor(item.isDone ? .green : .gray)
78+
ForEach($notesItem.checklist) { $item in
79+
Toggle(isOn: $item.isDone) {
7980
Text(item.title)
80-
Spacer()
8181
}
82+
.onChange(of: item.isDone) { _, _ in
83+
notesItem.updatedAt = Date()
84+
try? context.save()
85+
}
86+
}
87+
.onDelete { offsets in
88+
notesItem.checklist.remove(atOffsets: offsets)
89+
notesItem.updatedAt = Date()
90+
try? context.save()
8291
}
8392
}
8493
}

0 commit comments

Comments
 (0)