Skip to content

Commit 6db601f

Browse files
committed
add media upload counter next to progress bar
1 parent 50a4190 commit 6db601f

File tree

4 files changed

+89
-4
lines changed

4 files changed

+89
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"originHash" : "0c5ba17ae4238ee8c0614e8f0957f83778e450906dcaf8ccca5c1aa44c24a252",
3+
"pins" : [
4+
{
5+
"identity" : "gsplayer",
6+
"kind" : "remoteSourceControl",
7+
"location" : "https://github.com/wxxsw/GSPlayer",
8+
"state" : {
9+
"revision" : "aa6dad7943d52f5207f7fcc2ad3e4274583443b8",
10+
"version" : "0.2.26"
11+
}
12+
},
13+
{
14+
"identity" : "kingfisher",
15+
"kind" : "remoteSourceControl",
16+
"location" : "https://github.com/onevcat/Kingfisher",
17+
"state" : {
18+
"revision" : "415b1d97fb38bda1e5a6b2dde63354720832110b",
19+
"version" : "7.6.1"
20+
}
21+
},
22+
{
23+
"identity" : "secp256k1.swift",
24+
"kind" : "remoteSourceControl",
25+
"location" : "https://github.com/jb55/secp256k1.swift",
26+
"state" : {
27+
"revision" : "40b4b38b3b1c83f7088c76189a742870e0ca06a9"
28+
}
29+
},
30+
{
31+
"identity" : "swift-markdown-ui",
32+
"kind" : "remoteSourceControl",
33+
"location" : "https://github.com/damus-io/swift-markdown-ui",
34+
"state" : {
35+
"revision" : "76bb7971da7fbf429de1c84f1244adf657242fee"
36+
}
37+
},
38+
{
39+
"identity" : "swift-snapshot-testing",
40+
"kind" : "remoteSourceControl",
41+
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
42+
"state" : {
43+
"revision" : "5b356adceabff6ca027f6574aac79e9fee145d26",
44+
"version" : "1.14.1"
45+
}
46+
},
47+
{
48+
"identity" : "swift-syntax",
49+
"kind" : "remoteSourceControl",
50+
"location" : "https://github.com/apple/swift-syntax.git",
51+
"state" : {
52+
"revision" : "74203046135342e4a4a627476dd6caf8b28fe11b",
53+
"version" : "509.0.0"
54+
}
55+
}
56+
],
57+
"version" : 3
58+
}

damus.xcodeproj/xcshareddata/xcschemes/DamusNotificationService.xcscheme

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
savedToolIdentifier = ""
7878
useCustomWorkingDirectory = "NO"
7979
debugDocumentVersioning = "YES"
80+
askForAppToLaunch = "Yes"
8081
launchAutomaticallySubstyle = "2">
8182
<BuildableProductRunnable
8283
runnableDebuggingMode = "0">

damus/Models/ImageUploadModel.swift

+21-2
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,15 @@ enum MediaUpload {
5353

5454
class ImageUploadModel: NSObject, URLSessionTaskDelegate, ObservableObject {
5555
@Published var progress: Double? = nil
56+
@Published var currentImagesUploaded: Int = 0
57+
@Published var totalImagesToUpload: Int = 0
58+
private var completedUploads: Int = 0
5659

5760
func start(media: MediaUpload, uploader: MediaUploader, keypair: Keypair? = nil) async -> ImageUploadResult {
58-
let res = await create_upload_request(mediaToUpload: media, mediaUploader: uploader, progress: self, keypair: keypair)
5961
DispatchQueue.main.async {
60-
self.progress = nil
62+
self.totalImagesToUpload += 1
6163
}
64+
let res = await create_upload_request(mediaToUpload: media, mediaUploader: uploader, progress: self, keypair: keypair)
6265
return res
6366
}
6467

@@ -67,4 +70,20 @@ class ImageUploadModel: NSObject, URLSessionTaskDelegate, ObservableObject {
6770
self.progress = Double(totalBytesSent) / Double(totalBytesExpectedToSend)
6871
}
6972
}
73+
74+
func didFinishUpload() {
75+
DispatchQueue.main.async {
76+
self.completedUploads += 1
77+
self.currentImagesUploaded = self.completedUploads
78+
}
79+
}
80+
81+
func resetProgress() {
82+
DispatchQueue.main.async {
83+
self.progress = nil
84+
self.currentImagesUploaded = 0
85+
self.totalImagesToUpload = 0
86+
self.completedUploads = 0
87+
}
88+
}
7089
}

damus/Views/PostView.swift

+9-2
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,11 @@ struct PostView: View {
285285
}
286286

287287
if let progress = image_upload.progress {
288-
ProgressView(value: progress, total: 1.0)
289-
.progressViewStyle(.linear)
288+
HStack {
289+
ProgressView(value: progress, total: 1.0)
290+
.progressViewStyle(.linear)
291+
Text("\(image_upload.currentImagesUploaded)/\(image_upload.totalImagesToUpload)")
292+
}
290293
}
291294

292295
Divider()
@@ -316,6 +319,7 @@ struct PostView: View {
316319
let meta = blurhash.map { bh in calculate_image_metadata(url: url, img: img, blurhash: bh) }
317320
let uploadedMedia = UploadedMedia(localURL: media.localURL, uploadedURL: url, representingImage: img, metadata: meta)
318321
uploadedMedias.append(uploadedMedia)
322+
image_upload.didFinishUpload()
319323

320324
case .failed(let error):
321325
if let error {
@@ -325,6 +329,9 @@ struct PostView: View {
325329
}
326330
}
327331

332+
if (image_upload.currentImagesUploaded + 1) == image_upload.totalImagesToUpload {
333+
image_upload.resetProgress()
334+
}
328335
}
329336
}
330337

0 commit comments

Comments
 (0)