-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Refactor login/tasks choice to be based on data available
- Loading branch information
Showing
7 changed files
with
103 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// ActivityIndicator.swift | ||
// RealmTaskTracker | ||
// | ||
// Created by Ben Chatelain on 11/9/20. | ||
// | ||
|
||
import SwiftUI | ||
|
||
// MARK: UIActivityIndicatorView Wrapper | ||
|
||
/// Simple activity indicator to telegraph that the app is active in the background. | ||
struct ActivityIndicator: UIViewRepresentable { | ||
func makeUIView(context: Context) -> some UIView { | ||
return UIActivityIndicatorView(style: .large) | ||
} | ||
|
||
func updateUIView(_ uiView: UIViewType, context: Context) { | ||
(uiView as! UIActivityIndicatorView).startAnimating() | ||
} | ||
} | ||
|
||
struct ActivityIndicator_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ActivityIndicator() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// MainView.swift | ||
// RealmTaskTracker | ||
// | ||
// Created by Ben Chatelain on 11/9/20. | ||
// | ||
|
||
import SwiftUI | ||
|
||
// MARK: Main View | ||
/// The main screen that determines whether to present the LoginView or the TasksView for the one group in the realm. | ||
struct MainView: View { | ||
/// The state of this application. | ||
// @ObservedObject var state = AppState() | ||
@EnvironmentObject var state: AppState | ||
|
||
var body: some View { | ||
NavigationView { | ||
ZStack { | ||
// If a realm is open for a logged in user, show the TasksView, otherwise show the LoginView | ||
if let tasks = state.tasks { | ||
TasksView(tasks: tasks) | ||
.navigationBarTitle("Tasks") | ||
.disabled(state.shouldIndicateActivity) | ||
} else { | ||
LoginView() | ||
.navigationBarTitle("Login") | ||
} | ||
|
||
// If the app is doing work in the background, | ||
// overlay an ActivityIndicator | ||
if state.shouldIndicateActivity { | ||
ActivityIndicator() | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters