Skip to content

Commit

Permalink
Merge branch 'master' into lichess_ublog_fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar authored Aug 2, 2024
2 parents 6c5b867 + 9a71024 commit b211d8e
Show file tree
Hide file tree
Showing 17 changed files with 169 additions and 90 deletions.
4 changes: 3 additions & 1 deletion app/controllers/RelayTour.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import scalalib.Json.given
import lila.app.{ *, given }
import lila.core.id.RelayTourId
import lila.core.net.IpAddress
import lila.relay.RelayTour as TourModel
import lila.relay.{ JsonView, RelayTour as TourModel }
import lila.relay.ui.FormNavigation

final class RelayTour(env: Env, apiC: => Api) extends LilaController(env):
Expand Down Expand Up @@ -210,6 +210,8 @@ final class RelayTour(env: Env, apiC: => Api) extends LilaController(env):
res <- JsonOk(env.relay.jsonView.top(active, upcoming, past))
yield res

private given (using RequestHeader): JsonView.Config = JsonView.Config(html = getBool("html"))

private def WithTour(id: RelayTourId)(f: TourModel => Fu[Result])(using Context): Fu[Result] =
Found(env.relay.api.tourById(id))(f)

Expand Down
2 changes: 1 addition & 1 deletion modules/fide/src/main/FidePlayerApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ final class FidePlayerApi(repo: FideRepo, cacheApi: lila.memo.CacheApi)(using Ex

private val cache =
cacheApi[TitleName, Option[FidePlayer]](1024, "player.fidePlayer.byName"):
_.expireAfterWrite(3.minutes).buildAsyncFuture: p =>
_.expireAfterWrite(5.minutes).buildAsyncFuture: p =>
repo.playerColl
.find($doc("token" -> FidePlayer.tokenize(p.name.value), "title" -> p.title))
.cursor[FidePlayer]()
Expand Down
2 changes: 1 addition & 1 deletion modules/fide/src/main/FidePlayerSync.scala
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ final private class FidePlayerSync(repo: FideRepo, ws: StandaloneWSClient)(using
for
id <- number(0, 15)
name1 <- string(15, 76)
name = name1.filterNot(_.isDigit).trim
name = name1.trim
if name.sizeIs > 2
title = string(84, 89).flatMap(PlayerTitle.get)
wTitle = string(89, 105).flatMap(PlayerTitle.get)
Expand Down
18 changes: 11 additions & 7 deletions modules/relay/src/main/JsonView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class JsonView(
picfitUrl: PicfitUrl
)(using Executor):

import JsonView.given
import JsonView.{ Config, given }

given Writes[Option[RelayTour.Tier]] = Writes: t =>
JsString(t.flatMap(RelayTour.Tier.keys.get) | "user")
Expand Down Expand Up @@ -50,14 +50,16 @@ final class JsonView(
"tours" -> g.withShorterTourNames.tours
)

def fullTour(tour: RelayTour): JsObject =
def fullTour(tour: RelayTour)(using config: Config): JsObject =
Json
.toJsObject(tour)
.add("markup" -> tour.markup.map(markup(tour)))
.add("description" -> tour.markup.map: md =>
if config.html then markup(tour)(md).value
else md.value)
.add("teamTable" -> tour.teamTable)
.add("leaderboard" -> tour.autoLeaderboard)

def fullTourWithRounds(trs: WithRounds, group: Option[RelayGroup.WithTours]): JsObject =
def fullTourWithRounds(trs: WithRounds, group: Option[RelayGroup.WithTours])(using Config): JsObject =
Json
.obj(
"tour" -> fullTour(trs.tour),
Expand All @@ -66,7 +68,7 @@ final class JsonView(
)
.add("group" -> group)

def apply(t: RelayTour | WithLastRound | ActiveWithSomeRounds): JsObject = t match
def apply(t: RelayTour | WithLastRound | ActiveWithSomeRounds)(using Config): JsObject = t match
case tour: RelayTour => Json.obj("tour" -> fullTour(tour))
case tr: WithLastRound =>
Json
Expand Down Expand Up @@ -124,7 +126,7 @@ final class JsonView(
pinned: Option[RelayPinnedStream]
) =
JsonView.JsData(
relay = fullTourWithRounds(trs, group)
relay = fullTourWithRounds(trs, group)(using Config(html = true))
.add("sync" -> (canContribute.so(trs.rounds.find(_.id == currentRoundId).map(_.sync))))
.add("lcc", trs.rounds.find(_.id == currentRoundId).map(_.sync.upstream.exists(_.hasLcc)))
.add("isSubscribed" -> isSubscribed)
Expand All @@ -139,7 +141,7 @@ final class JsonView(
active: List[ActiveWithSomeRounds],
upcoming: List[WithLastRound],
past: Paginator[WithLastRound]
) =
)(using Config) =
Json.obj(
"active" -> active.sortBy(t => -(~t.tour.tier)).map(apply(_)),
"upcoming" -> upcoming.map(apply(_)),
Expand All @@ -148,6 +150,8 @@ final class JsonView(

object JsonView:

case class Config(html: Boolean)

case class JsData(relay: JsObject, study: JsObject, analysis: JsObject, group: Option[RelayGroup.Name])

given OWrites[RelayPinnedStream] = OWrites: s =>
Expand Down
2 changes: 1 addition & 1 deletion modules/relay/src/main/RelayTourStream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class RelayTourStream(
pipe = List($doc("$sort" -> RelayRoundRepo.sort.start))
)

def officialTourStream(perSecond: MaxPerSecond, nb: Max): Source[JsObject, ?] =
def officialTourStream(perSecond: MaxPerSecond, nb: Max)(using JsonView.Config): Source[JsObject, ?] =
val activeStream = colls.tour
.aggregateWith[Bdoc](readPreference = ReadPref.sec): framework =>
import framework.*
Expand Down
24 changes: 20 additions & 4 deletions modules/web/src/main/ui/SitePages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ final class SitePages(helpers: Helpers):
),
br,
st.section(cls := "box box-pad developers") {
val args = """style="width: 400px; height: 444px;" allowtransparency="true" frameborder="0""""
val args = """style="width: 400px; aspect-ratio: 10/11;" allowtransparency="true" frameborder="0""""
frag(
h1(cls := "box__top", id := "embed-tv")("Embed Lichess TV in your site"),
div(cls := "body")(
Expand All @@ -79,7 +79,7 @@ final class SitePages(helpers: Helpers):
},
br,
st.section(cls := "box box-pad developers") {
val args = """style="width: 400px; height: 444px;" allowtransparency="true" frameborder="0""""
val args = """style="width: 400px; aspect-ratio: 10/11;" allowtransparency="true" frameborder="0""""
frag(
h1(cls := "box__top", id := "embed-puzzle")("Embed the daily puzzle in your site"),
div(cls := "body")(
Expand All @@ -102,7 +102,7 @@ final class SitePages(helpers: Helpers):
},
br,
st.section(cls := "box box-pad developers") {
val args = """style="width: 600px; height: 397px;" frameborder="0""""
val args = """style="width: 100%; aspect-ratio: 3/2;" frameborder="0""""
frag(
h1(cls := "box__top", id := "embed-study")("Embed a chess analysis in your site"),
div(cls := "body")(
Expand All @@ -121,7 +121,7 @@ final class SitePages(helpers: Helpers):
},
br,
st.section(cls := "box box-pad developers") {
val args = """style="width: 600px; height: 397px;" frameborder="0""""
val args = """style="width: 100%; aspect-ratio: 3/2;" frameborder="0""""
frag(
h1(cls := "box__top")("Embed a chess game in your site"),
div(cls := "body")(
Expand All @@ -139,6 +139,22 @@ final class SitePages(helpers: Helpers):
p("The text is automatically translated to your visitor's language.")
)
)
},
br,
st.section(cls := "box box-pad developers") {
val args = """style="width: 100%; aspect-ratio: 4/3;" frameborder="0""""
frag(
h1(cls := "box__top")("Embed a broadcast in your site"),
div(cls := "body")(
div(cls := "center"):
raw(
s"""<iframe src="/embed/broadcast/sixdays-budapest-july-2024--gm-a/round-4/Cfu9KXTq?bg=auto&theme=auto" $args></iframe>"""
)
,
parameters,
p("The text is automatically translated to your visitor's language.")
)
)
}
)

Expand Down
1 change: 1 addition & 0 deletions ui/analyse/css/build/analyse.relay.embed.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@import '../../../common/css/component/board';
@import '../../../common/css/component/dialog';
@import '../../../common/css/component/box';
@import '../../../common/css/component/button';

@import '../study/show';
@import '../study/relay/show';
Expand Down
43 changes: 36 additions & 7 deletions ui/analyse/css/study/relay/_embed.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,45 @@ body {
@media (min-width: at-least($small)) {
---main-margin: 1vw;
---block-gap: 15px;
margin-bottom: $block-gap;
}
}

main {
grid-area: main;
/* game view */
main.analyse {
/* In embed mode we don't want any space on the sides. Make the table expand to the full width */
$embed-uniboard-table: minmax(#{$col3-uniboard-table-min}, auto);
@include mq-at-least-col2 {
grid-template-columns: var(---col2-uniboard-width) $analyse-block-gap $embed-uniboard-table;
grid-template-areas:
'board gauge tools'
'under . controls'
'under . round-training'
'under . side';
}

@include mq-at-least-col3 {
grid-template-columns: $col3-uniboard-side $analyse-block-gap var(---col3-uniboard-width) $analyse-block-gap $embed-uniboard-table;
}
}

/* tour view */
main.is-relay.has-relay-tour {
grid-template-areas: 'relay-tour' 'side';

&.page-small {
max-width: 1000px;
margin: auto;
width: 100%;
@include mq-at-least-col2 {
grid-template-rows: 100vh;
grid-template-areas: 'relay-tour . side';
.relay-games {
max-height: unset;
}
}

@include mq-at-least-col3 {
grid-template-areas: 'side . relay-tour relay-tour relay-tour';
}
}

.relay-tour__markup,
.study__multiboard {
overflow-y: auto;
}
28 changes: 16 additions & 12 deletions ui/analyse/css/study/relay/_tour.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
$hover-bg: $m-primary_bg--mix-30;
%tour-margin-horiz {
margin-left: 2vw;
margin-right: 2vw;
}

.relay-tour {
@extend %box-neat-force, %flex-column;
gap: 3em;
gap: 3vh;
background: $c-bg-box;
&__side {
@extend %flex-column;
Expand Down Expand Up @@ -128,7 +132,6 @@ $hover-bg: $m-primary_bg--mix-30;
&__image {
display: block;
}
min-height: 12vh;
}

h1 {
Expand All @@ -138,14 +141,15 @@ $hover-bg: $m-primary_bg--mix-30;
}

&__content {
@extend %flex-column;
@extend %flex-column, %tour-margin-horiz;
flex: 1;
min-width: 0; // somehow this prevents overflow when mselect is large
gap: 1em;
@include mq-at-least-col3 {
gap: calc(var(---box-padding) / 3);
}
margin: 1em 2em;
margin-top: 1em;
margin-bottom: 1em;
}

&__selectors {
Expand Down Expand Up @@ -257,7 +261,7 @@ $hover-bg: $m-primary_bg--mix-30;
}

&__nav {
@extend %flex-between, %box-margin-horiz;
@extend %flex-between, %tour-margin-horiz;
gap: 1em;
user-select: none;
}
Expand Down Expand Up @@ -287,10 +291,10 @@ $hover-bg: $m-primary_bg--mix-30;
}

&__info {
@extend %box-neat, %flex-between, %box-margin-horiz;
@extend %box-neat, %flex-between, %tour-margin-horiz;
gap: 1em;
background: $c-bg-zebra;
padding: 1em 2em;
padding: 1em 2vw;
> div {
@extend %flex-center-nowrap;
gap: 1em;
Expand All @@ -301,11 +305,11 @@ $hover-bg: $m-primary_bg--mix-30;
}

&__markup {
@extend %box-margin-horiz;
@extend %tour-margin-horiz;
@include rendered-markdown(2em, 50vh);
}
&__source {
@extend %box-margin-horiz;
@extend %tour-margin-horiz;
font-style: italic;
@media (max-width: at-most($x-large)) {
display: none;
Expand All @@ -315,9 +319,9 @@ $hover-bg: $m-primary_bg--mix-30;
}
}
&__share {
@extend %box-neat, %box-margin-horiz;
@extend %box-neat, %tour-margin-horiz;
background: $c-bg-zebra;
padding: 3em var(---box-padding) 1em var(---box-padding);
padding: 3em 2vw 1em 2vw;
h2 {
margin-bottom: 3rem;
}
Expand Down Expand Up @@ -367,7 +371,7 @@ $hover-bg: $m-primary_bg--mix-30;

.study__multiboard {
@media (min-width: at-least($xx-large)) {
margin: 0 calc(var(---box-padding) - 1em);
margin: 0 2em;
.now-playing a {
padding: 0.8em;
}
Expand Down
5 changes: 5 additions & 0 deletions ui/analyse/src/study/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,8 @@ export interface WithChapterId {

export type WithWhoAndPos = WithWho & WithPosition;
export type WithWhoAndChap = WithWho & WithChapterId;

export interface ChapterSelect {
is: (idOrNumber: ChapterId | number) => boolean;
set: (idOrNumber: ChapterId | number, force?: boolean) => Promise<boolean>;
}
2 changes: 1 addition & 1 deletion ui/analyse/src/study/multiBoard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function view(ctrl: MultiBoardCtrl, study: StudyCtrl): MaybeVNode {
'div.now-playing',
{
hook: {
insert: gameLinksListener(study.setChapter),
insert: gameLinksListener(study.chapterSelect),
},
},
pager.currentPageResults.map(makePreview(basePath, study.vm.chapterId, cloudEval)),
Expand Down
1 change: 0 additions & 1 deletion ui/analyse/src/study/relay/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export interface RelayTour {
description?: string;
info: RelayTourInfo;
official?: boolean;
markup?: string;
image?: string;
teamTable?: boolean;
leaderboard?: boolean;
Expand Down
6 changes: 3 additions & 3 deletions ui/analyse/src/study/relay/relayCtrl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RelayData, LogEvent, RelaySync, RelayRound, RoundId } from './interfaces';
import { BothClocks, ChapterId, Federations, ServerClockMsg } from '../interfaces';
import { BothClocks, ChapterId, ChapterSelect, Federations, ServerClockMsg } from '../interfaces';
import { StudyMemberCtrl } from '../studyMembers';
import { AnalyseSocketSend } from '../../socket';
import { Prop, Toggle, defined, notNull, prop, toggle } from 'common';
Expand Down Expand Up @@ -36,7 +36,7 @@ export default class RelayCtrl {
private readonly chapters: StudyChapters,
private readonly multiCloudEval: MultiCloudEval,
private readonly federations: () => Federations | undefined,
setChapter: (id: ChapterId | number) => Promise<boolean>,
chapterSelect: ChapterSelect,
) {
this.tourShow = toggle((location.pathname.split('/broadcast/')[1].match(/\//g) || []).length < 5);
const locationTab = location.hash.replace(/^#/, '') as RelayTab;
Expand All @@ -47,7 +47,7 @@ export default class RelayCtrl {
: 'boards';
this.tab = prop<RelayTab>(initialTab);
this.teams = data.tour.teamTable
? new RelayTeams(id, this.multiCloudEval, setChapter, this.roundPath, redraw)
? new RelayTeams(id, this.multiCloudEval, chapterSelect, this.roundPath, redraw)
: undefined;
this.leaderboard = data.tour.leaderboard
? new RelayLeaderboard(data.tour.id, this.federations, redraw)
Expand Down
Loading

0 comments on commit b211d8e

Please sign in to comment.