Skip to content

Commit 3e270d9

Browse files
committed
fix: folder statistics when folder is not shared yet
Signed-off-by: Tommy van der Vorst <tommy@pixelspark.nl>
1 parent 2e5d027 commit 3e270d9

File tree

2 files changed

+71
-12
lines changed

2 files changed

+71
-12
lines changed

Localizable.xcstrings

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34920,6 +34920,52 @@
3492034920
}
3492134921
}
3492234922
},
34923+
"This folder has not been shared with any other devices yet." : {
34924+
"localizations" : {
34925+
"de" : {
34926+
"stringUnit" : {
34927+
"state" : "translated",
34928+
"value" : "Dieser Ordner wurde noch nicht mit anderen Geräten geteilt."
34929+
}
34930+
},
34931+
"es" : {
34932+
"stringUnit" : {
34933+
"state" : "translated",
34934+
"value" : "Esta carpeta aún no se ha compartido con otros dispositivos."
34935+
}
34936+
},
34937+
"it" : {
34938+
"stringUnit" : {
34939+
"state" : "translated",
34940+
"value" : "Questa cartella non è ancora stata condivisa con altri dispositivi."
34941+
}
34942+
},
34943+
"ja" : {
34944+
"stringUnit" : {
34945+
"state" : "translated",
34946+
"value" : "このフォルダはまだ他のデバイスと共有されていません。"
34947+
}
34948+
},
34949+
"nl" : {
34950+
"stringUnit" : {
34951+
"state" : "translated",
34952+
"value" : "Deze map is nog niet met andere apparaten gedeeld."
34953+
}
34954+
},
34955+
"uk" : {
34956+
"stringUnit" : {
34957+
"state" : "translated",
34958+
"value" : "Ця папка ще не була поширена на інші пристрої."
34959+
}
34960+
},
34961+
"zh-Hans" : {
34962+
"stringUnit" : {
34963+
"state" : "translated",
34964+
"value" : "此文件夹尚未与其他设备共享。"
34965+
}
34966+
}
34967+
}
34968+
},
3492334969
"This folder is external to this app, and cannot be accessed anymore. To resolve this issue, unlink the folder and re-add it." : {
3492434970
"localizations" : {
3492534971
"de" : {

Sushitrain/FolderStatisticsView.swift

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ struct FolderStatisticsView: View {
167167

168168
self.loading = true
169169
await Task.detached {
170-
let peers = await appState.peers().filter({ d in !d.isSelf() })
170+
let sharedWithDeviceIDs = Set(folder.sharedWithDeviceIDs()?.asArray() ?? [])
171+
let peers = await appState.peers().filter({ d in !d.isSelf() && sharedWithDeviceIDs.contains(d.id) })
171172
var dict: [String: SushitrainPeer] = [:]
172173
for peer in peers {
173174
dict[peer.deviceID()] = peer
@@ -178,7 +179,7 @@ struct FolderStatisticsView: View {
178179
Task { @MainActor in
179180
self.allDevices = dict
180181
self.statistics = stats
181-
self.completions = completions ?? [:]
182+
self.completions = (completions ?? [:]).filter({ dict[$0.key] != nil })
182183
}
183184
}.value
184185
self.loading = false
@@ -196,18 +197,25 @@ struct FolderStatisticsView: View {
196197
}
197198
}
198199
else if let stats = self.statistics {
199-
FolderProgressChartView(statistics: stats, progressType: folder.isSelective() ? .stores : .needs).frame(height: 48)
200-
201-
// Global statistics
202-
if let g = stats.global {
203-
Section("Full folder") {
204-
// Use .formatted() here because zero is hidden in badges and that looks weird
205-
Text("Number of files").badge(g.files.formatted())
206-
Text("Number of directories").badge(g.directories.formatted())
207-
Text("File size").badge(formatter.string(fromByteCount: g.bytes))
200+
if !self.allDevices.isEmpty {
201+
FolderProgressChartView(statistics: stats, progressType: folder.isSelective() ? .stores : .needs).frame(height: 48)
202+
203+
// Global statistics
204+
if let g = stats.global {
205+
Section("Full folder") {
206+
// Use .formatted() here because zero is hidden in badges and that looks weird
207+
Text("Number of files").badge(g.files.formatted())
208+
Text("Number of directories").badge(g.directories.formatted())
209+
Text("File size").badge(formatter.string(fromByteCount: g.bytes))
210+
}
208211
}
212+
213+
}
214+
else {
215+
Text("This folder has not been shared with any other devices yet.")
209216
}
210217

218+
// Local stats
211219
let totalLocal = Double(stats.global!.bytes)
212220
let myPercentage = Int(
213221
totalLocal > 0 ? (100.0 * Double(stats.local!.bytes) / totalLocal) : 100)
@@ -221,7 +229,12 @@ struct FolderStatisticsView: View {
221229
Text("File size").badge(formatter.string(fromByteCount: local.bytes))
222230
} header: {
223231
HStack {
224-
Text("On this device: \(myPercentage)% of the full folder")
232+
if self.allDevices.isEmpty {
233+
Text("On this device")
234+
}
235+
else {
236+
Text("On this device: \(myPercentage)% of the full folder")
237+
}
225238
}
226239
}
227240
}

0 commit comments

Comments
 (0)