more ui/analyse rewrite

pull/3211/head
Thibault Duplessis 2017-06-28 15:47:14 +02:00
parent 6321032778
commit 4513519cc0
5 changed files with 36 additions and 26 deletions

View File

@ -1,6 +1,7 @@
import { Player, Status, Source } from 'game';
import * as cg from 'chessground/types';
import { Goal as PracticeGoal } from './study/practice/interfaces';
import { SocketSend } from './socket';
export type MaybeVNode = VNode | null | undefined;
export type MaybeVNodes = MaybeVNode[]
@ -61,8 +62,6 @@ export interface AnalysisSide {
blunder: number;
}
export type SocketSend = (type: string, data?: any) => void;
export interface AnalyseOpts {
element: HTMLElement;
sideElement: HTMLElement;

View File

@ -19,6 +19,7 @@ interface Req {
}
export interface Socket {
send: SocketSend;
receive(type: string, data: any): boolean;
sendAnaMove(req: Req): void;
sendAnaDrop(req: Req): void;
@ -27,7 +28,9 @@ export interface Socket {
clearCache(): void;
}
export function make(send, ctrl: AnalyseController): Socket {
export type SocketSend = (type: string, data?: any) => void;
export function make(send: SocketSend, ctrl: AnalyseController): Socket {
let anaMoveTimeout;
let anaDestsTimeout;
@ -157,6 +160,7 @@ export function make(send, ctrl: AnalyseController): Socket {
sendAnaDrop,
sendAnaDests,
sendForecasts(req) { send('forecasts', req); },
clearCache
clearCache,
send
};
}

View File

@ -22,3 +22,5 @@ export type StudyMember = any;
export interface StudyMemberMap {
[id: string]: StudyMember;
}
export type TagTypes = string[];

View File

@ -1,33 +1,34 @@
var m = require('mithril');
var throttle = require('common').throttle;
var memberCtrl = require('./studyMembers').ctrl;
var chapterCtrl = require('./studyChapters').ctrl;
var practiceCtrl = require('./practice/studyPracticeCtrl');
var commentFormCtrl = require('./commentForm').ctrl;
var glyphFormCtrl = require('./studyGlyph').ctrl;
var studyFormCtrl = require('./studyForm').ctrl;
var notifCtrl = require('./notif').ctrl;
var shareCtrl = require('./studyShare').ctrl;
var tagsCtrl = require('./studyTags').ctrl;
var tours = require('./studyTour');
var xhr = require('./studyXhr');
var treePath = require('tree').path;
import { throttle, prop } from 'common';
import AnalyseController from '../ctrl';
import { ctrl as memberCtrl } from './studyMembers';
import { ctrl as chapterCtrl } from './studyChapters';
import practiceCtrl from './practice/studyPracticeCtrl';
import { ctrl as commentFormCtrl } from './commentForm';
import { ctrl as glyphFormCtrl } from './studyGlyph';
import { ctrl as studyFormCtrl } from './studyForm';
import { ctrl as notifCtrl } from './notif';
import { ctrl as shareCtrl } from './studyShare';
import { ctrl as tagsCtrl } from './studyTags';
import * as tours from './studyTour';
import * as xhr from './studyXhr';
import { path as treePath } from 'tree';
import { TagTypes } from './interfaces';
// data.position.path represents the server state
// ctrl.path is the client state
module.exports = function(data, ctrl, tagTypes, practiceData) {
export default function(data, ctrl: AnalyseController, tagTypes: TagTypes, practiceData) {
var send = ctrl.socket.send;
const send = ctrl.socket.send;
var sri = lichess.StrongSocket && lichess.StrongSocket.sri;
const sri: string = window.lichess.StrongSocket.sri;
var vm = (function() {
var isManualChapter = data.chapter.id !== data.position.chapterId;
var sticked = data.features.sticky && !ctrl.vm.initialPath && !isManualChapter && !practiceData;
const isManualChapter = data.chapter.id !== data.position.chapterId;
const sticked = data.features.sticky && !ctrl.initialPath && !isManualChapter && !practiceData;
return {
loading: false,
nextChapterId: false,
tab: m.prop(data.chapters.length > 1 ? 'chapters' : 'members'),
tab: prop(data.chapters.length > 1 ? 'chapters' : 'members'),
chapterId: sticked ? data.position.chapterId : data.chapter.id,
// path is at ctrl.vm.path
mode: {
@ -38,10 +39,11 @@ module.exports = function(data, ctrl, tagTypes, practiceData) {
};
})();
var notif = notifCtrl();
const notif = notifCtrl(ctrl.redraw);
var form = studyFormCtrl(function(d, isNew) {
send("editStudy", d);
if (isNew && data.chapter.setup.variant.key === 'standard' && ctrl.vm.mainline.length === 1 && !data.chapter.setup.fromFen)
if (isNew && data.chapter.setup.variant.key === 'standard' && ctrl.mainline.length === 1 && !data.chapter.setup.fromFen)
chapters.newForm.openInitial();
}, function() {
return data;

View File

@ -24,6 +24,9 @@ interface Lichess {
sound: any
powertip: any
userAutocomplete: any
StrongSocket: {
sri: string
}
}
interface AssetUrlOpts {