Merge branch 'main' into add-collection-setting-menu

This commit is contained in:
Angelo Stavrow 2020-10-12 09:15:24 -04:00 committed by GitHub
commit 9e48f75717
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 16 deletions

View File

@ -94,8 +94,12 @@ extension WriteFreelyModel {
serverString = serverString.replacingOccurrences(of: insecureProtocolPrefix, with: secureProtocolPrefix)
}
isLoggingIn = true
account.server = serverString
client = WFClient(for: URL(string: serverString)!)
var serverURL = URL(string: serverString)!
if !serverURL.path.isEmpty {
serverURL.deleteLastPathComponent()
}
account.server = serverURL.absoluteString
client = WFClient(for: serverURL)
client?.login(username: username, password: password, completion: loginHandler)
}

View File

@ -7,6 +7,8 @@ struct PostEditorView: View {
@Environment(\.presentationMode) var presentationMode
@ObservedObject var post: WFAPost
@State private var updatingTitleFromServer: Bool = false
@State private var updatingBodyFromServer: Bool = false
@State private var selectedCollection: WFACollection?
@ -56,9 +58,12 @@ struct PostEditorView: View {
TextField("Title (optional)", text: $post.title)
.font(.custom("OpenSans-Regular", size: 26, relativeTo: Font.TextStyle.largeTitle))
.onChange(of: post.title) { _ in
if post.status == PostStatus.published.rawValue {
if post.status == PostStatus.published.rawValue && !updatingTitleFromServer {
post.status = PostStatus.edited.rawValue
}
if updatingTitleFromServer {
updatingTitleFromServer = false
}
}
ZStack(alignment: .topLeading) {
if post.body.count == 0 {
@ -71,18 +76,24 @@ struct PostEditorView: View {
TextEditor(text: $post.body)
.font(.custom("OpenSans-Regular", size: 17, relativeTo: Font.TextStyle.body))
.onChange(of: post.body) { _ in
if post.status == PostStatus.published.rawValue {
if post.status == PostStatus.published.rawValue && !updatingBodyFromServer {
post.status = PostStatus.edited.rawValue
}
if updatingBodyFromServer {
updatingBodyFromServer = false
}
}
}
case "wrap", "mono", "code":
TextField("Title (optional)", text: $post.title)
.font(.custom("Hack", size: 26, relativeTo: Font.TextStyle.largeTitle))
.onChange(of: post.title) { _ in
if post.status == PostStatus.published.rawValue {
if post.status == PostStatus.published.rawValue && !updatingTitleFromServer {
post.status = PostStatus.edited.rawValue
}
if updatingTitleFromServer {
updatingTitleFromServer = false
}
}
ZStack(alignment: .topLeading) {
if post.body.count == 0 {
@ -95,18 +106,24 @@ struct PostEditorView: View {
TextEditor(text: $post.body)
.font(.custom("Hack", size: 17, relativeTo: Font.TextStyle.body))
.onChange(of: post.body) { _ in
if post.status == PostStatus.published.rawValue {
if post.status == PostStatus.published.rawValue && !updatingBodyFromServer {
post.status = PostStatus.edited.rawValue
}
if updatingBodyFromServer {
updatingBodyFromServer = false
}
}
}
default:
TextField("Title (optional)", text: $post.title)
.font(.custom("Lora", size: 26, relativeTo: Font.TextStyle.largeTitle))
.onChange(of: post.title) { _ in
if post.status == PostStatus.published.rawValue {
if post.status == PostStatus.published.rawValue && !updatingTitleFromServer {
post.status = PostStatus.edited.rawValue
}
if updatingTitleFromServer {
updatingTitleFromServer = false
}
}
ZStack(alignment: .topLeading) {
if post.body.count == 0 {
@ -119,9 +136,12 @@ struct PostEditorView: View {
TextEditor(text: $post.body)
.font(.custom("Lora", size: 17, relativeTo: Font.TextStyle.body))
.onChange(of: post.body) { _ in
if post.status == PostStatus.published.rawValue {
if post.status == PostStatus.published.rawValue && !updatingBodyFromServer {
post.status = PostStatus.edited.rawValue
}
if updatingBodyFromServer {
updatingBodyFromServer = false
}
}
}
}
@ -209,8 +229,9 @@ struct PostEditorView: View {
}
}
.onChange(of: post.hasNewerRemoteCopy, perform: { _ in
if post.status == PostStatus.edited.rawValue && !post.hasNewerRemoteCopy {
post.status = PostStatus.published.rawValue
if !post.hasNewerRemoteCopy {
updatingTitleFromServer = true
updatingBodyFromServer = true
}
})
.onChange(of: post.status, perform: { _ in

View File

@ -5,6 +5,8 @@ struct PostEditorView: View {
@ObservedObject var post: WFAPost
@State private var isHovering: Bool = false
@State private var updatingTitleFromServer: Bool = false
@State private var updatingBodyFromServer: Bool = false
var body: some View {
VStack {
@ -15,9 +17,12 @@ struct PostEditorView: View {
.padding(.bottom)
.font(.custom("OpenSans-Regular", size: 26, relativeTo: Font.TextStyle.largeTitle))
.onChange(of: post.title) { _ in
if post.status == PostStatus.published.rawValue {
if post.status == PostStatus.published.rawValue && !updatingTitleFromServer {
post.status = PostStatus.edited.rawValue
}
if updatingTitleFromServer {
updatingTitleFromServer = false
}
}
ZStack(alignment: .topLeading) {
if post.body.count == 0 {
@ -31,9 +36,12 @@ struct PostEditorView: View {
.font(.custom("OpenSans-Regular", size: 17, relativeTo: Font.TextStyle.body))
.opacity(post.body.count == 0 && !isHovering ? 0.0 : 1.0)
.onChange(of: post.body) { _ in
if post.status == PostStatus.published.rawValue {
if post.status == PostStatus.published.rawValue && !updatingBodyFromServer {
post.status = PostStatus.edited.rawValue
}
if updatingBodyFromServer {
updatingBodyFromServer = false
}
}
.onHover(perform: { hovering in
self.isHovering = hovering
@ -46,9 +54,12 @@ struct PostEditorView: View {
.padding(.bottom)
.font(.custom("Hack", size: 26, relativeTo: Font.TextStyle.largeTitle))
.onChange(of: post.title) { _ in
if post.status == PostStatus.published.rawValue {
if post.status == PostStatus.published.rawValue && !updatingTitleFromServer {
post.status = PostStatus.edited.rawValue
}
if updatingTitleFromServer {
updatingTitleFromServer = false
}
}
ZStack(alignment: .topLeading) {
if post.body.count == 0 {
@ -62,9 +73,12 @@ struct PostEditorView: View {
.font(.custom("Hack", size: 17, relativeTo: Font.TextStyle.body))
.opacity(post.body.count == 0 && !isHovering ? 0.0 : 1.0)
.onChange(of: post.body) { _ in
if post.status == PostStatus.published.rawValue {
if post.status == PostStatus.published.rawValue && !updatingBodyFromServer {
post.status = PostStatus.edited.rawValue
}
if updatingBodyFromServer {
updatingBodyFromServer = false
}
}
.onHover(perform: { hovering in
self.isHovering = hovering
@ -77,9 +91,12 @@ struct PostEditorView: View {
.padding(.bottom)
.font(.custom("Lora", size: 26, relativeTo: Font.TextStyle.largeTitle))
.onChange(of: post.title) { _ in
if post.status == PostStatus.published.rawValue {
if post.status == PostStatus.published.rawValue && !updatingTitleFromServer {
post.status = PostStatus.edited.rawValue
}
if updatingTitleFromServer {
updatingTitleFromServer = false
}
}
ZStack(alignment: .topLeading) {
if post.body.count == 0 {
@ -93,9 +110,12 @@ struct PostEditorView: View {
.font(.custom("Lora", size: 17, relativeTo: Font.TextStyle.body))
.opacity(post.body.count == 0 && !isHovering ? 0.0 : 1.0)
.onChange(of: post.body) { _ in
if post.status == PostStatus.published.rawValue {
if post.status == PostStatus.published.rawValue && !updatingBodyFromServer {
post.status = PostStatus.edited.rawValue
}
if updatingBodyFromServer {
updatingBodyFromServer = false
}
}
.onHover(perform: { hovering in
self.isHovering = hovering