lichess.annouce failed dasher xhr

pull/6291/head
Niklas Fiekas 2020-04-04 13:28:23 +02:00
parent 498f7551a9
commit 19ccdd878b
5 changed files with 13 additions and 10 deletions

View File

@ -31,20 +31,22 @@ export function ctrl(data: BackgroundData, trans: Trans, redraw: Redraw, close:
{ key: 'transp', name: trans.noarg('transparent') }
];
const announceFail = () => window.lichess.announce({msg: 'Failed to save background preference'});
return {
list,
trans,
get: () => data.current,
set(c: string) {
data.current = c;
$.post('/pref/bg', { bg: c }, reloadAllTheThings);
$.post('/pref/bg', { bg: c }, reloadAllTheThings).fail(announceFail);
applyBackground(data, list);
redraw();
},
getImage: () => data.image,
setImage(i: string) {
data.image = i;
$.post('/pref/bgImg', { bgImg: i }, reloadAllTheThings);
$.post('/pref/bgImg', { bgImg: i }, reloadAllTheThings).fail(announceFail);
applyBackground(data, list);
redraw();
},

View File

@ -23,7 +23,10 @@ export function ctrl(data: BoardData, trans: Trans, redraw: Redraw, close: Close
const readZoom = () => parseInt(getComputedStyle(document.body).getPropertyValue('--zoom')) + 100;
const saveZoom = window.lichess.debounce(() => {
$.ajax({ method: 'post', url: '/pref/zoom?v=' + readZoom() });
$.ajax({
method: 'post',
url: '/pref/zoom?v=' + readZoom()
}).fail(() => window.lichess.announce({msg: 'Failed to save zoom'}));
}, 1000);
return {
@ -31,7 +34,7 @@ export function ctrl(data: BoardData, trans: Trans, redraw: Redraw, close: Close
trans,
setIs3d(v: boolean) {
data.is3d = v;
$.post('/pref/is3d', { is3d: v }, window.lichess.reload);
$.post('/pref/is3d', { is3d: v }, window.lichess.reload).fail(() => window.lichess.announce({msg: 'Failed to save geometry preference'}));
redraw();
},
readZoom,

View File

@ -39,7 +39,7 @@ export function ctrl(data: PieceData, trans: Trans, dimension: () => keyof Piece
applyPiece(t, d.list, dimension() === 'd3');
$.post('/pref/pieceSet' + (dimension() === 'd3' ? '3d' : ''), {
set: t
});
}).fail(() => window.lichess.announce({msg: 'Failed to save piece set preference'}));
redraw();
},
open

View File

@ -41,7 +41,7 @@ export function ctrl(raw: string[], trans: Trans, redraw: Redraw, close: Close):
else {
api.changeSet(k);
api.genericNotify();
$.post('/pref/soundSet', { set: k });
$.post('/pref/soundSet', { set: k }).fail(() => window.lichess.announce({msg: 'Failed to save sound preference'}));
}
redraw();
},
@ -70,9 +70,7 @@ export function view(ctrl: SoundCtrl): VNode {
header(ctrl.trans('sound'), ctrl.close),
h('div.content', [
h('div.slider', { hook: { insert: vn => makeSlider(ctrl, vn) } }),
h('div.selector', {
attrs: { method: 'post', action: '/pref/soundSet' }
}, ctrl.makeList().map(soundView(ctrl, current)))
h('div.selector', ctrl.makeList().map(soundView(ctrl, current)))
])
]);
}

View File

@ -39,7 +39,7 @@ export function ctrl(data: ThemeData, trans: Trans, dimension: () => keyof Theme
applyTheme(t, d.list);
$.post('/pref/theme' + (dimension() === 'd3' ? '3d' : ''), {
theme: t
});
}).fail(() => window.lichess.announce({msg: 'Failed to save theme preference'}));
redraw();
},
open