Skip to content

Commit

Permalink
Merge pull request #728 from hyperskill/feature/fill_blanks_select
Browse files Browse the repository at this point in the history
Fill in the blanks with selects
  • Loading branch information
ivan-magda authored Oct 30, 2023
2 parents 3ecd5c1 + 698e993 commit 23cebfa
Show file tree
Hide file tree
Showing 45 changed files with 1,863 additions and 151 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup-ios/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ runs:
- name: Setup Xcode version
uses: maxim-lobanov/setup-xcode@v1.6.0
with:
xcode-version: '15.0.0'
xcode-version: '15.0.1'

- name: Homebrew install git-crypt
run: brew install git-crypt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.hyperskill.app.android.step_quiz_fill_blanks.dialog.FillBlanksInputDi
import org.hyperskill.app.step_quiz.domain.model.submissions.Reply
import org.hyperskill.app.step_quiz.presentation.StepQuizFeature
import org.hyperskill.app.step_quiz_fill_blanks.model.FillBlanksItem
import org.hyperskill.app.step_quiz_fill_blanks.model.FillBlanksMode
import org.hyperskill.app.step_quiz_fill_blanks.model.InvalidFillBlanksConfigException
import org.hyperskill.app.step_quiz_fill_blanks.presentation.FillBlanksItemMapper
import org.hyperskill.app.step_quiz_fill_blanks.presentation.FillBlanksResolver
Expand All @@ -37,7 +38,8 @@ class FillBlanksStepQuizFormDelegate(
)
}

private val fillBlanksMapper: FillBlanksItemMapper = FillBlanksItemMapper()
// TODO: ALTAPPS-1021 provide corresponding mode
private val fillBlanksMapper: FillBlanksItemMapper = FillBlanksItemMapper(mode = FillBlanksMode.INPUT)

private var resolveState: ResolveState = ResolveState.NOT_RESOLVED

Expand Down Expand Up @@ -79,8 +81,11 @@ class FillBlanksStepQuizFormDelegate(
val dataset = state.attempt.dataset
if (dataset != null) {
try {
FillBlanksResolver.resolve(dataset)
ResolveState.RESOLVE_SUCCEED
// TODO: ALTAPPS-1021 handle resolve state
when (FillBlanksResolver.resolve(dataset)) {
FillBlanksMode.INPUT -> ResolveState.RESOLVE_SUCCEED
FillBlanksMode.SELECT -> ResolveState.RESOLVE_FAILED
}
} catch (e: InvalidFillBlanksConfigException) {
ResolveState.RESOLVE_FAILED
}
Expand All @@ -97,6 +102,10 @@ class FillBlanksStepQuizFormDelegate(
when (item) {
is FillBlanksItem.Input -> item.inputText
is FillBlanksItem.Text -> null
is FillBlanksItem.Select -> {
// TODO: ALTAPPS-1021 provide reply blanks for select mode
null
}
}
}
)
Expand Down
122 changes: 117 additions & 5 deletions iosHyperskillApp/iosHyperskillApp.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import shared

private final class AppGraph: IosAppComponentImpl {
override func getIosFCMTokenProvider() -> IosFCMTokenProvider {
IosFCMTokenProviderImpl()
IosFCMTokenProviderImpl.shared
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Foundation
import shared

final class IosFCMTokenProviderImpl: IosFCMTokenProvider {
static let shared = IosFCMTokenProviderImpl()

func getFCMToken() async throws -> String? {
guard Messaging.messaging().apnsToken != nil else {
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ enum StepQuizChildQuizViewFactory {
moduleOutput: moduleOutput
)
.makeModule()
case .fillBlanks:
case .fillBlanks(let mode):
StepQuizFillBlanksAssembly(
mode: mode.require(),
step: step,
dataset: dataset,
reply: reply,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ enum StepQuizChildQuizType {
case number
case math
case parsons
case fillBlanks
case fillBlanks(mode: FillBlanksModeWrapper?)
case unsupported(blockName: String)

var isCodeRelated: Bool {
Expand All @@ -25,7 +25,13 @@ enum StepQuizChildQuizType {
}
}

init(step: Step) {
static func resolve(step: Step, datasetOrNil: Dataset?) -> StepQuizChildQuizType {
StepQuizChildQuizType(step: step, datasetOrNil: datasetOrNil)
}

private init(step: Step, datasetOrNil: Dataset?) {
let unsupportedQuizType = StepQuizChildQuizType.unsupported(blockName: step.block.name)

if StepQuizResolver.shared.isQuizSupportable(step: step) {
switch step.block.name {
case BlockName.shared.CHOICE:
Expand All @@ -51,12 +57,31 @@ enum StepQuizChildQuizType {
case BlockName.shared.PARSONS:
self = .parsons
case BlockName.shared.FILL_BLANKS:
self = .fillBlanks
guard let dataset = datasetOrNil else {
self = .fillBlanks(mode: nil)
return
}

do {
let sharedMode = try FillBlanksResolver.shared.resolve(dataset: dataset)

switch FillBlanksModeWrapper(shared: sharedMode) {
case .input:
self = .fillBlanks(mode: .input)
case .select:
self = .fillBlanks(mode: .select)
default:
self = unsupportedQuizType
}
} catch {
assertionFailure("FillBlanksResolver: failed to resolve fill blanks with error = \(error)")
self = unsupportedQuizType
}
default:
self = .unsupported(blockName: step.block.name)
self = unsupportedQuizType
}
} else {
self = .unsupported(blockName: step.block.name)
self = unsupportedQuizType
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ final class StepQuizViewModel: FeatureViewModel<
private let stepQuizViewDataMapper: StepQuizViewDataMapper
var stepQuizStateKs: StepQuizFeatureStepQuizStateKs { .init(state.stepQuizState) }

weak var fillBlanksSelectOptionsModuleInput: StepQuizFillBlanksSelectOptionsInputProtocol?

@Published var isPracticingLoading = false

init(
Expand Down Expand Up @@ -142,7 +144,7 @@ final class StepQuizViewModel: FeatureViewModel<
}
}

// MARK: - StepQuizViewModel: StepQuizChildQuizDelegate -
// MARK: - StepQuizViewModel: StepQuizChildQuizOutputProtocol -

extension StepQuizViewModel: StepQuizChildQuizOutputProtocol {
func handleChildQuizSync(reply: Reply) {
Expand All @@ -162,6 +164,26 @@ extension StepQuizViewModel: StepQuizChildQuizOutputProtocol {
}
}

// MARK: - StepQuizViewModel: StepQuizFillBlanksOutputProtocol -

extension StepQuizViewModel: StepQuizFillBlanksOutputProtocol {
func handleStepQuizFillBlanksCurrentSelectModeState(
options: [StepQuizFillBlankOption],
selectedIndices: Set<Int>,
blanksCount: Int
) {
guard let fillBlanksSelectOptionsModuleInput else {
return assertionFailure("StepQuizViewModel: fillBlanksSelectOptionsModuleInput is nil")
}

fillBlanksSelectOptionsModuleInput.update(
options: options,
selectedIndices: selectedIndices,
blanksCount: blanksCount
)
}
}

// MARK: - StepQuizViewModel: StepQuizInputProtocol -

extension StepQuizViewModel: StepQuizInputProtocol {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,7 @@ final class StepQuizViewDataMapper {
}

func mapStepDataToViewData(step: Step, state: StepQuizFeatureStepQuizStateKs) -> StepQuizViewData {
let attemptLoadedState: StepQuizFeatureStepQuizStateAttemptLoaded? = {
switch state {
case .attemptLoading(let attemptLoadingState):
return attemptLoadingState.oldState
case .attemptLoaded(let attemptLoadedState):
return attemptLoadedState
default:
return nil
}
}()
let attemptLoadedState = StepQuizStateExtentionsKt.attemptLoadedState(state.sealed)

let quizType = resolveQuizType(
step: step,
Expand Down Expand Up @@ -96,29 +87,13 @@ final class StepQuizViewDataMapper {
state: StepQuizFeatureStepQuizStateKs,
attemptLoadedState: StepQuizFeatureStepQuizStateAttemptLoaded?
) -> StepQuizChildQuizType {
let unsupportedChildQuizType = StepQuizChildQuizType.unsupported(blockName: step.block.name)

if state == .unsupported {
return unsupportedChildQuizType
return .unsupported(blockName: step.block.name)
}

let childQuizType = StepQuizChildQuizType(step: step)

if case .fillBlanks = childQuizType {
guard let dataset = attemptLoadedState?.attempt.dataset else {
return childQuizType
}

do {
try FillBlanksResolver.shared.resolve(dataset: dataset)
} catch {
#if DEBUG
print("StepQuizViewDataMapper: failed to resolve fill blanks quiz type, error = \(error)")
#endif
return unsupportedChildQuizType
}
}

return childQuizType
return StepQuizChildQuizType.resolve(
step: step,
datasetOrNil: attemptLoadedState?.attempt.dataset
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ enum StepQuizSkeletonViewFactory {
case .parsons:
StepQuizParsonsSkeletonView()
case .fillBlanks:
#warning("TODO: FillBlanks skeleton view")
StepQuizParsonsSkeletonView()
StepQuizFillBlanksSkeletonView()
case .unsupported:
SkeletonRoundedView()
.frame(height: 100)
Expand Down
Loading

0 comments on commit 23cebfa

Please sign in to comment.