Skip to content

Commit

Permalink
broadcast embed group selector
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Aug 2, 2024
1 parent 94255fb commit feef5e2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
21 changes: 15 additions & 6 deletions app/controllers/RelayTour.scala
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,23 @@ final class RelayTour(env: Env, apiC: => Api) extends LilaController(env):
.soUse(env.relay.api.canUpdate(tour))
.flatMap:
if _ then Redirect(routes.RelayRound.form(tour.id))
else
for
owner <- env.user.lightUser(tour.ownerId)
markup = tour.markup.map(env.relay.markup(tour))
page <- Ok.page(views.relay.tour.showEmpty(tour, owner, markup))
yield page
else emptyBroadcastPage(tour)
case Some(round) => Redirect(round.withTour(tour).path)

def embedShow(slug: String, id: RelayTourId) = Open:
Found(env.relay.api.tourById(id)): tour =>
env.relay.listing.defaultRoundToShow
.get(tour.id)
.flatMap:
_.fold(emptyBroadcastPage(tour)): round =>
Redirect(s"/embed${round.withTour(tour).path}")

private def emptyBroadcastPage(tour: TourModel)(using Context) = for
owner <- env.user.lightUser(tour.ownerId)
markup = tour.markup.map(env.relay.markup(tour))
page <- Ok.page(views.relay.tour.showEmpty(tour, owner, markup))
yield page

def apiShow(id: RelayTourId) = Open:
Found(env.relay.api.tourById(id)): tour =>
for
Expand Down
1 change: 1 addition & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ GET /api/broadcast/by/:user controllers.RelayTour.apiBy(user:
GET /broadcast/subscribed controllers.RelayTour.subscribed(page: Int ?= 1)
GET /broadcast/all-private controllers.RelayTour.allPrivate(page: Int ?= 1)
GET /broadcast/:ts/$id<\w{8}> controllers.RelayTour.show(ts, id: RelayTourId)
GET /embed/broadcast/:ts/$id<\w{8}> controllers.RelayTour.embedShow(ts, id: RelayTourId)
GET /api/broadcast/$id<\w{8}> controllers.RelayTour.apiShow(id: RelayTourId)
GET /api/broadcast/$tourId<\w{8}>.pgn controllers.RelayTour.pgn(tourId: RelayTourId)
GET /broadcast/$tourId<\w{8}>/edit controllers.RelayTour.edit(tourId: RelayTourId)
Expand Down
2 changes: 2 additions & 0 deletions ui/analyse/css/build/analyse.relay.embed.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import '../../../common/css/embed';
@import '../analyse.abstract';
@import '../../../common/css/base/util';
@import '../../../common/css/base/form';
@import '../../../common/css/form/form3';
@import '../../../common/css/component/tabs-horiz';
Expand All @@ -9,6 +10,7 @@
@import '../../../common/css/component/mini-game';
@import '../../../common/css/component/board';
@import '../../../common/css/component/dialog';
@import '../../../common/css/component/box';

@import '../study/show';
@import '../study/relay/show';
Expand Down
19 changes: 9 additions & 10 deletions ui/analyse/src/study/relay/relayTourView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ const overview = (ctx: RelayViewContext) => {
];
};

const groupSelect = (relay: RelayCtrl, group: RelayGroup) => {
const toggle = relay.groupSelectShow;
const clickHook = { hook: bind('click', toggle.toggle, relay.redraw) };
const groupSelect = (ctx: RelayViewContext, group: RelayGroup) => {
const toggle = ctx.relay.groupSelectShow;
const clickHook = { hook: bind('click', toggle.toggle, ctx.relay.redraw) };
return h(
'div.mselect.relay-tour__mselect.relay-tour__group-select',
{
Expand All @@ -197,7 +197,7 @@ const groupSelect = (relay: RelayCtrl, group: RelayGroup) => {
h(
'label.mselect__label',
clickHook,
group.tours.find(t => t.id == relay.data.tour.id)?.name || relay.data.tour.name,
group.tours.find(t => t.id == ctx.relay.data.tour.id)?.name || ctx.relay.data.tour.name,
),
...(toggle()
? [
Expand All @@ -206,8 +206,8 @@ const groupSelect = (relay: RelayCtrl, group: RelayGroup) => {
'nav.mselect__list',
group.tours.map(tour =>
h(
`a.mselect__item${tour.id == relay.data.tour.id ? '.current' : ''}`,
{ attrs: { href: `/broadcast/-/${tour.id}` } },
`a.mselect__item${tour.id == ctx.relay.data.tour.id ? '.current' : ''}`,
{ attrs: { href: ctx.study.addEmbedPrefix(`/broadcast/-/${tour.id}`) } },
tour.name,
),
),
Expand Down Expand Up @@ -295,7 +295,6 @@ const stats = (ctx: RelayViewContext) => [...header(ctx), statsView(ctx.relay.st
const header = (ctx: RelayViewContext) => {
const { ctrl, relay, allowVideo } = ctx;
const d = relay.data,
study = ctrl.study!,
group = d.group,
embedVideo = d.videoUrls && allowVideo;

Expand All @@ -304,8 +303,8 @@ const header = (ctx: RelayViewContext) => {
h('div.relay-tour__header__content', [
h('h1', group?.name || d.tour.name),
h('div.relay-tour__header__selectors', [
group && groupSelect(relay, group),
roundSelect(relay, study),
group && groupSelect(ctx, group),
roundSelect(relay, ctx.study),
]),
]),
h(
Expand All @@ -314,7 +313,7 @@ const header = (ctx: RelayViewContext) => {
? renderVideoPlayer(relay)
: d.tour.image
? h('img', { attrs: { src: d.tour.image } })
: study.members.isOwner()
: ctx.study.members.isOwner()
? h(
'a.button.relay-tour__header__image-upload',
{ attrs: { href: `/broadcast/${d.tour.id}/edit` } },
Expand Down

0 comments on commit feef5e2

Please sign in to comment.