Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/coreI18n/src/main/key.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2124,6 +2124,7 @@ object I18nKey:
val `keyShowOrHideComments`: I18nKey = "keyShowOrHideComments"
val `keyEnterOrExitVariation`: I18nKey = "keyEnterOrExitVariation"
val `keyRequestComputerAnalysis`: I18nKey = "keyRequestComputerAnalysis"
val `keyRequestComputerAnalysisStudyVersion`: I18nKey = "keyRequestComputerAnalysisStudyVersion"
val `keyPreviousBranch`: I18nKey = "keyPreviousBranch"
val `keyNextBranch`: I18nKey = "keyNextBranch"
val `toggleVariationArrows`: I18nKey = "toggleVariationArrows"
Expand Down
6 changes: 5 additions & 1 deletion modules/web/src/main/ui/help.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ object help:
row(kbd("z"), trans.site.toggleAllAnalysis()),
row(kbd("a"), trans.site.bestMoveArrow()),
row(kbd("v"), trans.site.toggleVariationArrows()),
row(kbd("r"), trans.site.keyRequestComputerAnalysis()),
row(
kbd("r"),
if isStudy then trans.site.keyRequestComputerAnalysisStudyVersion()
else trans.site.keyRequestComputerAnalysis()
),
row(kbd("c"), trans.site.focusChat()),
helpDialog,
row(kbd("e"), trans.site.openingEndgameExplorer()),
Expand Down
1 change: 1 addition & 0 deletions translation/source/site.xml
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@
<string name="keyShowOrHideComments">show/hide comments</string>
<string name="keyEnterOrExitVariation">enter/exit variation</string>
<string name="keyRequestComputerAnalysis">Request computer analysis, Learn from your mistakes</string>
<string name="keyRequestComputerAnalysisStudyVersion">Request computer analysis</string>
<string name="keyPreviousBranch">Previous branch</string>
<string name="keyNextBranch">Next branch</string>
<string name="toggleVariationArrows">Toggle variation arrows</string>
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 @@ -3723,6 +3723,8 @@ interface I18n {
keyPreviousBranch: string;
/** Request computer analysis, Learn from your mistakes */
keyRequestComputerAnalysis: string;
/** Request computer analysis */
keyRequestComputerAnalysisStudyVersion: string;
/** show/hide comments */
keyShowOrHideComments: string;
/** Kid mode */
Expand Down
27 changes: 18 additions & 9 deletions ui/analyse/src/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { snabDialog } from 'lib/view';
import type { VNode } from 'snabbdom';
import { pubsub } from 'lib/pubsub';

export const keyToMouseEvent = (key: string, eventName: string, selector: string) =>
export const keyToMouseEvent = (key: string, eventName: string, selector: string, bubbles?: boolean) =>
window.site.mousetrap.bind(key, () =>
$(selector).each(function (this: HTMLElement) {
this.dispatchEvent(new MouseEvent(eventName));
this.dispatchEvent(new MouseEvent(eventName, { bubbles }));
}),
);

Expand Down Expand Up @@ -99,14 +99,23 @@ export const bind = (ctrl: AnalyseCtrl) => {
ctrl.redraw();
});

//'Request computer analysis' & 'Learn From Your Mistakes' (mutually exclusive)
keyToMouseEvent(
'r',
'click',
'.analyse__underboard__panels .computer-analysis button, .analyse__round-training .advice-summary a.button',
);
if (ctrl.study)
kbd.bind('r', () => {
ctrl.study?.vm.toolTab('serverEval');
ctrl.study?.serverEval.request();
ctrl.redraw();
});
else {
keyToMouseEvent('r', 'click', '.analyse__underboard__menu .computer-analysis', true);
keyToMouseEvent(
'r',
'click',
// 'request computer analysis' & 'learn From your mistakes' use cases are mutually exclusive:
'.analyse__underboard__panels .computer-analysis button, .analyse__round-training .advice-summary a.button',
);
}

//First explorer move
// First explorer move
kbd.bind('shift+space', () => {
const move = document
.querySelector('.explorer-box:not(.loading) tbody tr[data-uci]')
Expand Down
26 changes: 18 additions & 8 deletions ui/analyse/src/study/serverEval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ export default class ServerEval {
};

request = () => {
if (
!longEnoughForAnalysis(this) ||
!userHasAnalysisRequestPermission(this) ||
!this.root.showFishnetAnalysis() ||
this.root.data.analysis ||
this.requested
)
return;
this.root.socket.send('requestAnalysis', this.chapterId());
this.requested = true;
};
Expand Down Expand Up @@ -66,24 +74,26 @@ const disabled = () => h('div.study__server-eval.disabled.padded', 'You disabled

const requested = () => h('div.study__server-eval.requested.padded', spinnerVdom());

function requestButton(ctrl: ServerEval) {
const root = ctrl.root;
return h(
const longEnoughForAnalysis = (ctrl: ServerEval) => ctrl.root.mainline.length >= 5;

const userHasAnalysisRequestPermission = (ctrl: ServerEval) => ctrl.root.study!.members.canContribute();

const requestButton = (ctrl: ServerEval) =>
h(
'div.study__message',
root.mainline.length < 5
!longEnoughForAnalysis(ctrl)
? h('p', i18n.study.theChapterIsTooShortToBeAnalysed)
: !root.study!.members.canContribute()
: !userHasAnalysisRequestPermission(ctrl)
? [i18n.study.onlyContributorsCanRequestAnalysis]
: [
h('p', [i18n.study.getAFullComputerAnalysis, h('br'), i18n.study.makeSureTheChapterIsComplete]),
h(
'a.button.text',
{
attrs: { 'data-icon': licon.BarChart, disabled: root.mainline.length < 5 },
hook: bind('click', ctrl.request, root.redraw),
attrs: { 'data-icon': licon.BarChart },
hook: bind('click', ctrl.request, ctrl.root.redraw),
},
i18n.site.requestAComputerAnalysis,
),
],
);
}
Loading