Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix focus in tutorial #3072

Merged
merged 8 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,10 @@ struct SyncUpFormView: View {
.focused($focus, equals: .attendee(attendee.id))
}
.onDelete { indices in
guard let firstDeletedIndex = indices.first
else { return }
let firstDeletedAttendee = store.syncUp.attendees[firstDeletedIndex]
store.send(.onDeleteAttendees(indices))
guard focus == .attendee(firstDeletedAttendee.id)
else { return }
let index = min(firstDeletedIndex, store.syncUp.attendees.count - 1)
guard let firstIndex = indices.first
else { return .none }
let index = min(firstIndex, store.syncUp.attendees.count - 1)
focus = .attendee(store.syncUp.attendees[index].id)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,10 @@ struct SyncUpFormView: View {
.focused($focus, equals: .attendee(attendee.id))
}
.onDelete { indices in
guard let firstDeletedIndex = indices.first
else { return }
let firstDeletedAttendee = store.syncUp.attendees[firstDeletedIndex]
store.send(.onDeleteAttendees(indices))
guard focus == .attendee(firstDeletedAttendee.id)
else { return }
let index = min(firstDeletedIndex, store.syncUp.attendees.count - 1)
guard let firstIndex = indices.first
else { return .none }
let index = min(firstIndex, store.syncUp.attendees.count - 1)
focus = .attendee(store.syncUp.attendees[index].id)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,12 @@ struct SyncUpForm {
case .binding:
return .none

case let .onDeleteAttendees(indexSet):
guard let firstDeletedIndex = indexSet.first
case let .onDeleteAttendees(indices):
mbrandonw marked this conversation as resolved.
Show resolved Hide resolved
state.syncUp.attendees.remove(atOffsets: indices)
guard let firstIndex = indices.first
else { return .none }
let firstDeletedAttendee = state.syncUp.attendees[firstDeletedIndex]

state.syncUp.attendees.remove(atOffsets: indexSet)
if state.syncUp.attendees.isEmpty {
state.syncUp.attendees.append(
Attendee(id: Attendee.ID())
)
}

guard state.focus == .attendee(firstDeletedAttendee.id)
else { return .none }
let index = min(firstDeletedIndex, state.syncUp.attendees.count - 1)
let index = min(firstIndex, state.syncUp.attendees.count - 1)
state.focus = .attendee(state.syncUp.attendees[index].id)

return .none
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,10 @@ struct SyncUpFormView: View {
.focused($focus, equals: .attendee(attendee.id))
}
.onDelete { indices in
guard let firstDeletedIndex = indices.first
else { return }
let firstDeletedAttendee = store.syncUp.attendees[firstDeletedIndex]
store.send(.onDeleteAttendees(indices))
guard focus == .attendee(firstDeletedAttendee.id)
else { return }
let index = min(firstDeletedIndex, store.syncUp.attendees.count - 1)
guard let firstIndex = indices.first
else { return .none }
let index = min(firstIndex, store.syncUp.attendees.count - 1)
focus = .attendee(store.syncUp.attendees[index].id)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ struct SyncUpFormView: View {
.focused($focus, equals: .attendee(attendee.id))
}
.onDelete { indices in
// guard let firstDeletedIndex = indices.first
// else { return }
// let firstDeletedAttendee = store.syncUp.attendees[firstDeletedIndex]
store.send(.onDeleteAttendees(indices))
// guard focus == .attendee(firstDeletedAttendee.id)
// else { return }
// let index = min(firstDeletedIndex, store.syncUp.attendees.count - 1)
// store.send(.onDeleteAttendees(indices))
// guard let firstIndex = indices.first
// else { return .none }
// let index = min(firstIndex, store.syncUp.attendees.count - 1)
// focus = .attendee(store.syncUp.attendees[index].id)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,12 @@ struct SyncUpForm {
case .binding:
return .none

case let .onDeleteAttendees(indexSet):
guard let firstDeletedIndex = indexSet.first
case let .onDeleteAttendees(indices):
state.syncUp.attendees.remove(atOffsets: indices)
guard let firstIndex = indices.first
else { return .none }
let firstDeletedAttendee = state.syncUp.attendees[firstDeletedIndex]

state.syncUp.attendees.remove(atOffsets: indexSet)
if state.syncUp.attendees.isEmpty {
state.syncUp.attendees.append(
Attendee(id: Attendee.ID())
)
}

guard state.focus == .attendee(firstDeletedAttendee.id)
else { return .none }
let index = min(firstDeletedIndex, state.syncUp.attendees.count - 1)
let index = min(firstIndex, state.syncUp.attendees.count - 1)
state.focus = .attendee(state.syncUp.attendees[index].id)

return .none
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,12 @@ struct SyncUpForm {
case .binding:
return .none

case let .onDeleteAttendees(indexSet):
guard let firstDeletedIndex = indexSet.first
case let .onDeleteAttendees(indices):
state.syncUp.attendees.remove(atOffsets: indices)
guard let firstIndex = indices.first
else { return .none }
let firstDeletedAttendee = state.syncUp.attendees[firstDeletedIndex]

state.syncUp.attendees.remove(atOffsets: indexSet)
if state.syncUp.attendees.isEmpty {
state.syncUp.attendees.append(
Attendee(id: Attendee.ID())
)
}

guard state.focus == .attendee(firstDeletedAttendee.id)
else { return .none }
let index = min(firstDeletedIndex, state.syncUp.attendees.count - 1)
let index = min(firstIndex, state.syncUp.attendees.count - 1)
state.focus = .attendee(state.syncUp.attendees[index].id)

return .none
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,12 @@ struct SyncUpForm {
case .binding:
return .none

case let .onDeleteAttendees(indexSet):
guard let firstDeletedIndex = indexSet.first
case let .onDeleteAttendees(indices):
state.syncUp.attendees.remove(atOffsets: indices)
guard let firstIndex = indices.first
else { return .none }
let firstDeletedAttendee = state.syncUp.attendees[firstDeletedIndex]

state.syncUp.attendees.remove(atOffsets: indexSet)
if state.syncUp.attendees.isEmpty {
state.syncUp.attendees.append(
Attendee(id: uuid())
)
}

guard state.focus == .attendee(firstDeletedAttendee.id)
else { return .none }
let index = min(firstDeletedIndex, state.syncUp.attendees.count - 1)
let index = min(firstIndex, state.syncUp.attendees.count - 1)
state.focus = .attendee(state.syncUp.attendees[index].id)

return .none
}
}
Expand Down