|
5 | 5 | // You can obtain one at https://mozilla.org/MPL/2.0/. |
6 | 6 | import Foundation |
7 | 7 | import SwiftUI |
| 8 | +@preconcurrency import SushitrainCore |
8 | 9 |
|
9 | 10 | struct ChangesView: View { |
10 | 11 | @ObservedObject var appState: AppState |
| 12 | + |
11 | 13 | var body: some View { |
12 | 14 | List { |
13 | 15 | ForEach(appState.lastChanges, id: \.id) { change in |
14 | 16 | if let folder = appState.client.folder(withID: change.folderID) { |
15 | | - HStack { |
16 | | - VStack(alignment: .leading) { |
17 | | - Text("\(folder.displayName): \(change.path)") |
18 | | - .multilineTextAlignment(.leading) |
19 | | - .bold() |
20 | | - |
21 | | - if let dateString = change.time?.date().formatted() { |
22 | | - Text(dateString).dynamicTypeSize(.small) |
23 | | - .foregroundColor(.gray) |
24 | | - } |
25 | | - |
26 | | - if let peer = appState.client.peer(withShortID: change.shortID) { |
27 | | - if peer.deviceID() == appState.localDeviceID { |
28 | | - Text("By this device").dynamicTypeSize(.small) |
29 | | - .foregroundColor(.gray) |
30 | | - } |
31 | | - else { |
32 | | - Text("By \(peer.displayName)").dynamicTypeSize( |
33 | | - .small |
34 | | - ).foregroundColor(.gray) |
35 | | - } |
36 | | - } |
37 | | - }.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading) |
38 | | - Image(systemName: change.systemImage) |
| 17 | + if let entry = try? folder.getFileInformation(change.path), !entry.isDeleted() { |
| 18 | + NavigationLink(destination: FileView(file: entry, appState: self.appState, showPath: true, siblings: [])) { |
| 19 | + self.changeDetails(change: change, folder: folder) |
| 20 | + } |
| 21 | + } |
| 22 | + else { |
| 23 | + self.changeDetails(change: change, folder: folder) |
39 | 24 | } |
40 | 25 | } |
41 | 26 | } |
42 | 27 | } |
43 | 28 | .navigationTitle("Recent changes") |
44 | 29 | } |
| 30 | + |
| 31 | + @ViewBuilder private func changeDetails(change: SushitrainChange, folder: SushitrainFolder) -> some View { |
| 32 | + HStack { |
| 33 | + VStack(alignment: .leading) { |
| 34 | + Text("\(folder.displayName): \(change.path)") |
| 35 | + .multilineTextAlignment(.leading) |
| 36 | + .bold() |
| 37 | + |
| 38 | + if let dateString = change.time?.date().formatted() { |
| 39 | + Text(dateString).dynamicTypeSize(.small) |
| 40 | + .foregroundColor(.gray) |
| 41 | + } |
| 42 | + |
| 43 | + if let peer = appState.client.peer(withShortID: change.shortID) { |
| 44 | + if peer.deviceID() == appState.localDeviceID { |
| 45 | + Text("By this device").dynamicTypeSize(.small) |
| 46 | + .foregroundColor(.gray) |
| 47 | + } |
| 48 | + else { |
| 49 | + Text("By \(peer.displayName)").dynamicTypeSize( |
| 50 | + .small |
| 51 | + ).foregroundColor(.gray) |
| 52 | + } |
| 53 | + } |
| 54 | + }.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading) |
| 55 | + Image(systemName: change.systemImage) |
| 56 | + } |
| 57 | + } |
45 | 58 | } |
0 commit comments