Skip to content

Commit 13a6dfd

Browse files
committed
Merge branch 'development' into main
2 parents 87ee845 + 98d0b78 commit 13a6dfd

6 files changed

Lines changed: 64 additions & 8 deletions

File tree

iOSSC.xcodeproj/project.pbxproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
136BCFDB2539D64300C77D96 /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = 136BCFDA2539D64300C77D96 /* Alamofire */; };
2424
136BCFE42539DAB900C77D96 /* APIResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 136BCFE32539DAB900C77D96 /* APIResponse.swift */; };
2525
13709B57253C381000C422B8 /* SFSafeSymbols in Frameworks */ = {isa = PBXBuildFile; productRef = 13709B56253C381000C422B8 /* SFSafeSymbols */; };
26+
1373EE6B253CACD20088AB0F /* SwiftUIRefresh in Frameworks */ = {isa = PBXBuildFile; productRef = 1373EE6A253CACD20088AB0F /* SwiftUIRefresh */; };
2627
138E845A253AF7C800B1B8AD /* BackgroundView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 138E8459253AF7C800B1B8AD /* BackgroundView.swift */; };
2728
138E845D253AF7F000B1B8AD /* GradeMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 138E845C253AF7F000B1B8AD /* GradeMode.swift */; };
2829
138E8461253AFD1500B1B8AD /* HSDSans.otf in Resources */ = {isa = PBXBuildFile; fileRef = 138E8460253AFD1500B1B8AD /* HSDSans.otf */; };
@@ -65,6 +66,7 @@
6566
isa = PBXFrameworksBuildPhase;
6667
buildActionMask = 2147483647;
6768
files = (
69+
1373EE6B253CACD20088AB0F /* SwiftUIRefresh in Frameworks */,
6870
13EB1D2C253B6C57007D79D8 /* Haptica in Frameworks */,
6971
138E846A253B04E600B1B8AD /* KeychainAccess in Frameworks */,
7072
13709B57253C381000C422B8 /* SFSafeSymbols in Frameworks */,
@@ -197,6 +199,7 @@
197199
138E8469253B04E600B1B8AD /* KeychainAccess */,
198200
13EB1D2B253B6C57007D79D8 /* Haptica */,
199201
13709B56253C381000C422B8 /* SFSafeSymbols */,
202+
1373EE6A253CACD20088AB0F /* SwiftUIRefresh */,
200203
);
201204
productName = iOSSC;
202205
productReference = 132160A92539BE74003D3489 /* iOSSC.app */;
@@ -230,6 +233,7 @@
230233
138E8468253B04E600B1B8AD /* XCRemoteSwiftPackageReference "KeychainAccess" */,
231234
13EB1D2A253B6C57007D79D8 /* XCRemoteSwiftPackageReference "Haptica" */,
232235
13709B55253C381000C422B8 /* XCRemoteSwiftPackageReference "SFSafeSymbols" */,
236+
1373EE69253CACD20088AB0F /* XCRemoteSwiftPackageReference "SwiftUIRefresh" */,
233237
);
234238
productRefGroup = 132160AA2539BE74003D3489 /* Products */;
235239
projectDirPath = "";
@@ -484,6 +488,14 @@
484488
minimumVersion = 1.2.0;
485489
};
486490
};
491+
1373EE69253CACD20088AB0F /* XCRemoteSwiftPackageReference "SwiftUIRefresh" */ = {
492+
isa = XCRemoteSwiftPackageReference;
493+
repositoryURL = "https://github.com/timbersoftware/SwiftUIRefresh.git";
494+
requirement = {
495+
kind = upToNextMajorVersion;
496+
minimumVersion = 0.0.3;
497+
};
498+
};
487499
138E8468253B04E600B1B8AD /* XCRemoteSwiftPackageReference "KeychainAccess" */ = {
488500
isa = XCRemoteSwiftPackageReference;
489501
repositoryURL = "https://github.com/kishikawakatsumi/KeychainAccess";
@@ -513,6 +525,11 @@
513525
package = 13709B55253C381000C422B8 /* XCRemoteSwiftPackageReference "SFSafeSymbols" */;
514526
productName = SFSafeSymbols;
515527
};
528+
1373EE6A253CACD20088AB0F /* SwiftUIRefresh */ = {
529+
isa = XCSwiftPackageProductDependency;
530+
package = 1373EE69253CACD20088AB0F /* XCRemoteSwiftPackageReference "SwiftUIRefresh" */;
531+
productName = SwiftUIRefresh;
532+
};
516533
138E8469253B04E600B1B8AD /* KeychainAccess */ = {
517534
isa = XCSwiftPackageProductDependency;
518535
package = 138E8468253B04E600B1B8AD /* XCRemoteSwiftPackageReference "KeychainAccess" */;

iOSSC.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

iOSSC/Model/APIManager.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ class APIManager: ObservableObject {
6262
return loginState == .loggingIn
6363
}
6464

65+
var isRefreshing: Bool {
66+
return loginState == .refreshing
67+
}
68+
6569
func login(_ username: String?, _ password: String?) {
6670
guard let username = username, let password = password else {
6771
return
@@ -117,14 +121,20 @@ class APIManager: ObservableObject {
117121
}
118122
}
119123

124+
func refresh(completion: (() -> Void)? = nil) {
125+
loginState = .refreshing
126+
fetchModules(completion: { completion?() })
127+
}
128+
120129
/**
121130
Fetches all available data for the provided username and password
122131
GET https://api.kuhlti.me/ossc/modules
123132
*/
124-
private func fetchModules() {
133+
private func fetchModules(completion: (() -> Void)? = nil) {
125134
guard let username = username, let password = password else {
126135
loginState = .error
127136
print("Can't fetch without username and password")
137+
completion?()
128138
return
129139
}
130140

@@ -134,6 +144,7 @@ class APIManager: ObservableObject {
134144
print(error.localizedDescription)
135145
self.logout()
136146
self.loginState = .error
147+
completion?()
137148
return
138149
}
139150

@@ -142,17 +153,22 @@ class APIManager: ObservableObject {
142153
case .success:
143154
guard let data = apiResponse.data else {
144155
print("No data in APIResponse")
156+
completion?()
145157
return
146158
}
147159

148160
print("Recieved Data")
149161
self.data = data
150162
self.loginState = .loggedIn
151163

164+
completion?()
165+
152166
case .failed:
153167
print("API error with message: \(apiResponse.message ?? "NO MESSAGE PROVIDED")")
154168
self.logout()
155169
self.loginState = .error
170+
171+
completion?()
156172
}
157173
}
158174
}
@@ -182,6 +198,6 @@ class APIManager: ObservableObject {
182198
}
183199

184200
enum LoginState {
185-
case loggedOut, loggingIn, loggedIn, error
201+
case loggedOut, loggingIn, loggedIn, error, refreshing
186202
}
187203
}

iOSSC/View/ContentView.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
import SwiftUI
99
import Haptica
10+
import SwiftUIRefresh
1011

1112
struct ContentView: View {
1213
@EnvironmentObject var manager: APIManager
13-
1414
@State private var mode: GradeMode = .colorEmoji
15+
@State private var pullToRefreshShowing = false
1516

1617
init() {
1718
UITableView.appearance().backgroundColor = .clear
18-
// UITableView.appearance().separatorStyle = .none
1919
UITableViewCell.appearance().backgroundColor = .clear
2020
UINavigationBar.appearance().backgroundColor = .clear
2121
}
@@ -31,7 +31,12 @@ struct ContentView: View {
3131
.background(
3232
BackgroundView()
3333
)
34-
.navigationBarItems(leading: summaryLabel, trailing: logoutButton)
34+
.navigationBarItems(leading: summaryLabel, trailing: HStack { logoutButton })
35+
.pullToRefresh(isShowing: $pullToRefreshShowing) {
36+
manager.refresh {
37+
pullToRefreshShowing = false
38+
}
39+
}
3540
}
3641
}
3742

iOSSC/View/LoadingScreen.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ struct LoadingScreen: View {
1818
ProgressView().padding()
1919
HStack {
2020
Image(systemSymbol: .boltHorizontalCircleFill)
21-
Text("Server spooling up.")
21+
Text("Server is spooling up.")
2222
.multilineTextAlignment(.center)
2323
}
2424
.opacity(showText ? 1 : 0)
2525
}
2626
.foregroundColor(.white)
2727
}
2828
.onAppear {
29-
withAnimation(Animation.easeIn(duration: 1).delay(2)) {
29+
withAnimation(Animation.easeIn(duration: 1).delay(3)) {
3030
showText = true
3131
}
3232
}

iOSSC/iOSSCApp.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct iOSSCApp: App {
1313

1414
var body: some Scene {
1515
WindowGroup {
16-
if (manager.isLoggedIn) {
16+
if (manager.isLoggedIn || manager.isRefreshing) {
1717
ContentView().environmentObject(manager)
1818
} else if (manager.isLoggingIn) {
1919
LoadingScreen()

0 commit comments

Comments
 (0)