@@ -24,8 +24,8 @@ struct FileHistoryView: View {
2424 @Environment ( \. fileHistoryLoader)
2525 private var fileHistoryLoader
2626
27- @Environment ( \ . dismiss )
28- private var dismiss
27+ @Environment ( AppState . self )
28+ private var appState
2929
3030 var body : some View {
3131 VStack ( spacing: 0 ) {
@@ -44,10 +44,9 @@ struct FileHistoryView: View {
4444 }
4545 }
4646 }
47- . frame ( minWidth: 700 , minHeight: 500 )
4847 . background ( PoirotTheme . Colors. bgApp)
4948 . task {
50- loadHistory ( )
49+ await loadHistory ( )
5150 }
5251 }
5352
@@ -79,7 +78,7 @@ struct FileHistoryView: View {
7978 Spacer ( )
8079
8180 Button {
82- dismiss ( )
81+ appState . isShowingFileHistory = false
8382 } label: {
8483 Image ( systemName: " xmark.circle.fill " )
8584 . font ( PoirotTheme . Typography. large)
@@ -184,7 +183,7 @@ struct FileHistoryView: View {
184183 || ( selectedVersionIndex == nil && index == entry. versions. count - 1 )
185184 Button {
186185 selectedVersionIndex = index
187- loadVersionContent ( entry: entry, versionIndex: index)
186+ Task { await loadVersionContent ( entry: entry, versionIndex: index) }
188187 } label: {
189188 HStack ( spacing: PoirotTheme . Spacing. xs) {
190189 Image ( systemName: isSelected ? " circle.fill " : " circle " )
@@ -243,7 +242,7 @@ struct FileHistoryView: View {
243242 ProgressView ( )
244243 . frame ( maxWidth: . infinity, maxHeight: . infinity)
245244 . task ( id: currentKey) {
246- loadVersionContent ( entry: entry, versionIndex: effectiveIndex)
245+ await loadVersionContent ( entry: entry, versionIndex: effectiveIndex)
247246 }
248247 } else {
249248 ScrollView {
@@ -261,7 +260,7 @@ struct FileHistoryView: View {
261260 ProgressView ( )
262261 . frame ( maxWidth: . infinity, maxHeight: . infinity)
263262 . task ( id: currentKey) {
264- loadVersionContent ( entry: entry, versionIndex: effectiveIndex)
263+ await loadVersionContent ( entry: entry, versionIndex: effectiveIndex)
265264 }
266265 } else {
267266 ScrollView {
@@ -325,42 +324,47 @@ struct FileHistoryView: View {
325324
326325 // MARK: - Data Loading
327326
328- private func loadHistory( ) {
327+ private func loadHistory( ) async {
329328 let loader = fileHistoryLoader
330329 let sessionId = session. id
331330 let projectPath = session. projectPath
332- entries = loader. loadFileHistory ( for: sessionId, projectPath: projectPath)
331+ let loaded = await Task . detached {
332+ loader. loadFileHistory ( for: sessionId, projectPath: projectPath)
333+ } . value
334+ entries = loaded
333335 isLoading = false
334336 iconBounce += 1
335337
336338 // Auto-select first file
337339 if let first = entries. first {
338340 selectedFile = first
339- loadVersionContent ( entry: first, versionIndex: first. versions. count - 1 )
341+ await loadVersionContent ( entry: first, versionIndex: first. versions. count - 1 )
340342 }
341343 }
342344
343- private func loadVersionContent( entry: FileHistoryEntry , versionIndex: Int ) {
345+ private func loadVersionContent( entry: FileHistoryEntry , versionIndex: Int ) async {
344346 let loader = fileHistoryLoader
345347 let sessionId = session. id
346348
347349 // Load the selected version
348350 let version = entry. versions [ versionIndex]
349351 let key = " \( sessionId) / \( version. backupFileName) "
350352 if fileContents [ key] == nil {
351- fileContents [ key] = loader. loadFileContent (
352- for: sessionId, backupFileName: version. backupFileName
353- ) ?? " "
353+ let content = await Task . detached {
354+ loader. loadFileContent ( for: sessionId, backupFileName: version. backupFileName)
355+ } . value
356+ fileContents [ key] = content ?? " "
354357 }
355358
356359 // Also load previous version for diff
357360 if versionIndex > 0 {
358361 let prev = entry. versions [ versionIndex - 1 ]
359362 let prevKey = " \( sessionId) / \( prev. backupFileName) "
360363 if fileContents [ prevKey] == nil {
361- fileContents [ prevKey] = loader. loadFileContent (
362- for: sessionId, backupFileName: prev. backupFileName
363- ) ?? " "
364+ let content = await Task . detached {
365+ loader. loadFileContent ( for: sessionId, backupFileName: prev. backupFileName)
366+ } . value
367+ fileContents [ prevKey] = content ?? " "
364368 }
365369 }
366370 }
@@ -388,7 +392,7 @@ struct FileHistoryView: View {
388392 return components. dropLast ( ) . joined ( separator: " / " )
389393 }
390394
391- nonisolated ( unsafe ) private static let timeFormatter : DateFormatter = {
395+ private static let timeFormatter : DateFormatter = {
392396 let fmt = DateFormatter ( )
393397 fmt. dateFormat = " HH:mm:ss "
394398 return fmt
0 commit comments