Skip to content

Commit

Permalink
fix broadcast form navigation on new round page
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jun 17, 2024
1 parent d518665 commit 25e9fd2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
22 changes: 11 additions & 11 deletions app/controllers/RelayRound.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@ final class RelayRound(

def form(tourId: RelayTourId) = Auth { ctx ?=> _ ?=>
NoLameOrBot:
WithTourAndRoundsCanUpdate(tourId): trs =>
WithNavigationCanUpdate(tourId): nav =>
Ok.page:
views.relay.form.round.create(env.relay.roundForm.create(trs), FormNavigation(trs, none))
views.relay.form.round
.create(env.relay.roundForm.create(nav.tourWithRounds), nav)
}

def create(tourId: RelayTourId) = AuthOrScopedBody(_.Study.Write) { ctx ?=> me ?=>
NoLameOrBot:
WithTourAndRoundsCanUpdate(tourId): trs =>
val tour = trs.tour
WithNavigationCanUpdate(tourId): nav =>
def whenRateLimited = negotiate(
Redirect(routes.RelayTour.show(tour.slug, tour.id)),
Redirect(routes.RelayTour.show(nav.tour.slug, nav.tour.id)),
rateLimited
)
bindForm(env.relay.roundForm.create(trs))(
bindForm(env.relay.roundForm.create(nav.tourWithRounds))(
err =>
negotiate(
BadRequest.page(views.relay.form.round.create(err, FormNavigation(trs, none))),
BadRequest.page(views.relay.form.round.create(err, nav)),
jsonFormError(err)
),
setup =>
rateLimitCreation(whenRateLimited):
env.relay.api
.create(setup, tour)
.create(setup, nav.tour)
.flatMap: rt =>
negotiate(
Redirect(routes.RelayRound.edit(rt.relay.id)).flashSuccess,
Expand Down Expand Up @@ -187,14 +187,14 @@ final class RelayRound(
)(using Context): Fu[Result] =
Found(env.relay.api.tourById(id))(f)

private def WithTourAndRoundsCanUpdate(id: RelayTourId)(
f: TourModel.WithRounds => Fu[Result]
private def WithNavigationCanUpdate(id: RelayTourId)(
f: FormNavigation => Fu[Result]
)(using ctx: Context): Fu[Result] =
WithTour(id): tour =>
ctx.me
.soUse { env.relay.api.canUpdate(tour) }
.elseNotFound:
env.relay.api.withRounds(tour).flatMap(f)
env.relay.api.formNavigation(tour).flatMap(f)

private def doShow(rt: RoundModel.WithTour, oldSc: lila.study.Study.WithChapter, embed: Option[UserStr])(
using ctx: Context
Expand Down
6 changes: 3 additions & 3 deletions modules/relay/src/main/RelayApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ final class RelayApi(
if study.canContribute(me) || Granter(_.StudyAdmin) =>
relay.withTour(tour)

def formNavigation(id: RelayRoundId)(using me: Me): Fu[Option[(RelayRound, ui.FormNavigation)]] =
def formNavigation(id: RelayRoundId): Fu[Option[(RelayRound, ui.FormNavigation)]] =
byIdWithTour(id).flatMapz(rt => formNavigation(rt).dmap(some))

def formNavigation(rt: RelayRound.WithTour)(using me: Me): Fu[(RelayRound, ui.FormNavigation)] =
def formNavigation(rt: RelayRound.WithTour): Fu[(RelayRound, ui.FormNavigation)] =
formNavigation(rt.tour).map: nav =>
(rt.round, nav.copy(round = rt.round.id.some))

def formNavigation(tour: RelayTour)(using me: Me): Fu[ui.FormNavigation] = for
def formNavigation(tour: RelayTour): Fu[ui.FormNavigation] = for
group <- withTours.get(tour.id)
rounds <- roundRepo.byTourOrdered(tour.id)
yield ui.FormNavigation(group, tour, rounds, none)
Expand Down
7 changes: 2 additions & 5 deletions modules/relay/src/main/ui/FormUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ case class FormNavigation(
round: Option[RelayRoundId],
newRound: Boolean = false
):
def tourWithGroup = RelayTour.WithGroupTours(tour, group)

object FormNavigation:
def apply(trs: RelayTour.WithRounds, roundId: Option[RelayRoundId]): FormNavigation =
FormNavigation(none, trs.tour, trs.rounds, roundId)
def tourWithGroup = RelayTour.WithGroupTours(tour, group)
def tourWithRounds = RelayTour.WithRounds(tour, rounds)

final class FormUi(helpers: Helpers, ui: RelayUi, tourUi: RelayTourUi):
import helpers.{ *, given }
Expand Down

0 comments on commit 25e9fd2

Please sign in to comment.