forked from openedx/openedx-app-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Enrolled Web Based Programs Implementation (openedx#260)
* feat: enrolled programs feature implimentation * refactor: config refactoring * refactor: using configureable URIScheme * refactor: address review feedback * refactor: address review feedback * fix: fix failure after merge * refactor: remove extra space
- Loading branch information
1 parent
02fcec9
commit a03bb3e
Showing
13 changed files
with
453 additions
and
38 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
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
108 changes: 108 additions & 0 deletions
108
Discovery/Discovery/Presentation/WebPrograms/ProgramWebviewView.swift
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,108 @@ | ||
// | ||
// ProgramWebviewView.swift | ||
// Discovery | ||
// | ||
// Created by SaeedBashir on 1/23/24. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
import Theme | ||
import Core | ||
|
||
public enum ProgramViewType: Equatable { | ||
case program | ||
case programDetail | ||
} | ||
|
||
public struct ProgramWebviewView: View { | ||
@State private var isLoading: Bool = true | ||
|
||
@ObservedObject private var viewModel: ProgramWebviewViewModel | ||
private var router: DiscoveryRouter | ||
private var viewType: ProgramViewType | ||
private var pathID: String | ||
|
||
private var URLString: String { | ||
switch viewType { | ||
case .program: | ||
return viewModel.config.program.webview.baseURL ?? "" | ||
case .programDetail: | ||
let template = viewModel.config.program.webview.programDetailTemplate | ||
return template?.replacingOccurrences( | ||
of: URIString.pathPlaceHolder.rawValue, | ||
with: pathID | ||
) ?? "" | ||
} | ||
} | ||
|
||
public init( | ||
viewModel: ProgramWebviewViewModel, | ||
router: DiscoveryRouter, | ||
viewType: ProgramViewType = .program, | ||
pathID: String = "" | ||
) { | ||
self.viewModel = viewModel | ||
self.router = router | ||
self.viewType = viewType | ||
self.pathID = pathID | ||
|
||
if let url = URL(string: URLString) { | ||
viewModel.request = URLRequest(url: url) | ||
} | ||
} | ||
|
||
public var body: some View { | ||
GeometryReader { proxy in | ||
VStack(alignment: .center) { | ||
WebView( | ||
viewModel: .init( | ||
url: URLString, | ||
baseURL: "" | ||
), | ||
isLoading: $isLoading, | ||
refreshCookies: {}, | ||
navigationDelegate: viewModel | ||
) | ||
|
||
if isLoading || viewModel.showProgress { | ||
HStack(alignment: .center) { | ||
ProgressBar( | ||
size: 40, | ||
lineWidth: 8 | ||
) | ||
.padding(.vertical, proxy.size.height / 2) | ||
} | ||
.frame(width: proxy.size.width, height: proxy.size.height) | ||
} | ||
|
||
// MARK: - Show Error | ||
if viewModel.showError { | ||
VStack { | ||
SnackBarView(message: viewModel.errorMessage) | ||
} | ||
.padding(.bottom, 20) | ||
.transition(.move(edge: .bottom)) | ||
.onAppear { | ||
doAfter(Theme.Timeout.snackbarMessageLongTimeout) { | ||
viewModel.errorMessage = nil | ||
} | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Offline mode SnackBar | ||
OfflineSnackBarView( | ||
connectivity: viewModel.connectivity, | ||
reloadAction: { | ||
NotificationCenter.default.post( | ||
name: .webviewReloadNotification, | ||
object: nil | ||
) | ||
}) | ||
} | ||
.navigationBarHidden(viewType == .program) | ||
.navigationTitle(CoreLocalization.Mainscreen.programs) | ||
.background(Theme.Colors.background.ignoresSafeArea()) | ||
} | ||
} |
Oops, something went wrong.