fix(training): 按后台权限控制培训中心入口
This commit is contained in:
@@ -100,13 +100,29 @@ final class AllFunctionsViewController: BaseViewController {
|
||||
self?.applyViewModel(animated: self?.hasAppliedInitialSnapshot == true)
|
||||
}
|
||||
}
|
||||
NotificationCenter.default.addObserver(
|
||||
self,
|
||||
selector: #selector(reloadFunctions),
|
||||
name: NotificationName.permissionItemsDidChange,
|
||||
object: AppStore.shared.permissions
|
||||
)
|
||||
NotificationCenter.default.addObserver(
|
||||
self,
|
||||
selector: #selector(reloadFunctions),
|
||||
name: NotificationName.accountDidSwitch,
|
||||
object: nil
|
||||
)
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
viewModel.loadFunctions()
|
||||
}
|
||||
|
||||
@objc private func reloadFunctions() {
|
||||
Task { @MainActor [weak self] in self?.viewModel.loadFunctions() }
|
||||
}
|
||||
|
||||
override func viewDidDisappear(_ animated: Bool) {
|
||||
super.viewDidDisappear(animated)
|
||||
if isMovingFromParent, viewModel.didCustomize {
|
||||
|
||||
@@ -107,10 +107,17 @@ final class ProfileViewController: BaseViewController {
|
||||
name: NotificationName.userProfileDidUpdate,
|
||||
object: nil
|
||||
)
|
||||
NotificationCenter.default.addObserver(
|
||||
self,
|
||||
selector: #selector(handlePermissionItemsDidChange),
|
||||
name: NotificationName.permissionItemsDidChange,
|
||||
object: AppStore.shared.permissions
|
||||
)
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
applyViewModel()
|
||||
let showLoading = !hasLoadedProfileOnce && !viewModel.hasCachedBasicInfo
|
||||
Task {
|
||||
await reloadProfile(showGlobalLoading: showLoading)
|
||||
@@ -204,7 +211,7 @@ final class ProfileViewController: BaseViewController {
|
||||
}
|
||||
|
||||
private func applyViewModel() {
|
||||
trainingRow.isHidden = AppStore.shared.session.accountType != .storeUser
|
||||
trainingRow.isHidden = !viewModel.showsTrainingEntry
|
||||
trainingRow.configure(value: "学习课程与答题", accessory: .chevron)
|
||||
nicknameField.text = viewModel.displayNickname
|
||||
uidLabel.text = "UID:\(viewModel.displayUID)"
|
||||
@@ -293,9 +300,14 @@ final class ProfileViewController: BaseViewController {
|
||||
}
|
||||
|
||||
@objc private func handleAccountDidSwitch() {
|
||||
applyViewModel()
|
||||
Task { await reloadProfile(showGlobalLoading: true) }
|
||||
}
|
||||
|
||||
@objc private func handlePermissionItemsDidChange() {
|
||||
Task { @MainActor [weak self] in self?.applyViewModel() }
|
||||
}
|
||||
|
||||
@objc private func handleProfileDidUpdate() {
|
||||
viewModel.applyLocalProfileUpdate()
|
||||
applyViewModel()
|
||||
|
||||
Reference in New Issue
Block a user