Skip to content

Commit 599114f

Browse files
committed
feat: private entries
1 parent 0978048 commit 599114f

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

Horizon/Models/Journal.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ struct Journal: Codable, Identifiable, Equatable {
66
var id: Int
77
var entryTemplate: String?
88
var entryTemplateActive: Bool
9+
var isPrivate: Bool
910
var lastEntryAt: Date?
1011
var slug: String
1112
var title: String
@@ -14,6 +15,7 @@ struct Journal: Codable, Identifiable, Equatable {
1415
case id
1516
case entryTemplate
1617
case entryTemplateActive
18+
case isPrivate = "private"
1719
case lastEntryAt = "last_entry_at"
1820
case slug
1921
case title

Horizon/Networking/Futureland.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ enum Futureland {
1515
}
1616

1717
/// Gets journals for signed in user
18-
static func createEntry(token: String, notes: String, journalId: Int, file: File?) -> UploadRequest {
18+
static func createEntry(
19+
token: String,
20+
notes: String,
21+
journalId: Int,
22+
file: File?,
23+
isPrivate: Bool
24+
) -> UploadRequest {
1925
let url = baseURL.appendingPathComponent("/entries")
2026
var request = URLRequest(url: url)
2127
request.httpMethod = "POST"
@@ -34,6 +40,7 @@ enum Futureland {
3440
multipartFormData.append(Data(notes.utf8), withName: "notes")
3541
multipartFormData.append(Data(streakDate.utf8), withName: "streakDate")
3642
multipartFormData.append(Data("\(journalId)".utf8), withName: "journal_id")
43+
multipartFormData.append(Data("\(isPrivate)".utf8), withName: "private")
3744
multipartFormData.append(fileData, withName: "file", fileName: fileName, mimeType: mimeType)
3845
}, with: request)
3946
}

Horizon/Prefs/GeneralPrefsView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ let GeneralPrefsViewController: (Store) -> PreferencePane = { store in
2222
}
2323

2424
struct GeneralPrefsView: View {
25-
@EnvironmentObject var store: Store
25+
@EnvironmentObject
26+
var store: Store
2627

2728
var body: some View {
2829
Preferences.Container(contentWidth: Preferences.contentWidth) {

Horizon/Publish/PublishView.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ struct PublishView: View {
9191
if viewModel.wordCount > 1 {
9292
Text("\(viewModel.wordCount) words")
9393
}
94+
95+
if !(viewModel.selectedJournal?.isPrivate ?? false) {
96+
Button("\(viewModel.isPrivate ? "🔒" : "🔓")") {
97+
viewModel.isPrivate = !viewModel.isPrivate
98+
}
99+
.disabled(viewModel.networkActive)
100+
.keyboardShortcut("P", modifiers: [.command, .shift])
101+
}
94102
}
95103
}
96104
.padding()

Horizon/Publish/PublishViewModel.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class PublishViewModel: ObservableObject, Identifiable {
2727

2828
@Published
2929
var isFileBrowserOpen = false
30+
31+
@Published
32+
var isPrivate = false
3033

3134
@Published
3235
var file: File?
@@ -59,7 +62,8 @@ class PublishViewModel: ObservableObject, Identifiable {
5962
token: token,
6063
notes: entry,
6164
journalId: selectedJournalId,
62-
file: file
65+
file: file,
66+
isPrivate: isPrivate
6367
)
6468
.uploadProgress { progress in
6569
self.progress = progress.fractionCompleted
@@ -108,6 +112,7 @@ class PublishViewModel: ObservableObject, Identifiable {
108112
func reset() {
109113
progress = 0.0
110114
networkActive = false
115+
isPrivate = false
111116
file = nil
112117
entry = ""
113118

0 commit comments

Comments
 (0)