Skip to content

Commit

Permalink
Merge branch 'master' into glicko-first-move
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar authored Nov 1, 2024
2 parents d31bc4a + cb70d43 commit 300d191
Show file tree
Hide file tree
Showing 46 changed files with 283 additions and 178 deletions.
2 changes: 1 addition & 1 deletion app/controllers/User.scala
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ final class User(
me: Me
): Fu[Result] =
env.report.api.inquiries
.ofModId(me.id)
.ofModId(me)
.zip(env.user.api.withPerfsAndEmails(username).orFail(s"No such user $username"))
.flatMap { case (inquiry, WithPerfsAndEmails(user, emails)) =>
import views.mod.{ user as ui }
Expand Down
1 change: 0 additions & 1 deletion modules/fide/src/main/FidePlayerSync.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ final private class FidePlayerSync(repo: FideRepo, ws: StandaloneWSClient)(using
if httpStream.status != 200 then
fufail(s"RelayFidePlayerApi.pull ${httpStream.status} ${httpStream.statusText}")
else
val startAt = nowInstant
for
nbUpdated <-
ZipInputStreamSource: () =>
Expand Down
2 changes: 0 additions & 2 deletions modules/relay/src/main/RelayRoundForm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ final class RelayRoundForm(using mode: Mode):
.map(_.trim)
.traverse: i =>
GameId.from(i.trim).toRight(s"Invalid game ID: $i")
.left
.map(_.mkString(", "))
.filterOrElse(
_.sizeIs <= RelayFetch.maxChaptersToShow.value,
s"Max games: ${RelayFetch.maxChaptersToShow}"
Expand Down
4 changes: 2 additions & 2 deletions modules/team/src/main/ui/FormUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final class FormUi(helpers: Helpers, bits: TeamUi)(
standardFlash,
t.enabled.option(
postForm(cls := "form3", action := routes.Team.update(t.id))(
flairField(form, t),
flairField(form),
entryFields(form),
textFields(form),
accessFields(form),
Expand Down Expand Up @@ -92,7 +92,7 @@ final class FormUi(helpers: Helpers, bits: TeamUi)(

private val explainInput = input(st.name := "explain", tpe := "hidden")

private def flairField(form: Form[?], team: Team)(using Context) =
private def flairField(form: Form[?])(using Context) =
form3.flairPickerGroup(form("flair"), Flair.from(form("flair").value))

private def textFields(form: Form[?])(using Context) = frag(
Expand Down
1 change: 1 addition & 0 deletions translation/source/site.xml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@
<item quantity="one">%s game with you</item>
<item quantity="other">%s games with you</item>
</plurals>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<string name="whiteTimeOut">White time out</string>
<string name="blackTimeOut">Black time out</string>
Expand Down
19 changes: 9 additions & 10 deletions ui/.build/readme
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ Usage:
# multiple short options can be preceded by a single dash

Recommended:
ui/build -cdw # clean, build debug, and watch for changes with clean rebuilds
ui/build -cdw # clean, build debug, and watch for changes with clean rebuilds

Options:
-h, --help show this help and exit
-w, --watch build and watch for changes
-c, --clean-build clean all non-i18n build artifacts and build fresh
-c, --clean clean all build artifacts and build fresh
-p, --prod build minified assets (prod builds)
-n, --no-install don't run pnpm install
-d, --debug build assets with site.debug = true
Expand All @@ -22,18 +22,17 @@ Options:
--no-context don't log the context

Exclusive Options: (any of these will disable other functions)
--clean clean all build artifacts, including i18n/translation, and exit
--clean-exit clean all build artifacts and exit
--tsc run tsc on {package}/tsconfig.json and dependencies
--sass run sass on {package}/css/build/*.scss and dependencies
--esbuild run esbuild (given in {package}/package.json/lichess/bundles array)
--sync run sync copies (given in {package}/package.json/lichess/sync objects)
--i18n build @types/lichess/i18n.d.ts and translation/js files

Examples:
./build -np # no pnpm install, build minified
./build analyse site msg # build analyse, site, and msg packages (as opposed to everything)
./build -w dasher chart # watch mode for dasher and chart packages
./build --tsc -w # watch mode but type checking only
./build --sass msg notify # build css only for msg and notify packages
./build -w -l=/path # build, watch, and patch js console with POST to ${location.origin}/path.
# ui/build listens on 8666, displays received json as 'web' over stdout
./build -np # no pnpm install, build minified
./build -w dasher chart # watch mode for dasher and chart packages
./build --tsc -w # watch mode but type checking only
./build -w -l=/path # build, watch. patch console methods in emitted js to also POST messages
# to ${location.origin}/path. ui/build watch process displays received
# messages as 'web' in build logs
6 changes: 1 addition & 5 deletions ui/.build/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ import { esbuild, stopEsbuild } from './esbuild.ts';
import { sync, stopSync } from './sync.ts';
import { monitor, stopMonitor } from './monitor.ts';
import { writeManifest } from './manifest.ts';
import { clean } from './clean.ts';
import { type Package, env, errorMark, colors as c } from './main.ts';
import { i18n, stopI18n } from './i18n.ts';

export async function build(pkgs: string[]): Promise<void> {
await stop();
await clean();

if (env.install) cps.execSync('pnpm install', { cwd: env.rootDir, stdio: 'inherit' });
if (!pkgs.length) env.log(`Parsing packages in '${c.cyan(env.uiDir)}'`);

Expand Down Expand Up @@ -43,7 +39,7 @@ export async function build(pkgs: string[]): Promise<void> {
monitor(pkgs);
}

export async function stop(): Promise<void> {
export async function stopBuild(): Promise<void> {
stopMonitor();
stopSass();
stopTsc();
Expand Down
19 changes: 9 additions & 10 deletions ui/.build/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ const args: Record<string, string> = {
'--watch': 'w',
'--prod': 'p',
'--debug': 'd',
'--clean-build': 'c',
'--clean': '',
'--clean-exit': '',
'--clean': 'c',
'--update': '',
'--no-install': 'n',
'--log': 'l',
};

type Builder = 'sass' | 'tsc' | 'esbuild';

export function main(): void {
export async function main(): Promise<void> {
const argv = ps.argv.slice(2);
const oneDashRe = /^-([a-z]+)(?:=[a-zA-Z0-9-_:./]+)?$/;
const stringArg = (arg: string): string | boolean => {
Expand Down Expand Up @@ -66,17 +66,17 @@ export function main(): void {
env.remoteLog = stringArg('--log');
env.clean = argv.some(x => x.startsWith('--clean')) || oneDashArgs.includes('c');
env.install = !argv.includes('--no-install') && !oneDashArgs.includes('n');
env.rebuild = env.watch && env.install;
env.rgb = argv.includes('--rgb');

if (argv.length === 1 && (argv[0] === '--help' || argv[0] === '-h')) {
console.log(fs.readFileSync(path.resolve(env.buildDir, 'readme'), 'utf8'));
} else if (argv.includes('--clean')) {
deepClean();
} else {
startConsole();
build(argv.filter(x => !x.startsWith('-')));
return;
} else if (env.clean) {
await deepClean();
if (argv.includes('--clean-exit')) return;
}
startConsole();
build(argv.filter(x => !x.startsWith('-')));
}

export interface Package {
Expand Down Expand Up @@ -127,7 +127,6 @@ class Env {
building: Package[] = [];

watch = false;
rebuild = false;
clean = false;
prod = false;
debug = false;
Expand Down
9 changes: 5 additions & 4 deletions ui/.build/src/monitor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import fs from 'node:fs';
import path from 'node:path';
import ps from 'node:process';
import { build, stop } from './build.ts';
import { build, stopBuild } from './build.ts';
import { env } from './main.ts';
import { clean } from './clean.ts';
import { globArray } from './parse.ts';
import { stopTsc, tsc } from './tsc.ts';
import { stopEsbuild, esbuild } from './esbuild.ts';
Expand Down Expand Up @@ -37,11 +38,11 @@ export async function monitor(pkgs: string[]): Promise<void> {
}, 2000);
};
const packageChange = async () => {
if (env.rebuild) {
if (env.watch && env.install) {
clearTimeout(tscTimeout);
clearTimeout(reinitTimeout);
await stop();
reinitTimeout = setTimeout(() => build(pkgs), 2000);
await stopBuild();
reinitTimeout = setTimeout(() => clean().then(() => build(pkgs)), 2000);
return;
}
env.warn('Exiting due to package.json change');
Expand Down
2 changes: 2 additions & 0 deletions ui/@types/lichess/i18n.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3601,6 +3601,8 @@ interface I18n {
notificationsX: I18nFormat;
/** Offer draw */
offerDraw: string;
/** OK */
ok: string;
/** One day */
oneDay: string;
/** One URL per line. */
Expand Down
25 changes: 25 additions & 0 deletions ui/@types/lichess/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,33 @@ interface Fipr {
x64hash128(input: string, seed: number): string;
}

interface Events {
on(key: string, cb: (...args: any[]) => void): void;
off(key: string, cb: (...args: any[]) => void): void;
}

interface Api {
initializeDom: (root?: HTMLElement) => void;
events: Events;
socket: {
subscribeToMoveLatency: () => void;
events: Events;
};
onlineFriends: {
request: () => void;
events: Events;
};
chat: {
post: (text: string) => void;
};
overrides: {
[key: string]: (...args: any[]) => unknown;
};
}

interface Window {
site: Site;
lichess: Api;
fipr: Fipr;
i18n: I18n;
$as<T>(cash: Cash): T;
Expand Down
2 changes: 1 addition & 1 deletion ui/analyse/src/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const bind = (ctrl: AnalyseCtrl) => {
.bind('f', ctrl.flip)
.bind('?', () => {
ctrl.keyboardHelp = !ctrl.keyboardHelp;
if (ctrl.keyboardHelp) pubsub.emit('analyse.close-all');
if (ctrl.keyboardHelp) pubsub.emit('analysis.closeAll');
ctrl.redraw();
})
.bind('l', ctrl.toggleCeval)
Expand Down
2 changes: 1 addition & 1 deletion ui/analyse/src/plugins/analyse.study.tour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class TourCtrl {
},
exitOnEsc: true,
});
pubsub.on('analyse.close-all', this.tour.cancel);
pubsub.on('analysis.closeAll', this.tour.cancel);
}

buildTour(steps: Shepherd.Step.StepOptions[]) {
Expand Down
4 changes: 2 additions & 2 deletions ui/analyse/src/study/chapterNewForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ export class StudyChapterNewForm {
readonly setTab: () => void,
readonly root: AnalyseCtrl,
) {
pubsub.on('analyse.close-all', () => this.isOpen(false));
pubsub.on('analysis.closeAll', () => this.isOpen(false));
}

open = () => {
pubsub.emit('analyse.close-all');
pubsub.emit('analysis.closeAll');
this.isOpen(true);
this.loadVariants();
this.initial(false);
Expand Down
4 changes: 2 additions & 2 deletions ui/analyse/src/study/inviteForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ export function makeCtrl(
spectators = prop<string[]>([]);

const toggle = () => {
if (!open()) pubsub.emit('analyse.close-all');
if (!open()) pubsub.emit('analysis.closeAll');
open(!open());
redraw();
};

pubsub.on('analyse.close-all', () => open(false));
pubsub.on('analysis.closeAll', () => open(false));

const previouslyInvited = storedSet<string>('study.previouslyInvited', 10);
return {
Expand Down
3 changes: 1 addition & 2 deletions ui/bits/src/bits.challengePage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as xhr from 'common/xhr';
import StrongSocket from 'common/socket';
import { userComplete } from 'common/userComplete';
import { pubsub } from 'common/pubsub';

interface ChallengeOpts {
xhrUrl: string;
Expand All @@ -19,7 +18,7 @@ export function initModule(opts: ChallengeOpts): void {
xhr.text(opts.xhrUrl).then(html => {
$(selector).replaceWith($(html).find(selector));
init();
pubsub.emit('content-loaded', $(selector)[0]);
window.lichess.initializeDom($(selector)[0]);
});
},
},
Expand Down
6 changes: 3 additions & 3 deletions ui/bits/src/bits.checkout.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as xhr from 'common/xhr';
import { spinnerHtml } from 'common/spinner';
import { contactEmail } from './bits';
import { alert } from 'common/dialog';
import { alert, prompt } from 'common/dialog';

export interface Pricing {
currency: string;
Expand Down Expand Up @@ -56,9 +56,9 @@ export function initModule({ stripePublicKey, pricing }: { stripePublicKey: stri
toggleCheckout();
});

$checkout.find('group.amount .other label').on('click', function (this: HTMLLabelElement) {
$checkout.find('group.amount .other label').on('click', async function (this: HTMLLabelElement) {
let amount: number;
const raw: string = prompt(this.title) || '';
const raw: string = (await prompt(this.title)) ?? '';
try {
amount = parseFloat(raw.replace(',', '.').replace(/[^0-9\.]/gim, ''));
} catch (_) {
Expand Down
3 changes: 1 addition & 2 deletions ui/bits/src/bits.infiniteScroll.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as xhr from 'common/xhr';
import { spinnerHtml } from 'common/spinner';
import { pubsub } from 'common/pubsub';

export function initModule(selector: string = '.infinite-scroll'): void {
$(selector).each(function (this: HTMLElement) {
Expand Down Expand Up @@ -37,7 +36,7 @@ function register(el: HTMLElement, selector: string, backoff = 500) {
nav.remove();
$(el).append(($(html).is(selector) ? $(html) : $(html).find(selector)).html());
dedupEntries(el);
pubsub.emit('content-loaded', el);
window.lichess.initializeDom(el);
setTimeout(() => register(el, selector, backoff * 1.05), backoff); // recursion with backoff
},
e => {
Expand Down
14 changes: 9 additions & 5 deletions ui/bits/src/bits.team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as xhr from 'common/xhr';
import flairPickerLoader from './exports/flairPicker';
import StrongSocket from 'common/socket';
import { makeChat } from 'chat';
import { prompt } from 'common/dialog';

interface TeamOpts {
id: string;
Expand All @@ -23,11 +24,14 @@ export function initModule(opts: TeamOpts): void {
});
}

$('button.explain').on('click', e => {
let why = prompt('Please explain the reason for this action');
why = why && why.trim();
if (why && why.length > 3) $(e.target).parents('form').find('input[name="explain"]').val(why);
else return false;
$('button.explain').on('click', async e => {
if (!e.isTrusted) return;
e.preventDefault();
const why = (await prompt('Please explain the reason for this action'))?.trim();
if (why && why.length > 3) {
$(e.target).parents('form').find('input[name="explain"]').val(why);
(e.target as HTMLElement).click();
}
});

$('.emoji-details').each(function (this: HTMLElement) {
Expand Down
10 changes: 5 additions & 5 deletions ui/bits/src/bits.tvGames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const requestReplacementGame = () => {
.json(url.toString())
.then((data: ReplacementResponse) => {
main.find(`.mini-game[href^="/${oldId}"]`).replaceWith(data.html);
if (data.html.includes('mini-game__result')) onFinish(data.id);
pubsub.emit('content-loaded');
if (data.html.includes('mini-game__result')) window.lichess.overrides.tvGamesOnFinish(data.id);
window.lichess.initializeDom();
})
.then(done, done);
});
Expand All @@ -40,17 +40,17 @@ const done = () => {
requestReplacementGame();
};

const onFinish = (id: string) =>
window.lichess.overrides.tvGamesOnFinish = (id: string) =>
setTimeout(() => {
finishedIdQueue.push(id);
requestReplacementGame();
}, 7000); // 7000 matches the rematch wait duration in /modules/tv/main/Tv.scala

site.load.then(() => {
pubsub.on('socket.in.finish', ({ id }) => onFinish(id));
pubsub.on('socket.in.finish', ({ id }) => window.lichess.overrides.tvGamesOnFinish(id));
$('main.tv-games')
.find('.mini-game')
.each((_i, el) => {
if ($(el).find('.mini-game__result').length > 0) onFinish(getId(el)!);
if ($(el).find('.mini-game__result').length > 0) window.lichess.overrides.tvGamesOnFinish(getId(el)!);
});
});
Loading

0 comments on commit 300d191

Please sign in to comment.