| 1 | import SwiftUI |
| 2 | |
| 3 | /// The bounded Engineering listing, shared by the phone tab and Mac detail. |
| 4 | struct ChangedFilesList: View { |
| 5 | let facts: ThinChangeFiles |
| 6 | var openFile: (ThinChangedFile) -> Void |
| 7 | |
| 8 | var body: some View { |
| 9 | VStack(alignment: .leading, spacing: 16) { |
| 10 | Text(ChangedFilesPresentation.total(files: facts.files, additions: facts.additions, deletions: facts.deletions)) |
| 11 | .font(.headline).fixedSize(horizontal: false, vertical: true) |
| 12 | ForEach(ChangedFilesPresentation.groups(facts)) { group in |
| 13 | VStack(alignment: .leading, spacing: 0) { |
| 14 | if !group.folder.isEmpty { |
| 15 | Text(verbatim: VisibleCodeText.display(group.folder)).font(Typo.secondaryStrong).foregroundStyle(Palette.secondary).padding(.bottom, 8) |
| 16 | } |
| 17 | ForEach(group.files) { file in |
| 18 | Button { openFile(file) } label: { ChangedFileLabel(file: file) } |
| 19 | .buttonStyle(.plain) |
| 20 | .accessibilityLabel(accessibility(file)) |
| 21 | .accessibilityIdentifier("changed-file-" + file.path) |
| 22 | Divider() |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | if facts.truncated { |
| 27 | Text(String(format: EquipoStrings.text("native.changes.truncated"), facts.entries.count)) |
| 28 | .font(Typo.secondary).foregroundStyle(Palette.secondary).fixedSize(horizontal: false, vertical: true) |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | private func accessibility(_ file: ThinChangedFile) -> String { |
| 33 | [ChangedFilesPresentation.displayPath(file), ChangedFilesPresentation.status(file), |
| 34 | ChangedFilesPresentation.renamedFrom(file), |
| 35 | file.binary ? EquipoStrings.text("native.changes.binary") |
| 36 | : ChangedFilesPresentation.total(files: 1, additions: file.additions, deletions: file.deletions)] |
| 37 | .compactMap { $0 }.joined(separator: ", ") |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | private struct ChangedFileLabel: View { |
| 42 | let file: ThinChangedFile |
| 43 | var body: some View { |
| 44 | HStack(alignment: .top, spacing: 12) { |
| 45 | VStack(alignment: .leading, spacing: 6) { |
| 46 | Text(verbatim: ChangedFilesPresentation.displayPath(file)).font(.system(.subheadline, design: .monospaced)) |
| 47 | .foregroundStyle(Palette.text).fixedSize(horizontal: false, vertical: true) |
| 48 | if let old = ChangedFilesPresentation.renamedFrom(file) { |
| 49 | Text(verbatim: old) |
| 50 | .font(Typo.caption).foregroundStyle(Palette.secondary).fixedSize(horizontal: false, vertical: true) |
| 51 | } |
| 52 | HStack(spacing: 12) { |
| 53 | Text(ChangedFilesPresentation.status(file)).font(Typo.caption).foregroundStyle(Palette.secondary) |
| 54 | if file.binary { |
| 55 | Text(EquipoStrings.text("native.changes.binary")).font(Typo.caption).foregroundStyle(Palette.secondary) |
| 56 | } else { |
| 57 | Text(verbatim: "+\(file.additions)").foregroundStyle(Palette.positive) |
| 58 | Text(verbatim: "−\(file.deletions)").foregroundStyle(Palette.negative) |
| 59 | } |
| 60 | }.font(.system(.caption, design: .monospaced)) |
| 61 | }.frame(maxWidth: .infinity, alignment: .leading) |
| 62 | Image(systemName: "chevron.right").font(.caption).foregroundStyle(Palette.secondary) |
| 63 | }.padding(.vertical, 12).frame(minHeight: 44).contentShape(Rectangle()) |
| 64 | } |
| 65 | } |
| 66 | |