Skip to content

Commit 24762db

Browse files
committed
make game search a TS module
1 parent 8248aa7 commit 24762db

File tree

5 files changed

+28
-25
lines changed

5 files changed

+28
-25
lines changed

app/views/search/index.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object index {
2121
views.html.base.layout(
2222
title = searchInXGames.txt(nbGames.localize, nbGames),
2323
moreJs = frag(
24-
jsTag("search.js"),
24+
jsModule("game-search"),
2525
infiniteScrollTag
2626
),
2727
moreCss = cssTag("search")

app/views/user/show/page.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
package views.html.user.show
22

3+
import controllers.routes
34
import play.api.data.Form
45

56
import lila.api.Context
7+
import lila.app.mashup.UserInfo
68
import lila.app.mashup.UserInfo.Angle
79
import lila.app.templating.Environment._
810
import lila.app.ui.ScalatagsTemplate._
911
import lila.common.paginator.Paginator
10-
import lila.app.mashup.UserInfo
1112
import lila.game.Game
1213
import lila.user.User
1314

14-
import controllers.routes
15-
1615
object page {
1716

1817
def activity(
@@ -87,7 +86,7 @@ object page {
8786
embedJsUnsafeLoadThen(s"lichess.ratingHistoryChart($ratingChart);")
8887
)
8988
},
90-
withSearch option frag(jsTag("search.js")),
89+
withSearch option jsModule("game-search"),
9190
isGranted(_.UserSpy) option jsModule("mod.user")
9291
)
9392

ui/build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mkdir -p public/compiled
1616
apps1="common"
1717
apps2="chess ceval game tree chat nvui"
1818
apps3="site swiss msg chat cli challenge notify learn insight editor puzzle round analyse lobby tournament tournamentSchedule tournamentCalendar simul dasher speech palantir serviceWorker"
19-
site_plugins="tvEmbed puzzleEmbed analyseEmbed user modUser clas coordinate captcha expandText team forum account coachForm challengePage checkout login teamBattleForm dgt"
19+
site_plugins="tvEmbed puzzleEmbed analyseEmbed user modUser clas coordinate captcha expandText team forum account coachForm challengePage checkout login teamBattleForm dgt gameSearch"
2020
round_plugins="keyboardMove nvui"
2121
analyse_plugins="nvui"
2222

ui/site/rollup.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,9 @@ export default rollupProject({
153153
input: 'src/dgt/dgt.ts',
154154
output: 'dgt',
155155
name: 'lichessDgt'
156+
},
157+
gameSearch: {
158+
input: 'src/gameSearch.ts',
159+
output: 'game-search'
156160
}
157161
});
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
$(function() {
1+
window.lichess.load.then(() => {
22

3-
var $form = $(".search__form");
4-
var $usernames = $form.find(".usernames input");
5-
var $userRows = $form.find(".user-row");
6-
var $result = $(".search__result");
3+
const form = document.querySelector('.search__form') as HTMLFormElement,
4+
$form = $(form),
5+
$usernames = $form.find(".usernames input"),
6+
$userRows = $form.find(".user-row"),
7+
$result = $(".search__result");
78

89
function getUsernames() {
9-
var us = [];
10-
$usernames.each(function() {
11-
var u = $(this).val().trim();
10+
const us: string[] = [];
11+
$usernames.each(function(this: HTMLInputElement) {
12+
const u = this.value.trim();
1213
if (u) us.push(u);
1314
});
1415
return us;
@@ -21,7 +22,7 @@ $(function() {
2122
return (row.classList.contains(rowClassName) && player.length && user == player) ? "selected" : ""
2223
}
2324
getUsernames().forEach(function(user) {
24-
var option = [];
25+
const option: string[] = [];
2526
option.push("<option value='" + user + "'");
2627
option.push(isSelected(row, "winner", user, 'req-winner'));
2728
option.push(isSelected(row, "loser", user, 'req-loser'));
@@ -35,25 +36,24 @@ $(function() {
3536
}
3637

3738
function reloadUserChoices() {
38-
$userRows.each(function() {
39+
$userRows.each(function(this: HTMLTableRowElement) {
3940
userChoices(this);
4041
});
4142
}
4243
reloadUserChoices();
4344
$usernames.on("input paste", reloadUserChoices);
4445

4546
var toggleAiLevel = function() {
46-
$form.find(".opponent select").each(function() {
47-
$form[0].querySelector('.aiLevel')?.classList.toggle('none', $(this).val() != 1);
48-
$form[0].querySelector('.opponentName')?.classList.toggle('none', $(this).val() == 1);
47+
$form.find(".opponent select").each(function(this: HTMLSelectElement) {
48+
$form[0].querySelector('.aiLevel')?.classList.toggle('none', this.value != "1");
49+
$form[0].querySelector('.opponentName')?.classList.toggle('none', this.value == "1");
4950
});
5051
};
5152
toggleAiLevel();
5253
$form.find(".opponent select").change(toggleAiLevel);
5354

5455
function serialize() {
55-
const data = new FormData($form[0]),
56-
params = new URLSearchParams(data),
56+
const params = new URLSearchParams(new FormData(form) as any),
5757
keys = Array.from(params.keys());
5858
for (let k of keys) {
5959
if (params.get(k) == '') params.delete(k);
@@ -62,10 +62,10 @@ $(function() {
6262
}
6363

6464
const serialized = serialize();
65-
$result.find("a.permalink").each(function() {
65+
$result.find("a.permalink").each(function(this: HTMLAnchorElement) {
6666
$(this).attr("href", $(this).attr("href").split('?')[0] + "?" + serialized);
6767
});
68-
$result.find('.search__rows').each(function() {
68+
$result.find('.search__rows').each(function(this: HTMLTableRowElement) {
6969
var $next = $(this).find(".pager a");
7070
if (!$next.length) return;
7171
$next.attr("href", $next.attr("href") + "&" + serialized);
@@ -79,12 +79,12 @@ $(function() {
7979
}
8080
}, function() {
8181
$("#infscr-loading").remove();
82-
lichess.pubsub.emit('content_loaded');
82+
window.lichess.pubsub.emit('content_loaded');
8383
});
8484
});
8585

8686
$form.submit(function() {
87-
$form.find("input,select").filter(function() { return !this.value; }).attr("disabled", "disabled");
87+
$form.find("input,select").filter(function(this: HTMLInputElement) { return !this.value; }).attr("disabled", "disabled");
8888
$form.addClass('searching');
8989
});
9090
});

0 commit comments

Comments
 (0)