Skip to content

Commit a596e5f

Browse files
committed
refactor preview code
1 parent 2fdc060 commit a596e5f

15 files changed

Lines changed: 153 additions & 362 deletions

Xcodes.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
36741BFD291E4FDB00A85AAE /* DownloadPreferencePane.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36741BFC291E4FDB00A85AAE /* DownloadPreferencePane.swift */; };
1111
36741BFF291E50F500A85AAE /* FileError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36741BFE291E50F500A85AAE /* FileError.swift */; };
12-
536CFDD2263C94DE00026CE0 /* SignedInView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 536CFDD1263C94DE00026CE0 /* SignedInView.swift */; };
12+
536CFDD2263C94DE00026CE0 /* SignedInView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 536CFDD1263C94DE00026CE0 /* SignedInView.swift */; };
1313
536CFDD4263C9A8000026CE0 /* XcodesSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 536CFDD3263C9A8000026CE0 /* XcodesSheet.swift */; };
1414
53CBAB2C263DCC9100410495 /* XcodesAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53CBAB2B263DCC9100410495 /* XcodesAlert.swift */; };
1515
63EAA4EB259944450046AB8F /* ProgressButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63EAA4EA259944450046AB8F /* ProgressButton.swift */; };

Xcodes/Frontend/InfoPane/CompatibilityView.swift

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,7 @@ struct CompatibilityView: View {
2525
}
2626
}
2727

28-
struct CompatibilityView_Preview: PreviewProvider {
29-
static var previews: some View {
30-
WrapperView()
31-
}
32-
}
33-
34-
private struct WrapperView: View {
35-
@State var isNil = false
36-
var requiredMacOSVersion: String? {
37-
isNil
38-
? nil
39-
: "10.15.4"
40-
}
41-
42-
var body: some View {
43-
VStack {
44-
HStack {
45-
CompatibilityView(requiredMacOSVersion: requiredMacOSVersion)
46-
.border(.red)
47-
}
48-
Spacer()
49-
Toggle(isOn: $isNil) {
50-
Text("Is Nil?")
51-
}
52-
}
53-
.frame(width: 200, height: 100)
54-
.padding()
55-
}
28+
#Preview {
29+
CompatibilityView(requiredMacOSVersion: "10.15.4")
30+
.padding()
5631
}

Xcodes/Frontend/InfoPane/CompilersView.swift

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -44,36 +44,15 @@ struct CompilersView: View {
4444
}
4545
}
4646

47-
struct CompilersView_Preview: PreviewProvider {
48-
static var previews: some View {
49-
WrapperView()
50-
}
51-
}
52-
53-
private struct WrapperView: View {
54-
@State var isNil = false
55-
var compilers: Compilers? {
56-
isNil
57-
? nil
58-
: Compilers(
59-
gcc: .init(number: "4"),
60-
llvm_gcc: .init(number: "213"),
61-
llvm: .init(number: "2.3"),
62-
clang: .init(number: "7.3"),
63-
swift: .init(number: "5.3.2"))
64-
}
65-
66-
var body: some View {
67-
VStack {
68-
CompilersView(compilers: compilers)
69-
.border(.red)
70-
Spacer()
71-
Toggle(isOn: $isNil) {
72-
Text("Is Nil?")
73-
}
74-
}
75-
.frame(width: 200, height: 100)
76-
.padding()
77-
}
47+
#Preview {
48+
let compilers = Compilers(
49+
gcc: .init(number: "4"),
50+
llvm_gcc: .init(number: "213"),
51+
llvm: .init(number: "2.3"),
52+
clang: .init(number: "7.3"),
53+
swift: .init(number: "5.3.2")
54+
)
55+
56+
return CompilersView(compilers: compilers)
57+
.padding()
7858
}
79-

Xcodes/Frontend/InfoPane/IconView.swift

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,14 @@ struct IconView: View {
2424
}
2525
}
2626

27-
//#Preview {
28-
// Group {
29-
// IconView(path: "/Applications/Xcode.app")
30-
// IconView()
31-
// }
32-
// .padding()
33-
//}
34-
35-
struct IconView_Preview: PreviewProvider {
36-
static var previews: some View {
37-
WrapperView()
38-
}
27+
#Preview("Installed") {
28+
IconView(installState: XcodeInstallState.installed(Path("/Applications/Xcode.app")!))
29+
.frame(width: 300, height: 100)
30+
.padding()
3931
}
4032

41-
private struct WrapperView: View {
42-
@State var isIcon = false
43-
var state: XcodeInstallState {
44-
isIcon
45-
? XcodeInstallState.installed(Path("/Applications/Xcode.app")!)
46-
: XcodeInstallState.notInstalled
47-
}
48-
49-
var body: some View {
50-
VStack {
51-
IconView(installState: state)
52-
.border(.red)
53-
Spacer()
54-
Toggle(isOn: $isIcon) {
55-
Text("Icon?")
56-
}
57-
}
58-
.frame(width: 300, height: 100)
59-
.padding()
60-
}
33+
#Preview("Not Installed") {
34+
IconView(installState: XcodeInstallState.notInstalled)
35+
.frame(width: 300, height: 100)
36+
.padding()
6137
}

Xcodes/Frontend/InfoPane/IdenticalBuildView.swift

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,14 @@ struct IdenticalBuildsView: View {
4949
}
5050
}
5151

52-
struct IdenticalBuildsView_Preview: PreviewProvider {
53-
static var previews: some View {
54-
WrapperView()
55-
}
56-
}
52+
let builds: [Version] = [.init(xcodeVersion: "15.0")!, .init(xcodeVersion: "15.1")!]
5753

58-
private struct WrapperView: View {
59-
@State var isEmpty = false
60-
var builds: [Version] {
61-
isEmpty
62-
? []
63-
: [.init(xcodeVersion: "15.0")!,
64-
.init(xcodeVersion: "15.1")!]
65-
}
54+
#Preview("Has Some Builds") {
55+
IdenticalBuildsView(builds: builds)
56+
.padding()
57+
}
6658

67-
var body: some View {
68-
VStack {
69-
IdenticalBuildsView(builds: builds)
70-
.border(.red)
71-
Spacer()
72-
Toggle(isOn: $isEmpty) {
73-
Text("No Builds?")
74-
}
75-
}
76-
.frame(width: 300, height: 100)
77-
.padding()
78-
}
59+
#Preview("No Build") {
60+
IdenticalBuildsView(builds: [])
61+
.padding()
7962
}

Xcodes/Frontend/InfoPane/InfoPane.swift

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,36 +36,21 @@ struct InfoPane: View {
3636
}
3737
}
3838

39-
struct InfoPane_Previews: PreviewProvider {
40-
static var previews: some View {
41-
WrapperView()
42-
}
43-
}
39+
#Preview(PreviewName.allCases[0].rawValue) { makePreviewContent(for: 0) }
40+
#Preview(PreviewName.allCases[1].rawValue) { makePreviewContent(for: 1) }
41+
#Preview(PreviewName.allCases[2].rawValue) { makePreviewContent(for: 2) }
42+
#Preview(PreviewName.allCases[3].rawValue) { makePreviewContent(for: 3) }
43+
#Preview(PreviewName.allCases[4].rawValue) { makePreviewContent(for: 4) }
4444

45-
private struct WrapperView: View {
46-
@State var name: PreviewName = .Populated_Installed_Selected
47-
48-
var body: some View {
49-
VStack {
50-
InfoPane(xcode: xcode)
51-
.environmentObject(configure(AppState()) {
52-
$0.allXcodes = [xcode]
53-
})
54-
.border(.red)
55-
.frame(width: 300, height: 400)
56-
Spacer()
57-
Picker("Preview Name", selection: $name) {
58-
ForEach(PreviewName.allCases) {
59-
Text($0.rawValue).tag($0)
60-
}
61-
}
62-
.pickerStyle(.inline)
63-
}
64-
.frame(maxWidth: .infinity)
65-
.padding()
66-
}
45+
private func makePreviewContent(for index: Int) -> some View {
46+
let name = PreviewName.allCases[index]
6747

68-
var xcode: Xcode { xcodeDict[name]! }
48+
return InfoPane(xcode: xcodeDict[name]!)
49+
.environmentObject(configure(AppState()) {
50+
$0.allXcodes = [xcodeDict[name]!]
51+
})
52+
.frame(width: 300, height: 400)
53+
.padding()
6954
}
7055

7156
enum PreviewName: String, CaseIterable, Identifiable {

Xcodes/Frontend/InfoPane/InfoPaneControls.swift

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,19 @@ struct InfoPaneControls: View {
2828
}
2929
}
3030

31-
struct InfoPaneControls_Previews: PreviewProvider {
32-
static var previews: some View {
33-
WrapperView()
34-
}
35-
}
36-
37-
private struct WrapperView: View {
38-
@State var name: PreviewName = .Populated_Installed_Selected
39-
40-
var body: some View {
41-
VStack {
42-
InfoPaneControls(xcode: xcode)
43-
.environmentObject(configure(AppState()) {
44-
$0.allXcodes = [xcode]
45-
})
46-
.border(.red)
47-
.frame(width: 300, height: 400)
48-
Spacer()
49-
Picker("Preview Name", selection: $name) {
50-
ForEach(PreviewName.allCases) {
51-
Text($0.rawValue).tag($0)
52-
}
53-
}
54-
.pickerStyle(.inline)
55-
56-
}
57-
.frame(maxWidth: .infinity)
58-
.padding()
59-
}
60-
61-
var xcode: Xcode { xcodeDict[name]! }
31+
#Preview(PreviewName.allCases[0].rawValue) { makePreviewContent(for: 0) }
32+
#Preview(PreviewName.allCases[1].rawValue) { makePreviewContent(for: 1) }
33+
#Preview(PreviewName.allCases[2].rawValue) { makePreviewContent(for: 2) }
34+
#Preview(PreviewName.allCases[3].rawValue) { makePreviewContent(for: 3) }
35+
#Preview(PreviewName.allCases[4].rawValue) { makePreviewContent(for: 4) }
36+
37+
private func makePreviewContent(for index: Int) -> some View {
38+
let name = PreviewName.allCases[index]
39+
40+
return InfoPaneControls(xcode: xcodeDict[name]!)
41+
.environmentObject(configure(AppState()) {
42+
$0.allXcodes = [xcodeDict[name]!]
43+
})
44+
.frame(width: 300)
45+
.padding()
6246
}

Xcodes/Frontend/InfoPane/InstallationStepDetailView.swift

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,25 @@ struct InstallationStepDetailView: View {
2424
}
2525
}
2626

27-
struct InstallDetailView_Previews: PreviewProvider {
28-
static var previews: some View {
29-
Group {
30-
InstallationStepDetailView(
31-
installationStep: .downloading(
32-
progress: configure(Progress()) {
33-
$0.kind = .file
34-
$0.fileOperationKind = .downloading
35-
$0.estimatedTimeRemaining = 123
36-
$0.totalUnitCount = 11944848484
37-
$0.completedUnitCount = 848444920
38-
$0.throughput = 9211681
39-
}
40-
)
41-
)
27+
#Preview("Downloading") {
28+
InstallationStepDetailView(
29+
installationStep: .downloading(
30+
progress: configure(Progress()) {
31+
$0.kind = .file
32+
$0.fileOperationKind = .downloading
33+
$0.estimatedTimeRemaining = 123
34+
$0.totalUnitCount = 11944848484
35+
$0.completedUnitCount = 848444920
36+
$0.throughput = 9211681
37+
}
38+
)
39+
)
40+
.padding()
41+
}
4242

43-
InstallationStepDetailView(
44-
installationStep: .unarchiving
45-
)
46-
}
47-
.padding()
48-
}
43+
#Preview("Unarchiving") {
44+
InstallationStepDetailView(
45+
installationStep: .unarchiving
46+
)
47+
.padding()
4948
}

Xcodes/Frontend/InfoPane/InstalledStateButtons.swift

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -42,38 +42,35 @@ struct InstalledStateButtons: View {
4242
}
4343
}
4444

45-
struct InstalledStateButtons_Preview: PreviewProvider {
46-
static var previews: some View {
47-
InstalledStateButtons(xcode: Self.xcode)
48-
.environmentObject(configure(AppState()) {
49-
$0.allXcodes = [Self.xcode]
50-
})
51-
.padding()
52-
.frame(width: 300)
53-
}
54-
55-
static private let xcode = Xcode(
56-
version: Version(major: 12, minor: 3, patch: 0),
57-
installState: .installed(Path("/Applications/Xcode-12.3.0.app")!),
58-
selected: true,
59-
icon: NSWorkspace.shared.icon(forFile: "/Applications/Xcode-12.3.0.app"),
60-
requiredMacOSVersion: "10.15.4",
61-
releaseNotesURL: URL(string: "https://developer.apple.com/documentation/xcode-release-notes/xcode-12_3-release-notes/")!,
62-
releaseDate: Date(),
63-
sdks: SDKs(
64-
macOS: .init(number: "11.1"),
65-
iOS: .init(number: "14.3"),
66-
watchOS: .init(number: "7.3"),
67-
tvOS: .init(number: "14.3")
68-
),
69-
compilers: Compilers(
70-
gcc: .init(number: "4"),
71-
llvm_gcc: .init(number: "213"),
72-
llvm: .init(number: "2.3"),
73-
clang: .init(number: "7.3"),
74-
swift: .init(number: "5.3.2")
75-
),
76-
downloadFileSize: 242342424
77-
)
45+
#Preview {
46+
InstalledStateButtons(xcode: xcode)
47+
.environmentObject(configure(AppState()) {
48+
$0.allXcodes = [xcode]
49+
})
50+
.padding()
51+
.frame(width: 300)
7852
}
7953

54+
private let xcode = Xcode(
55+
version: Version(major: 12, minor: 3, patch: 0),
56+
installState: .installed(Path("/Applications/Xcode-12.3.0.app")!),
57+
selected: true,
58+
icon: NSWorkspace.shared.icon(forFile: "/Applications/Xcode-12.3.0.app"),
59+
requiredMacOSVersion: "10.15.4",
60+
releaseNotesURL: URL(string: "https://developer.apple.com/documentation/xcode-release-notes/xcode-12_3-release-notes/")!,
61+
releaseDate: Date(),
62+
sdks: SDKs(
63+
macOS: .init(number: "11.1"),
64+
iOS: .init(number: "14.3"),
65+
watchOS: .init(number: "7.3"),
66+
tvOS: .init(number: "14.3")
67+
),
68+
compilers: Compilers(
69+
gcc: .init(number: "4"),
70+
llvm_gcc: .init(number: "213"),
71+
llvm: .init(number: "2.3"),
72+
clang: .init(number: "7.3"),
73+
swift: .init(number: "5.3.2")
74+
),
75+
downloadFileSize: 242342424
76+
)

0 commit comments

Comments
 (0)