Skip to content

Commit 49cdd8f

Browse files
authored
Fixed various sample projects issues (#1217)
1 parent 318a8fd commit 49cdd8f

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

Stitch/App/Serialization/SampleProjects.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func downloadFile(from url: URL,
2626

2727
// Used by modal that imports a single sample project.
2828
func importStitchSampleProject(sampleProjectURL: URL,
29-
store: StitchStore) async {
29+
store: StitchStore) async throws {
3030

3131
log("importStitchSampleProjectSideEffect: sampleProjectURL: \(sampleProjectURL)")
3232

@@ -58,7 +58,7 @@ func importStitchSampleProject(sampleProjectURL: URL,
5858

5959
} catch {
6060
log("importStitchSampleProjectSideEffect: Download failed: \(error)")
61-
fatalErrorIfDebug()
61+
throw error
6262
}
6363
}
6464

Stitch/Home/View/SampleProjectsView.swift

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,28 @@ struct SampleProjectsView: View {
6767
}
6868

6969
struct SampleProjectsList: View {
70+
// displays loading screen when tapped
71+
@State private var urlLoadingForPresentation: URL?
72+
7073
@Bindable var store: StitchStore
7174

7275
var body: some View {
7376
VStack(alignment: .leading) {
7477
HStack {
7578
SampleProjectView(store: store,
79+
urlLoadingForPresentation: $urlLoadingForPresentation,
7680
data: .init(projectName: "Monthly Stays (Josh Pekera)",
7781
projectURL: "Monthly_Stays/Monthly%20Stays%20(Josh%20Pekera).stitch",
7882
projectAssetName: "MonthlyStays")
7983
)
8084
SampleProjectView(store: store,
85+
urlLoadingForPresentation: $urlLoadingForPresentation,
8186
data: .init(projectName: "Music Player (GK3)",
8287
projectURL: "Music_Player/Music%20Player%20(GK3).stitch",
8388
projectAssetName: "MusicPlayer")
8489
)
8590
SampleProjectView(store: store,
91+
urlLoadingForPresentation: $urlLoadingForPresentation,
8692
data: .init(projectName: "Hello World",
8793
projectURL: "Hello_World/Hello%20World.stitch",
8894
projectAssetName: "HelloWorld")
@@ -91,11 +97,13 @@ struct SampleProjectsList: View {
9197

9298
HStack {
9399
SampleProjectView(store: store,
100+
urlLoadingForPresentation: $urlLoadingForPresentation,
94101
data: .init(projectName: "Wallet",
95102
projectURL: "Wallet/Wallet%20(Wayne%20Sang).stitch",
96103
projectAssetName: "Wallet")
97104
)
98105
SampleProjectView(store: store,
106+
urlLoadingForPresentation: $urlLoadingForPresentation,
99107
data: .init(projectName: "AR Robot (Elliot)",
100108
projectURL:"AR_Robot/AR%20Robot%20(Elliot).stitch",
101109
projectAssetName: "ARRobot")
@@ -135,25 +143,41 @@ struct SampleProjectsList: View {
135143
}
136144

137145
struct SampleProjectView: View {
138-
// displays loading screen when tapped
139-
@State private var isLoadingForPresentation = false
140146

141147
@Bindable var store: StitchStore
142148

149+
// displays loading screen when tapped
150+
@Binding var urlLoadingForPresentation: URL?
151+
143152
let data: SampleProjectData?
144153

154+
var isLoadingForPresentation: Bool {
155+
urlLoadingForPresentation == data?.url
156+
}
157+
145158
var body: some View {
146159
if let data = data {
147160
Button {
148-
self.isLoadingForPresentation = true
161+
// Only load project if another isn't loading
162+
guard !self.isLoadingForPresentation else {
163+
return
164+
}
165+
166+
DispatchQueue.main.async {
167+
self.urlLoadingForPresentation = data.url
168+
}
149169

150170
Task(priority: .high) { [weak store] in
151171
if let store = store {
152-
await importStitchSampleProject(sampleProjectURL: data.url,
153-
store: store)
154-
155-
await MainActor.run { [weak store] in
156-
store?.showsSampleProjectModal = false
172+
do {
173+
try await importStitchSampleProject(sampleProjectURL: data.url,
174+
store: store)
175+
176+
await MainActor.run { [weak store] in
177+
store?.showsSampleProjectModal = false
178+
}
179+
} catch {
180+
store.displayError(error: .customError("Sample project could not load, please check your internet connection and try again."))
157181
}
158182
}
159183
}

0 commit comments

Comments
 (0)