Skip to content

Commit

Permalink
Added: Series - Day of Week
Browse files Browse the repository at this point in the history
  • Loading branch information
JPKribs committed Nov 4, 2024
1 parent 7af4b22 commit db51dff
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 35 deletions.
2 changes: 0 additions & 2 deletions Shared/ViewModels/ParentalRatingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ final class ParentalRatingsViewModel: ViewModel, Stateful {
@Published
private(set) var parentalRatings: [ParentalRating] = []

@Published
final var lastAction: Action? = nil
@Published
final var state: State = .initial

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ extension MetadataTextEditorView {
}))

if item.lockData != true {
Divider()
ForEach(MetadataField.allCases, id: \.self) { field in
Toggle(field.rawValue, isOn: Binding(
get: { item.lockedFields?.contains(field) ?? false },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,40 +43,77 @@ extension MetadataTextEditorView {
}

Section(L10n.episodes) {
DatePicker(
"Air Time",
selection: Binding<Date>(
get: { parseAirTimeToDate(item.airTime) },
set: { date in
item.airTime = formatDateToString(date)
}
),
displayedComponents: .hourAndMinute
)
ChevronAlertButton(
"Run Time",
subtitle: ServerTicks(item.runTimeTicks ?? 0)
.seconds.formatted(.hourMinute),
description: "Episode runtime in minutes"
) {
TextField(
"Minutes",
value: $tempRunTime,
format: .number
)
.keyboardType(.numberPad)
} onSave: {
if let tempRunTime = tempRunTime, tempRunTime != 0 {
item.runTimeTicks = ServerTicks(minutes: tempRunTime).ticks
} else {
item.runTimeTicks = nil
airTimeView

runTimeView
}

Section(L10n.dayOfWeek) {
airDaysView
}
}

// MARK: - Air Time View

@ViewBuilder
private var airTimeView: some View {
DatePicker(
"Air Time",
selection: Binding<Date>(
get: { parseAirTimeToDate(item.airTime) },
set: { date in
item.airTime = formatDateToString(date)
}
} onCancel: {
if let originalRunTime = item.runTimeTicks {
tempRunTime = Int(ServerTicks(originalRunTime).minutes)
} else {
tempRunTime = nil
),
displayedComponents: .hourAndMinute
)
}

// MARK: - Air Days View

@ViewBuilder
private var airDaysView: some View {
ForEach(DayOfWeek.allCases, id: \.self) { field in
Toggle(field.displayTitle ?? L10n.unknown, isOn: Binding(
get: { item.airDays?.contains(field) ?? false },
set: { isSelected in
if isSelected {
item.airDays?.append(field)
} else {
item.airDays?.removeAll { $0 == field }
}
}
))
}
}

// MARK: - Run Time View

@ViewBuilder
private var runTimeView: some View {
ChevronAlertButton(
"Run Time",
subtitle: ServerTicks(item.runTimeTicks ?? 0)
.seconds.formatted(.hourMinute),
description: "Episode runtime in minutes"
) {
TextField(
L10n.minutes,
value: $tempRunTime,
format: .number
)
.keyboardType(.numberPad)
} onSave: {
if let tempRunTime = tempRunTime, tempRunTime != 0 {
item.runTimeTicks = ServerTicks(minutes: tempRunTime).ticks
} else {
item.runTimeTicks = nil
}
} onCancel: {
if let originalRunTime = item.runTimeTicks {
tempRunTime = Int(ServerTicks(originalRunTime).minutes)
} else {
tempRunTime = nil
}
}
}
Expand Down

0 comments on commit db51dff

Please sign in to comment.