Skip to content

Commit cb39f7f

Browse files
committed
Fixed ArticleNote
- sheet now opens at first try in the right article
1 parent a14897f commit cb39f7f

File tree

4 files changed

+16
-111
lines changed

4 files changed

+16
-111
lines changed

PG5602_H24-4/Views/APITest.swift

-96
This file was deleted.

PG5602_H24-4/Views/ArticleView/ArticleListView.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// ArticleListView.swift
33
// PG5602_H24-4
44
//
5-
// Created by Karima Thingvold on 07/12/2024.
65
//
76

87
import SwiftUI
@@ -40,7 +39,7 @@ struct ArticleListView: View {
4039
}
4140
.swipeActions(edge: .trailing, allowsFullSwipe: false) {
4241
Button(action: {
43-
addNoteAction(article) // Bruker closure for å åpne NoteSheet
42+
addNoteAction(article)
4443
}) {
4544
Label("Add note", systemImage: "note")
4645
}

PG5602_H24-4/Views/ArticleView/ArticleNote.swift

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// ArticleNote.swift
33
// PG5602_H24-4
44
//
5-
// Created by Karima Thingvold on 07/12/2024.
65
//
76

87
import SwiftUI
@@ -13,7 +12,7 @@ struct ArticleNote: View {
1312
var onSave: () -> Void
1413

1514
var body: some View {
16-
NavigationView {
15+
NavigationStack {
1716
VStack(alignment: .leading, spacing: 20) {
1817

1918
Text("Add Note for:")
@@ -22,12 +21,12 @@ struct ArticleNote: View {
2221

2322
Text(article.title)
2423
.font(.subheadline)
25-
.foregroundColor(.secondary)
24+
.foregroundStyle(.secondary)
2625
.lineLimit(2)
2726
.padding(.bottom)
2827

2928

30-
TextField("Enter your note here...", text: $noteText)
29+
TextField("Enter note here...", text: $noteText)
3130
.textFieldStyle(RoundedBorderTextFieldStyle())
3231
.padding(.horizontal)
3332

@@ -38,7 +37,7 @@ struct ArticleNote: View {
3837
.frame(maxWidth: .infinity)
3938
.padding()
4039
.background(Color.blue)
41-
.foregroundColor(.white)
40+
.foregroundStyle(.white)
4241
.cornerRadius(10)
4342
.padding(.horizontal)
4443
}

PG5602_H24-4/Views/ArticleView/ArticlesView.swift

+11-8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// ArticlesView.swift
33
// PG5602_H24-4
44
//
5-
// Created by Karima Thingvold on 01/12/2024.
6-
//
75

86
import SwiftUI
97
import SwiftData
@@ -36,7 +34,7 @@ struct ArticlesView: View {
3634
tickerTextColor: $tickerTextColor,
3735
tickerFSize: $tickerFSize
3836
)
39-
.frame(height: 50)
37+
.frame(height: 50)
4038
}
4139

4240
NavigationView {
@@ -53,10 +51,11 @@ struct ArticlesView: View {
5351
)
5452
}
5553
}
56-
/// Works, but sometimes its to much to load so it takes som time.
57-
.sheet(isPresented: $showNoteSheet, onDismiss: {
58-
selectedArticle = nil
59-
}) {
54+
/// Works, but...
55+
.sheet(isPresented: Binding(
56+
get: { showNoteSheet && selectedArticle != nil },
57+
set: { if !$0 { showNoteSheet = false; selectedArticle = nil } }
58+
)) {
6059
if let selectedArticle = selectedArticle {
6160
ArticleNote(
6261
article: selectedArticle,
@@ -66,12 +65,13 @@ struct ArticlesView: View {
6665
}
6766
}
6867

68+
6969
if !detailedView && tickerPosition == "Bottom" && isNewsTickerActive {
7070
NewsTickerView(
7171
tickerTextColor: $tickerTextColor,
7272
tickerFSize: $tickerFSize
7373
)
74-
.frame(height: 50)
74+
.frame(height: 50)
7575
}
7676
}
7777
}
@@ -87,8 +87,11 @@ struct ArticlesView: View {
8787
func openNoteSheet(for article: Article) {
8888
selectedArticle = article
8989
noteText = article.note ?? ""
90+
print("Selected Article: \(selectedArticle?.title ?? "None")")
91+
print("Note Text: \(noteText)")
9092
showNoteSheet = true
9193
}
94+
9295

9396
func saveNote() {
9497
guard let article = selectedArticle else { return }

0 commit comments

Comments
 (0)