Skip to content

Commit

Permalink
♻️ (NewGek): Remove GridSize enum from UIModel
Browse files Browse the repository at this point in the history
  • Loading branch information
HPezz authored and ladislas committed Dec 17, 2024
1 parent f56ffa0 commit 3e052f1
Showing 1 changed file with 39 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,83 +9,51 @@ import SwiftUI
// MARK: - DnDGridViewUIChoicesWrapper

public struct DnDGridUIModel {
// MARK: Internal

static let zero = DnDGridUIModel(action: nil, choices: [])

var action: Exercise.Action?
var choices: [DnDAnswerNode]

func choiceSize(for choiceNumber: Int) -> CGSize {
DnDGridSize(choiceNumber).choiceSize(for: self.action)
}

// MARK: Private

// swiftlint:disable identifier_name cyclomatic_complexity

private enum DnDGridSize: Int {
case one = 1
case two
case three
case four
case five
case six
case none

// MARK: Lifecycle

init(_ rawValue: Int) {
self = DnDGridSize(rawValue: rawValue) ?? .none
}

// MARK: Internal

func choiceSize(for action: Exercise.Action?) -> CGSize {
switch action {
case .ipad(type: .image),
.ipad(type: .sfsymbol):
switch self {
case .one,
.two,
.three,
.four:
CGSize(width: 180, height: 180)
case .five,
.six,
.none:
CGSize(width: 150, height: 150)
}
case .none:
switch self {
case .one,
.two:
CGSize(width: 300, height: 300)
case .three,
.four:
CGSize(width: 240, height: 240)
case .five,
.six,
.none:
CGSize(width: 200, height: 200)
}
default:
switch self {
case .one,
.two:
CGSize(width: 220, height: 220)
case .three,
.four:
CGSize(width: 200, height: 200)
case .five:
CGSize(width: 160, height: 160)
case .six,
.none:
CGSize(width: 150, height: 150)
}
}
// swiftlint:disable cyclomatic_complexity

func choiceSize(for numberOfChoices: Int) -> CGSize {
switch self.action {
case .ipad(type: .image),
.ipad(type: .sfsymbol):
switch numberOfChoices {
case 1...4:
CGSize(width: 180, height: 180)
case 5...6:
CGSize(width: 150, height: 150)
default:
CGSize(width: 150, height: 150)
}
case .none:
switch numberOfChoices {
case 1...2:
CGSize(width: 300, height: 300)
case 3...4:
CGSize(width: 240, height: 240)
case 5...6:
CGSize(width: 200, height: 200)
default:
CGSize(width: 200, height: 200)
}
default:
switch numberOfChoices {
case 1...2:
CGSize(width: 220, height: 220)
case 3...4:
CGSize(width: 200, height: 200)
case 5:
CGSize(width: 160, height: 160)
case 6:
CGSize(width: 150, height: 150)
default:
CGSize(width: 150, height: 150)
}
}
}

// swiftlint:enable identifier_name cyclomatic_complexity
// swiftlint:enable cyclomatic_complexity
}

0 comments on commit 3e052f1

Please sign in to comment.