@@ -11,6 +11,7 @@ struct HistoryView: View {
1111 @EnvironmentObject var timerViewModel : TimerViewModel
1212 @State private var editingSession : TimerSession ?
1313 @State private var editedLabel : String = " "
14+ @State private var editedDuration : Int = 0
1415
1516 var filteredSessions : [ TimerSession ] {
1617 let calendar = Calendar . current
@@ -22,75 +23,149 @@ struct HistoryView: View {
2223 }
2324
2425 var body : some View {
25- List {
26- ForEach ( filteredSessions) { session in
27- VStack ( alignment: . leading) {
28- Text ( session. label)
29- . font ( . headline)
30-
31- HStack {
32- Text ( session. startDate, style: . date)
33- . font ( . subheadline)
34- . foregroundColor ( . secondary)
35-
36- Spacer ( )
26+ VStack ( alignment: . leading) {
27+ Text ( " History " )
28+ . font ( . system( . title, design: . monospaced) )
29+ . padding ( )
30+ List {
31+ ForEach ( filteredSessions) { session in
32+ VStack ( alignment: . leading) {
33+ Text ( session. label)
34+ . font ( . headline)
3735
38- Text ( session. formattedDuration)
39- . font ( . system( . subheadline, design: . monospaced) )
40- . foregroundColor ( . secondary)
36+ HStack {
37+ Text ( session. startDate, style: . date)
38+ . font ( . subheadline)
39+ . foregroundColor ( . secondary)
40+
41+ Spacer ( )
42+
43+ Text ( session. formattedDuration)
44+ . font ( . system( . subheadline, design: . monospaced) )
45+ . foregroundColor ( . secondary)
46+ }
47+ }
48+ . contentShape ( Rectangle ( ) )
49+ . onTapGesture {
50+ editingSession = session
51+ editedLabel = session. label
4152 }
42- }
43- . contentShape ( Rectangle ( ) )
44- . onTapGesture {
45- editingSession = session
46- editedLabel = session. label
4753 }
4854 }
49- }
50- . navigationTitle ( " BigTime " )
51- . sheet ( item: $editingSession) { session in
52- NavigationView {
53- VStack ( spacing: 20 ) {
54- Text ( " Edit Session " )
55- . font ( . system( . title2, design: . monospaced) )
56-
57- Form {
58- Section {
59- TextField ( " Session Label " , text: $editedLabel)
60- . textFieldStyle ( RoundedBorderTextFieldStyle ( ) )
61- }
62- }
63-
64- HStack {
65- Button ( " Cancel " ) {
66- editingSession = nil
67- }
68- Button ( " Save " ) {
69- if let session = editingSession {
70- timerViewModel. updateSessionLabel ( session, newLabel: editedLabel)
55+ . scrollContentBackground ( . hidden) // Hides the default background
56+ . background ( Color . clear) // Sets the background to transparent
57+ . navigationTitle ( " BigTime " )
58+ . sheet ( item: $editingSession) { session in
59+ NavigationView {
60+ VStack ( spacing: 20 ) {
61+ Text ( " Edit Session " )
62+ . font ( . system( . title2, design: . monospaced) )
63+
64+ Form {
65+ Section {
66+ TextField ( " Session Label " , text: $editedLabel)
67+ . textFieldStyle ( RoundedBorderTextFieldStyle ( ) )
68+
69+ // Timer preview/editor
70+ HStack {
71+ Text ( " Duration: " )
72+ Spacer ( )
73+ HStack ( spacing: 2 ) {
74+ // Hours
75+ Stepper (
76+ value: Binding (
77+ get: { editedDuration / 3600 } ,
78+ set: { editedDuration = ( $0 * 3600 ) + ( editedDuration % 3600 ) }
79+ ) ,
80+ in: 0 ... 23
81+ ) {
82+ Text ( " \( editedDuration / 3600 ) h " )
83+ . font ( . system( . body, design: . monospaced) )
84+ . frame ( width: 40 )
85+ }
86+
87+ // Minutes
88+ Stepper (
89+ value: Binding (
90+ get: { ( editedDuration % 3600 ) / 60 } ,
91+ set: { editedDuration = ( editedDuration / 3600 * 3600 ) + ( $0 * 60 ) + ( editedDuration % 60 ) }
92+ ) ,
93+ in: 0 ... 59
94+ ) {
95+ Text ( " \( ( editedDuration % 3600 ) / 60 ) m " )
96+ . font ( . system( . body, design: . monospaced) )
97+ . frame ( width: 40 )
98+ }
99+
100+ // Seconds
101+ Stepper (
102+ value: Binding (
103+ get: { editedDuration % 60 } ,
104+ set: { editedDuration = ( editedDuration / 60 * 60 ) + $0 }
105+ ) ,
106+ in: 0 ... 59
107+ ) {
108+ Text ( " \( editedDuration % 60 ) s " )
109+ . font ( . system( . body, design: . monospaced) )
110+ . frame ( width: 40 )
111+ }
112+ }
113+ }
71114 }
72- editingSession = nil
73115 }
74- . font ( . system( size: 12 , weight: . medium) )
75- . background ( Color . accentColor) // Use the accent color as the background
76- . cornerRadius ( 5 )
77116
78- Button ( " Delete " ) {
79- if let session = editingSession {
80- timerViewModel. deleteSession ( session)
117+ HStack ( spacing: 12 ) {
118+ Button ( " Cancel " ) {
119+ editingSession = nil
120+ }
121+ . buttonStyle ( . bordered)
122+
123+ Button ( " Continue " ) {
124+ if let session = editingSession {
125+ let updatedSession = TimerSession (
126+ id: session. id,
127+ startDate: session. startDate,
128+ duration: editedDuration,
129+ label: editedLabel
130+ )
131+ timerViewModel. updateSessionLabel ( session, newLabel: editedLabel)
132+ timerViewModel. continueFromSession ( updatedSession)
133+ }
134+ editingSession = nil
135+ }
136+ . buttonStyle ( . borderedProminent)
137+
138+ Button ( " Save " ) {
139+ if let session = editingSession {
140+ timerViewModel. updateSessionLabel ( session, newLabel: editedLabel)
141+ }
142+ editingSession = nil
143+ }
144+ . buttonStyle ( . bordered)
145+ . background ( Color . accentColor) // Use the accent color as the background
146+ . cornerRadius ( 5 )
147+
148+ Button ( " Delete " ) {
149+ if let session = editingSession {
150+ timerViewModel. deleteSession ( session)
151+ }
152+ editingSession = nil
81153 }
82- editingSession = nil
154+ . background ( Color . red. opacity ( 0.5 ) ) // Light red background
155+ . cornerRadius ( 5 )
156+ }
157+ }
158+ . onAppear {
159+ if let session = editingSession {
160+ editedLabel = session. label
161+ editedDuration = session. duration
83162 }
84- . font ( . system( size: 12 , weight: . medium) )
85- . foregroundColor ( . red) // Red color for the delete button
86- . background ( Color . red. opacity ( 0.5 ) ) // Light red background
87- . cornerRadius ( 5 )
88163 }
164+ . padding ( )
165+ . frame ( width: 300 , height: 200 , alignment: . center)
89166 }
90- . padding ( )
91- . padding ( . vertical, 50 )
167+ . frame ( width: 300 , height: 200 , alignment: . center)
92168 }
93- . frame ( width: 300 , height: 200 , alignment: . center)
94169 }
95170 }
96171}
0 commit comments