Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
chore: show unit in dropdown, update indicator to current component b…
Browse files Browse the repository at this point in the history
…lock (#1809)
  • Loading branch information
Muhammad Umer authored Oct 13, 2023
1 parent 6b82751 commit 1666b73
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
3 changes: 3 additions & 0 deletions Source/CourseContentHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ class CourseContentHeaderView: UIView {
if blocks.count > 1 {
button.isEnabled = true
dropDownImageView.isHidden = false
} else {
button.isEnabled = false
dropDownImageView.isHidden = true
}
}

Expand Down
37 changes: 14 additions & 23 deletions Source/NewCourseContentController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,8 @@ class NewCourseContentController: UIViewController, InterfaceOrientationOverridi
private var headerViewState: HeaderViewState = .expanded

private var currentBlock: CourseBlock? {
willSet {
currentBlock?.completion.unsubscribe(observer: self)
}

didSet {
updateView()
currentBlock?.completion.subscribe(observer: self) { [weak self] _,_ in
self?.updateView()
}
}
}

Expand Down Expand Up @@ -103,7 +96,7 @@ class NewCourseContentController: UIViewController, InterfaceOrientationOverridi
setStatusBar(color: environment.styles.primaryLightColor())
addSubViews()
setupComponentView()
setupCompletedBlocksView()
configureBlocks()
}

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -170,30 +163,27 @@ class NewCourseContentController: UIViewController, InterfaceOrientationOverridi
self.courseContentViewController = courseContentViewController
}

private func setupCompletedBlocksView() {
private func configureBlocks() {
guard let block = currentBlock,
let parent = courseQuerier.parentOfBlockWith(id: block.blockID).value,
let children = courseQuerier.childrenOfBlockWithID(blockID: parent.blockID, forMode: courseOutlineMode).value?.children,
let section = courseQuerier.parentOfBlockWith(id: block.blockID, type: .Section).firstSuccess().value,
let sectionChildren = courseQuerier.childrenOfBlockWithID(blockID: section.blockID, forMode: courseOutlineMode).value
else { return }

let childBlocks: [CourseBlock] = sectionChildren.children.compactMap { item in
courseQuerier.childrenOfBlockWithID(blockID: item.blockID, forMode: courseOutlineMode)
.firstSuccess().value?.children ?? []
}.flatMap { $0 }

let childViews: [UIView] = childBlocks.map { block -> UIView in
let childViews: [UIView] = children.map { childBlock -> UIView in
let view = UIView()
view.backgroundColor = block.isCompleted ? environment.styles.accentBColor() : environment.styles.neutralDark()
view.backgroundColor = block.blockID == childBlock.blockID ? environment.styles.accentBColor() : environment.styles.neutralDark()
return view
}

headerView.setBlocks(currentBlock: block, blocks: childBlocks)
headerView.setBlocks(currentBlock: parent, blocks: sectionChildren.children)
progressStackView.removeAllArrangedSubviews()
progressStackView.addArrangedSubviews(childViews)
}

private func findCourseBlockToShow() {
guard let childBlocks = courseQuerier.childrenOfBlockWithID(blockID: blockID, forMode: .full)
guard let childBlocks = courseQuerier.childrenOfBlockWithID(blockID: blockID, forMode: courseOutlineMode)
.firstSuccess().value?.children.compactMap({ $0 }).filter({ $0.type == .Unit })
else { return }

Expand All @@ -208,14 +198,14 @@ class NewCourseContentController: UIViewController, InterfaceOrientationOverridi

private func updateView() {
guard let block = currentBlock else { return }
configureBlocks()
updateTitle(block: block)
setupCompletedBlocksView()
}

private func updateTitle(block: CourseBlock) {
guard let parent = courseQuerier.parentOfBlockWith(id: block.blockID, type: .Section).firstSuccess().value
else { return }
headerView.update(title: parent.displayName, subtitle: block.displayName)
guard let currentBlock = courseQuerier.parentOfBlockWith(id: block.blockID).value,
let parent = courseQuerier.parentOfBlockWith(id: currentBlock.blockID).value else { return }
headerView.update(title: parent.displayName, subtitle: currentBlock.displayName)
}

override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
Expand Down Expand Up @@ -262,7 +252,8 @@ extension NewCourseContentController: CourseContentHeaderViewDelegate {
}

func didTapOnUnitBlock(block: CourseBlock) {
courseContentViewController?.moveToBlock(block: block)
guard let firstBlock = courseQuerier.blockWithID(id: block.children.first).value else { return }
courseContentViewController?.moveToBlock(block: firstBlock)
}
}

Expand Down

0 comments on commit 1666b73

Please sign in to comment.