Move zoom pref to separate cookie (#9675)
* Move zoom pref to separate cookie * zoom cookie: Fix maxAge * Fallback to old zoom value from session cookiemodGoal^2
parent
565edbe8e1
commit
7e7a8a6dd3
|
@ -52,7 +52,7 @@ final class Pref(env: Env) extends LilaController(env) {
|
|||
def set(name: String) =
|
||||
OpenBody { implicit ctx =>
|
||||
if (name == "zoom") {
|
||||
Ok.withCookies(env.lilaCookie.session("zoom2", (getInt("v") | 185).toString)).fuccess
|
||||
Ok.withCookies(env.lilaCookie.cookie("zoom", (getInt("v") | 85).toString)).fuccess
|
||||
} else {
|
||||
implicit val req = ctx.body
|
||||
(setters get name) ?? { case (form, fn) =>
|
||||
|
|
|
@ -78,7 +78,8 @@ sealed trait Context extends lila.user.UserContextWrapper {
|
|||
def requiresFingerprint = isAuth && !pageData.hasFingerprint
|
||||
|
||||
def zoom: Int = {
|
||||
req.session get "zoom2" flatMap (_.toIntOption) map (_ - 100) filter (0 <=) filter (100 >=)
|
||||
def oldZoom = req.session get "zoom2" flatMap (_.toIntOption) map (_ - 100)
|
||||
req.cookies get "zoom" map (_.value) flatMap (_.toIntOption) orElse oldZoom filter (0 <=) filter (100 >=)
|
||||
} | 85
|
||||
|
||||
def flash(name: String): Option[String] = req.flash get name
|
||||
|
|
|
@ -21,7 +21,7 @@ export default function resizeHandle(els: cg.Elements, pref: Prefs.ShowResizeHan
|
|||
initialZoom = parseInt(getComputedStyle(document.body).getPropertyValue('--zoom'));
|
||||
let zoom = initialZoom;
|
||||
|
||||
const saveZoom = debounce(() => xhr.text(`/pref/zoom?v=${100 + zoom}`, { method: 'post' }), 700);
|
||||
const saveZoom = debounce(() => xhr.text(`/pref/zoom?v=${zoom}`, { method: 'post' }), 700);
|
||||
|
||||
const resize = (move: MouchEvent) => {
|
||||
const pos = eventPosition(move)!,
|
||||
|
|
|
@ -19,7 +19,7 @@ export interface BoardData {
|
|||
export type PublishZoom = (v: number) => void;
|
||||
|
||||
export function ctrl(data: BoardData, trans: Trans, redraw: Redraw, close: Close): BoardCtrl {
|
||||
const readZoom = () => parseInt(getComputedStyle(document.body).getPropertyValue('--zoom')) + 100;
|
||||
const readZoom = () => parseInt(getComputedStyle(document.body).getPropertyValue('--zoom'));
|
||||
|
||||
const saveZoom = debounce(
|
||||
() =>
|
||||
|
@ -44,7 +44,7 @@ export function ctrl(data: BoardData, trans: Trans, redraw: Redraw, close: Close
|
|||
},
|
||||
readZoom,
|
||||
setZoom(v: number) {
|
||||
document.body.setAttribute('style', '--zoom:' + (v - 100));
|
||||
document.body.setAttribute('style', '--zoom:' + v);
|
||||
window.dispatchEvent(new Event('resize'));
|
||||
redraw();
|
||||
saveZoom();
|
||||
|
@ -83,7 +83,7 @@ export function view(ctrl: BoardCtrl): VNode {
|
|||
isNaN(domZoom)
|
||||
? [h('p', 'No board to zoom here!')]
|
||||
: [
|
||||
h('p', [ctrl.trans.noarg('boardSize'), ': ', domZoom - 100, '%']),
|
||||
h('p', [ctrl.trans.noarg('boardSize'), ': ', domZoom, '%']),
|
||||
h('input.range', {
|
||||
attrs: {
|
||||
type: 'range',
|
||||
|
|
Loading…
Reference in New Issue