Skip to content

Commit

Permalink
[macos] Pull BlobEntrys out of BlobGlobalState
Browse files Browse the repository at this point in the history
Now `BlobGlobalState` has a single `uploadProgress` field. Can probably be simplified further, but this is fine for now.
  • Loading branch information
atulsmadhugiri committed Oct 7, 2023
1 parent e932ab3 commit 6d6f50b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 14 deletions.
4 changes: 2 additions & 2 deletions macos/plop/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let (destinationURL, uploadTask, localPath) = uploadBlob(filepath: filepath)

uploadTask.observe(.progress) { snapshot in
self.blobGlobalState.blobEntries.last?.uploadProgress =
self.blobGlobalState.uploadProgress =
snapshot.progress?.fractionCompleted ?? 0
}

Expand All @@ -106,7 +106,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
filepath: filepath.path)

uploadTask.observe(.progress) { snapshot in
self.blobGlobalState.blobEntries.last?.uploadProgress =
self.blobGlobalState.uploadProgress =
snapshot.progress?.fractionCompleted ?? 0
}

Expand Down
4 changes: 1 addition & 3 deletions macos/plop/BlobGlobalState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import SwiftData

@Model final class BlobEntry: Identifiable {
var id = UUID()
var uploadProgress: Double = 1.0
var uploadURL: String = ""
var uploadLocalPath: URL? = nil
var fileSize: String? = nil
Expand All @@ -18,7 +17,6 @@ import SwiftData
uploadLocalPath: URL? = nil
) {
self.id = id
self.uploadProgress = 1.0
self.uploadURL = uploadURL
self.uploadLocalPath = uploadLocalPath

Expand All @@ -37,5 +35,5 @@ import SwiftData
}

@Observable final class BlobGlobalState {
var blobEntries: [BlobEntry] = []
var uploadProgress: Double = 1.0
}
9 changes: 3 additions & 6 deletions macos/plop/BlobPopover.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ struct BlobPopover: View {
var body: some View {
VStack {
HStack {
ScreenshotButton(
uploadProgress: $blobGlobalState.blobEntries.last?.uploadProgress ?? .constant(0.0))
ScreenshotButton(uploadProgress: $blobGlobalState.uploadProgress)
RecordButton()
UploadButton(
previousUploadURL: $blobGlobalState.blobEntries.last?.uploadURL ?? .constant(""),
uploadProgress: $blobGlobalState.blobEntries.last?.uploadProgress ?? .constant(0.0))
UploadButton(uploadProgress: $blobGlobalState.uploadProgress)
}

Divider()
Expand All @@ -22,7 +19,7 @@ struct BlobPopover: View {
previousUploadLocalPath: entries.last?.uploadLocalPath ?? URL(string: ""))

UploadProgressView(
uploadProgress: $blobGlobalState.blobEntries.last?.uploadProgress ?? .constant(0.0))
uploadProgress: $blobGlobalState.uploadProgress)

HStack {
TextField("", text: .constant(entries.last?.uploadURL ?? "")).frame(
Expand Down
4 changes: 1 addition & 3 deletions macos/plop/UploadButton.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import SwiftUI

struct UploadButton: View {
@Binding var previousUploadURL: String
@Binding var uploadProgress: Double

@State private var fileSelectionDialogPresented = false
Expand All @@ -26,7 +25,6 @@ struct UploadButton: View {
uploadTask.observe(.success) { _ in
NSSound(named: "Funk")?.play()
replaceClipboard(with: destinationURL)
previousUploadURL = destinationURL
}
} catch {
print("Could not get filepath for selected file.")
Expand All @@ -37,6 +35,6 @@ struct UploadButton: View {

struct UploadButton_Previews: PreviewProvider {
static var previews: some View {
UploadButton(previousUploadURL: .constant("https://google.com"), uploadProgress: .constant(1.0))
UploadButton(uploadProgress: .constant(1.0))
}
}

0 comments on commit 6d6f50b

Please sign in to comment.