Skip to content

Commit

Permalink
Merge branch 'master' into streamer-approval-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar authored Dec 20, 2024
2 parents ff549c9 + a21fe82 commit 0067769
Show file tree
Hide file tree
Showing 19 changed files with 34 additions and 44 deletions.
5 changes: 0 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ Compile / sourceDirectory := baseDirectory.value / "app"
Compile / scalaSource := baseDirectory.value / "app"
Universal / sourceDirectory := baseDirectory.value / "dist"

// cats-parse v1.0.0 is the same as v0.3.1, so this is safe
ThisBuild / libraryDependencySchemes ++= Seq(
"org.typelevel" %% "cats-parse" % VersionScheme.Always
)

// format: off
libraryDependencies ++= akka.bundle ++ playWs.bundle ++ macwire.bundle ++ scalalib.bundle ++ chess.bundle ++ Seq(
play.json, play.logback, compression, hasher,
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions ui/api/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type PubsubCallback, type PubsubEvent, pubsub, initializeDom } from 'common/pubsub';
import { type PubsubCallback, type PubsubEvent, pubsub } from 'common/pubsub';

// #TODO document these somewhere
const publicEvents = ['ply', 'analysis.change', 'chat.resize', 'analysis.closeAll'];
Expand Down Expand Up @@ -27,8 +27,10 @@ export interface Api {
}

// this object is available to extensions as window.lichess
export const api: Api = ((window as any).lichess = {
initializeDom,
export const api: Api = {
initializeDom: (root?: HTMLElement) => {
pubsub.emit('content-loaded', root);
},
events: {
on(name: PubsubEvent, cb: PubsubCallback): void {
if (!publicEvents.includes(name)) throw 'This event is not part of the public API';
Expand Down Expand Up @@ -72,4 +74,4 @@ export const api: Api = ((window as any).lichess = {
// some functions will be exposed here
// to be overriden by browser extensions
overrides: {},
});
};
4 changes: 2 additions & 2 deletions ui/bits/src/bits.challengePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as xhr from 'common/xhr';
import { wsConnect, wsSend } from 'common/socket';
import { userComplete } from 'common/userComplete';
import { isTouchDevice, isIos } from 'common/device';
import { initializeDom } from 'common/pubsub';
import { pubsub } from 'common/pubsub';

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

export function initModule(selector: string = '.infinite-scroll'): void {
$(selector).each(function (this: HTMLElement) {
Expand Down Expand Up @@ -37,7 +37,7 @@ function register(el: HTMLElement, selector: string, backoff = 500) {
nav.remove();
$(el).append(($(html).is(selector) ? $(html) : $(html).find(selector)).html());
dedupEntries(el);
initializeDom(el);
pubsub.emit('content-loaded', el);
setTimeout(() => register(el, selector, backoff * 1.05), backoff); // recursion with backoff
},
e => {
Expand Down
4 changes: 2 additions & 2 deletions ui/bits/src/bits.tvGames.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as xhr from 'common/xhr';
import { pubsub, initializeDom } from 'common/pubsub';
import { pubsub } from 'common/pubsub';
import { api } from 'api';

interface ReplacementResponse {
Expand Down Expand Up @@ -30,7 +30,7 @@ const requestReplacementGame = () => {
.then((data: ReplacementResponse) => {
main.find(`.mini-game[href^="/${oldId}"]`).replaceWith(data.html);
if (data.html.includes('mini-game__result')) api.overrides.tvGamesOnFinish(data.id);
initializeDom();
pubsub.emit('content-loaded');
})
.then(done, done);
});
Expand Down
4 changes: 2 additions & 2 deletions ui/bits/src/bits.user.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as xhr from 'common/xhr';
import { makeLinkPopups } from 'common/linkPopup';
import { alert } from 'common/dialog';
import { initializeDom } from 'common/pubsub';
import { pubsub } from 'common/pubsub';

export function initModule(): void {
makeLinkPopups($('.social_links'));
Expand Down Expand Up @@ -48,7 +48,7 @@ export function initModule(): void {
browseTo = (path: string) =>
xhr.text(path).then(html => {
$content.html(html);
initializeDom($content[0]);
pubsub.emit('content-loaded', $content[0]);
history.replaceState({}, '', path);
site.asset.loadEsm('bits.infiniteScroll');
});
Expand Down
1 change: 0 additions & 1 deletion ui/chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
".": "./src/chat.ts"
},
"dependencies": {
"api": "workspace:*",
"common": "workspace:*",
"palantir": "workspace:*"
}
Expand Down
3 changes: 1 addition & 2 deletions ui/chat/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { prop } from 'common';
import { storage, type LichessStorage } from 'common/storage';
import { pubsub, type PubsubEvent, type PubsubCallback } from 'common/pubsub';
import { alert } from 'common/dialog';
import { api } from 'api';

export default class ChatCtrl {
data: ChatData;
Expand Down Expand Up @@ -103,7 +102,7 @@ export default class ChatCtrl {
alert('Max length: 140 chars. ' + text.length + ' chars used.');
return false;
}
api.chat.post(text);
pubsub.emit('socket.send', 'talk', text);
return true;
};

Expand Down
4 changes: 2 additions & 2 deletions ui/chat/src/moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { ModerationCtrl, ModerationOpts, ModerationData, ModerationReason }
import { numberFormat } from 'common/number';
import { userModInfo, flag, timeout } from './xhr';
import type ChatCtrl from './ctrl';
import { pubsub, initializeDom } from 'common/pubsub';
import { pubsub } from 'common/pubsub';
import { confirm } from 'common/dialog';

export function moderationCtrl(opts: ModerationOpts): ModerationCtrl {
Expand Down Expand Up @@ -158,7 +158,7 @@ export function moderationView(ctrl?: ModerationCtrl): VNode[] | undefined {
{
hook: {
insert() {
initializeDom();
pubsub.emit('content-loaded');
},
},
},
Expand Down
4 changes: 0 additions & 4 deletions ui/common/src/pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ export class Pubsub {

export const pubsub: Pubsub = new Pubsub();

export function initializeDom(root?: HTMLElement): void {
pubsub.emit('content-loaded', root);
}

interface OneTimeHandler {
promise: Promise<void>;
resolve?: () => void;
Expand Down
6 changes: 3 additions & 3 deletions ui/lobby/src/lobby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as xhr from 'common/xhr';
import main from './main';
import type { LobbyOpts } from './interfaces';
import { wsConnect, wsPingInterval } from 'common/socket';
import { pubsub, initializeDom } from 'common/pubsub';
import { pubsub } from 'common/pubsub';

export function initModule(opts: LobbyOpts) {
opts.appElement = document.querySelector('.lobby__app') as HTMLElement;
Expand Down Expand Up @@ -35,12 +35,12 @@ export function initModule(opts: LobbyOpts) {
reload_timeline() {
xhr.text('/timeline').then(html => {
$('.timeline').html(html);
initializeDom();
pubsub.emit('content-loaded');
});
},
featured(o: { html: string }) {
$('.lobby__tv').html(o.html);
initializeDom();
pubsub.emit('content-loaded');
},
redirect(e: RedirectTo) {
lobbyCtrl.setRedirecting();
Expand Down
4 changes: 2 additions & 2 deletions ui/mod/src/mod.user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tablesort from 'tablesort';
import { expandCheckboxZone, shiftClickCheckboxRange, selector } from './checkBoxes';
import { spinnerHtml } from 'common/spinner';
import { confirm } from 'common/dialog';
import { initializeDom } from 'common/pubsub';
import { pubsub } from 'common/pubsub';

site.load.then(() => {
const $toggle = $('.mod-zone-toggle'),
Expand Down Expand Up @@ -64,7 +64,7 @@ site.load.then(() => {
const getLocationHash = (a: HTMLAnchorElement) => a.href.replace(/.+(#\w+)$/, '$1');

function userMod($inZone: Cash) {
initializeDom($inZone[0]);
pubsub.emit('content-loaded', $inZone[0]);

const makeReady = (selector: string, f: (el: HTMLElement, i: number) => void, cls = 'ready') => {
$inZone.find(selector + `:not(.${cls})`).each(function (this: HTMLElement, i: number) {
Expand Down
4 changes: 2 additions & 2 deletions ui/notify/src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { h, type VNode } from 'snabbdom';
import * as licon from 'common/licon';
import { spinnerVdom as spinner } from 'common/spinner';
import makeRenderers from './renderers';
import { initializeDom } from 'common/pubsub';
import { pubsub } from 'common/pubsub';

const renderers = makeRenderers();

Expand Down Expand Up @@ -74,7 +74,7 @@ function clickHook(f: () => void) {
};
}

const contentLoaded = (vnode: VNode) => initializeDom(vnode.elm as HTMLElement);
const contentLoaded = (vnode: VNode) => pubsub.emit('content-loaded', vnode.elm);

function recentNotifications(d: NotifyData, scrolling: boolean): VNode {
return h(
Expand Down
4 changes: 2 additions & 2 deletions ui/round/src/round.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { wsConnect, wsDestroy } from 'common/socket';
import { storage } from 'common/storage';
import { setClockWidget } from 'common/clock';
import { makeChat } from 'chat';
import { pubsub, initializeDom } from 'common/pubsub';
import { pubsub } from 'common/pubsub';
import { myUserId } from 'common';
import { alert } from 'common/dialog';

Expand Down Expand Up @@ -76,7 +76,7 @@ async function boot(
$meta.length && $('.game__meta').replaceWith($meta);
$('.crosstable').replaceWith($html.find('.crosstable'));
startTournamentClock();
initializeDom();
pubsub.emit('content-loaded');
});
},
tourStanding(s: TourPlayer[]) {
Expand Down
4 changes: 2 additions & 2 deletions ui/simul/src/simul.home.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { wsConnect } from 'common/socket';
import { pubsub, initializeDom } from 'common/pubsub';
import { pubsub } from 'common/pubsub';

site.load.then(() => {
wsConnect(`/socket/v5`, false, { params: { flag: 'simul' } });
pubsub.on('socket.in.reload', async () => {
const rsp = await fetch('/simul/reload');
const html = await rsp.text();
$('.simul-list__content').html(html);
initializeDom();
pubsub.emit('content-loaded');
});
});
4 changes: 2 additions & 2 deletions ui/site/src/announce.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { escapeHtml } from 'common';
import { initializeDom } from 'common/pubsub';
import { pubsub } from 'common/pubsub';

let timeout: Timeout | undefined;

Expand All @@ -25,7 +25,7 @@ const announce = (d: LichessAnnouncement) => {
const millis = d.date ? new Date(d.date).getTime() - Date.now() : 5000;
if (millis > 0) timeout = setTimeout(kill, millis);
else kill();
if (d.date) initializeDom();
if (d.date) pubsub.emit('content-loaded');
}
};

Expand Down
4 changes: 2 additions & 2 deletions ui/site/src/powertip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as licon from 'common/licon';
import { text as xhrText } from 'common/xhr';
import { requestIdleCallback, $as } from 'common';
import { spinnerHtml } from 'common/spinner';
import { initializeDom } from 'common/pubsub';
import { pubsub } from 'common/pubsub';

// Thanks Steven Benner! - adapted from https://github.com/stevenbenner/jquery-powertip

Expand All @@ -14,7 +14,7 @@ const onPowertipPreRender = (id: string, preload?: (url: string) => void) => (el
xhrText(url + '/mini').then(html => {
const el = document.getElementById(id) as HTMLElement;
el.innerHTML = html;
initializeDom(el);
pubsub.emit('content-loaded', el);
});
};

Expand Down
2 changes: 2 additions & 0 deletions ui/site/src/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { unload, redirect, reload } from './reload';
import announce from './announce';
import { displayLocale } from 'common/i18n';
import sound from './sound';
import { api } from 'api';

const site = window.site;
// site.load is initialized in site.inline.ts (body script)
Expand All @@ -26,3 +27,4 @@ site.reload = reload;
site.announce = announce;
site.sound = sound;
site.load.then(boot);
(window as any).lichess = api;

0 comments on commit 0067769

Please sign in to comment.