@@ -5,6 +5,8 @@ struct PostEditorView: View {
5
5
@Environment ( \. horizontalSizeClass) var horizontalSizeClass
6
6
@Environment ( \. presentationMode) var presentationMode
7
7
@ObservedObject var post : WFAPost
8
+ @State private var updatingTitleFromServer : Bool = false
9
+ @State private var updatingBodyFromServer : Bool = false
8
10
9
11
var body : some View {
10
12
VStack {
@@ -47,9 +49,12 @@ struct PostEditorView: View {
47
49
TextField ( " Title (optional) " , text: $post. title)
48
50
. font ( . custom( " OpenSans-Regular " , size: 26 , relativeTo: Font . TextStyle. largeTitle) )
49
51
. onChange ( of: post. title) { _ in
50
- if post. status == PostStatus . published. rawValue {
52
+ if post. status == PostStatus . published. rawValue && !updatingTitleFromServer {
51
53
post. status = PostStatus . edited. rawValue
52
54
}
55
+ if updatingTitleFromServer {
56
+ updatingTitleFromServer = false
57
+ }
53
58
}
54
59
ZStack ( alignment: . topLeading) {
55
60
if post. body. count == 0 {
@@ -62,18 +67,24 @@ struct PostEditorView: View {
62
67
TextEditor ( text: $post. body)
63
68
. font ( . custom( " OpenSans-Regular " , size: 17 , relativeTo: Font . TextStyle. body) )
64
69
. onChange ( of: post. body) { _ in
65
- if post. status == PostStatus . published. rawValue {
70
+ if post. status == PostStatus . published. rawValue && !updatingBodyFromServer {
66
71
post. status = PostStatus . edited. rawValue
67
72
}
73
+ if updatingBodyFromServer {
74
+ updatingBodyFromServer = false
75
+ }
68
76
}
69
77
}
70
78
case " wrap " , " mono " , " code " :
71
79
TextField ( " Title (optional) " , text: $post. title)
72
80
. font ( . custom( " Hack " , size: 26 , relativeTo: Font . TextStyle. largeTitle) )
73
81
. onChange ( of: post. title) { _ in
74
- if post. status == PostStatus . published. rawValue {
82
+ if post. status == PostStatus . published. rawValue && !updatingTitleFromServer {
75
83
post. status = PostStatus . edited. rawValue
76
84
}
85
+ if updatingTitleFromServer {
86
+ updatingTitleFromServer = false
87
+ }
77
88
}
78
89
ZStack ( alignment: . topLeading) {
79
90
if post. body. count == 0 {
@@ -86,18 +97,24 @@ struct PostEditorView: View {
86
97
TextEditor ( text: $post. body)
87
98
. font ( . custom( " Hack " , size: 17 , relativeTo: Font . TextStyle. body) )
88
99
. onChange ( of: post. body) { _ in
89
- if post. status == PostStatus . published. rawValue {
100
+ if post. status == PostStatus . published. rawValue && !updatingBodyFromServer {
90
101
post. status = PostStatus . edited. rawValue
91
102
}
103
+ if updatingBodyFromServer {
104
+ updatingBodyFromServer = false
105
+ }
92
106
}
93
107
}
94
108
default :
95
109
TextField ( " Title (optional) " , text: $post. title)
96
110
. font ( . custom( " Lora " , size: 26 , relativeTo: Font . TextStyle. largeTitle) )
97
111
. onChange ( of: post. title) { _ in
98
- if post. status == PostStatus . published. rawValue {
112
+ if post. status == PostStatus . published. rawValue && !updatingTitleFromServer {
99
113
post. status = PostStatus . edited. rawValue
100
114
}
115
+ if updatingTitleFromServer {
116
+ updatingTitleFromServer = false
117
+ }
101
118
}
102
119
ZStack ( alignment: . topLeading) {
103
120
if post. body. count == 0 {
@@ -110,9 +127,12 @@ struct PostEditorView: View {
110
127
TextEditor ( text: $post. body)
111
128
. font ( . custom( " Lora " , size: 17 , relativeTo: Font . TextStyle. body) )
112
129
. onChange ( of: post. body) { _ in
113
- if post. status == PostStatus . published. rawValue {
130
+ if post. status == PostStatus . published. rawValue && !updatingBodyFromServer {
114
131
post. status = PostStatus . edited. rawValue
115
132
}
133
+ if updatingBodyFromServer {
134
+ updatingBodyFromServer = false
135
+ }
116
136
}
117
137
}
118
138
}
@@ -145,8 +165,9 @@ struct PostEditorView: View {
145
165
}
146
166
}
147
167
. onChange ( of: post. hasNewerRemoteCopy, perform: { _ in
148
- if post. status == PostStatus . edited. rawValue && !post. hasNewerRemoteCopy {
149
- post. status = PostStatus . published. rawValue
168
+ if !post. hasNewerRemoteCopy {
169
+ updatingTitleFromServer = true
170
+ updatingBodyFromServer = true
150
171
}
151
172
} )
152
173
. onChange ( of: post. status, perform: { _ in
0 commit comments