TS plugin for team page
parent
7b4eeb7f6f
commit
fac58b630a
|
@ -283,11 +283,11 @@ final class Team(
|
|||
|
||||
def subscribe(teamId: String) = {
|
||||
def doSub(req: Request[_], me: UserModel) =
|
||||
Form(single("v" -> boolean))
|
||||
Form(single("subscribe" -> optional(boolean)))
|
||||
.bindFromRequest()(req)
|
||||
.fold(_ => funit, v => api.subscribe(teamId, me.id, v))
|
||||
.fold(_ => funit, v => api.subscribe(teamId, me.id, ~v))
|
||||
AuthOrScopedBody(_.Team.Write)(
|
||||
auth = ctx => me => doSub(ctx.body, me) inject Redirect(routes.Team.show(teamId)),
|
||||
auth = ctx => me => doSub(ctx.body, me) inject jsonOkResult,
|
||||
scoped = req => me => doSub(req, me) inject jsonOkResult
|
||||
)
|
||||
}
|
||||
|
|
|
@ -38,8 +38,8 @@ object show {
|
|||
v <- socketVersion
|
||||
chat <- chatOption
|
||||
} yield frag(
|
||||
jsModule("chat"),
|
||||
embedJsUnsafeLoadThen(s"""const cfg=${safeJsonValue(
|
||||
jsModule("team"),
|
||||
embedJsUnsafeLoadThen(s"""teamStart(${safeJsonValue(
|
||||
Json.obj(
|
||||
"id" -> t.id,
|
||||
"socketVersion" -> v.value,
|
||||
|
@ -52,15 +52,7 @@ object show {
|
|||
localMod = ctx.userId exists t.leaders.contains
|
||||
)
|
||||
)
|
||||
)};
|
||||
lichess.socket = new lichess.StrongSocket('/team/${t.id}',${v.value});
|
||||
cfg.chat && lichess.makeChat(cfg.chat);
|
||||
$$('#team-subscribe').on('change', function() {
|
||||
const v = this.checked;
|
||||
$$(this).parents('form').each(function() {
|
||||
$$.post(this.action, { v });
|
||||
});
|
||||
})""")
|
||||
)})""")
|
||||
)
|
||||
) {
|
||||
val enabledOrLeader = t.enabled || info.ledByMe || isGranted(_.Admin)
|
||||
|
|
|
@ -51,7 +51,7 @@ interface Lichess {
|
|||
|
||||
// socket.js
|
||||
StrongSocket: {
|
||||
new(url: string, version: number | false, cfg: any): any;
|
||||
new(url: string, version: number | false, cfg?: any): any;
|
||||
firstConnect: Promise<(tpe: string, data: any) => void>
|
||||
}
|
||||
|
||||
|
|
2
ui/build
2
ui/build
|
@ -16,7 +16,7 @@ mkdir -p public/compiled
|
|||
apps1="common"
|
||||
apps2="chess ceval game tree chat nvui"
|
||||
apps3="site swiss msg chat cli challenge notify learn insight editor puzzle round analyse lobby tournament tournamentSchedule tournamentCalendar simul dasher speech palantir serviceWorker"
|
||||
site_plugins="tvEmbed puzzleEmbed analyseEmbed user modUser clas coordinate captcha expandText"
|
||||
site_plugins="tvEmbed puzzleEmbed analyseEmbed user modUser clas coordinate captcha expandText team"
|
||||
round_plugins="keyboardMove nvui"
|
||||
analyse_plugins="nvui"
|
||||
|
||||
|
|
|
@ -113,4 +113,9 @@ export default rollupProject({
|
|||
input: 'src/expand-text.ts',
|
||||
output: 'expand-text',
|
||||
},
|
||||
team: {
|
||||
input: 'src/team.ts',
|
||||
output: 'team',
|
||||
name: 'teamStart'
|
||||
}
|
||||
});
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
import * as xhr from 'common/xhr';
|
||||
import LichessChat from 'chat';
|
||||
|
||||
window.LichessChat = LichessChat;
|
||||
|
||||
interface TeamOpts {
|
||||
id: string;
|
||||
socketVersion: number;
|
||||
chat?: any;
|
||||
}
|
||||
|
||||
export default function(opts: TeamOpts) {
|
||||
|
||||
const li = window.lichess;
|
||||
|
||||
li.socket = new li.StrongSocket('/team/' + opts.id, opts.socketVersion);
|
||||
|
||||
if (opts.chat) window.lichess.makeChat(opts.chat);
|
||||
|
||||
$('#team-subscribe').on('change', function(this: HTMLInputElement) {
|
||||
$(this).parents('form').each(function(this: HTMLFormElement) {
|
||||
xhr.formToXhr(this);
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue