Skip to content

Commit 574ea8c

Browse files
committed
ux: allow navigating to file from recent changes view
1 parent 7de478c commit 574ea8c

File tree

1 file changed

+37
-24
lines changed

1 file changed

+37
-24
lines changed

Sushitrain/ChangesView.swift

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,54 @@
55
// You can obtain one at https://mozilla.org/MPL/2.0/.
66
import Foundation
77
import SwiftUI
8+
@preconcurrency import SushitrainCore
89

910
struct ChangesView: View {
1011
@ObservedObject var appState: AppState
12+
1113
var body: some View {
1214
List {
1315
ForEach(appState.lastChanges, id: \.id) { change in
1416
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)
3924
}
4025
}
4126
}
4227
}
4328
.navigationTitle("Recent changes")
4429
}
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+
}
4558
}

0 commit comments

Comments
 (0)