@@ -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