Skip to content

Commit

Permalink
Fixed logic for Quick Post title and content
Browse files Browse the repository at this point in the history
  • Loading branch information
livid committed Apr 27, 2024
1 parent f9d93e5 commit 4b49915
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
27 changes: 14 additions & 13 deletions Planet/Labs/Quick Post/QuickPostView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct QuickPostView: View {
.padding(.bottom, 10)
.padding(.leading, 10)
.padding(.trailing, 0)

TextEditor(text: $content)
.font(.system(size: 14, weight: .regular, design: .default))
.lineSpacing(7)
Expand All @@ -37,9 +37,9 @@ struct QuickPostView: View {
.padding(.trailing, 10)
.frame(height: 160)
}

Divider()

HStack {
Spacer()
Button("Cancel", role: .cancel) {
Expand All @@ -49,7 +49,7 @@ struct QuickPostView: View {
.keyboardShortcut(.cancelAction)
.buttonStyle(.bordered)
.buttonBorderShape(.roundedRectangle)

Button {
// Save content as a new MyArticleModel
do {
Expand All @@ -70,7 +70,7 @@ struct QuickPostView: View {
.background(Color(NSColor.windowBackgroundColor))
}.frame(width: 500)
}

private func extractTitle(from content: String) -> String {
let content = content.trim()
let lines = content.components(separatedBy: .newlines)
Expand All @@ -81,7 +81,7 @@ struct QuickPostView: View {
}
return ""
}

private func extractContent(from content: String) -> String {
let content = content.trim()
let lines = content.components(separatedBy: .newlines)
Expand All @@ -92,16 +92,17 @@ struct QuickPostView: View {
if line.hasPrefix("# ") {
i += 1
continue
} else {
result += "\(line)\n"
}
}
if i > 0 {
result += line + "\n"
} else {
result += "\(line)\n"
}
i += 1
}
return result.trim()
}

private func saveContent() throws {
// Save content as a new MyArticleModel
guard let planet = KeyboardShortcutHelper.shared.activeMyPlanet else { return }
Expand All @@ -121,22 +122,22 @@ struct QuickPostView: View {
articles?.append(article)
articles?.sort(by: { MyArticleModel.reorder(a: $0, b: $1) })
planet.articles = articles

do {
try article.save()
try article.savePublic()
try planet.copyTemplateAssets()
planet.updated = Date()
try planet.save()

Task {
try await planet.savePublic()
try await planet.publish()
Task(priority: .background) {
await article.prewarm()
}
}

Task { @MainActor in
PlanetStore.shared.selectedView = .myPlanet(planet)
PlanetStore.shared.refreshSelectedArticles()
Expand Down
2 changes: 1 addition & 1 deletion Planet/versioning.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CURRENT_PROJECT_VERSION = 1995
CURRENT_PROJECT_VERSION = 1996

0 comments on commit 4b49915

Please sign in to comment.