From 2580399552f81cc56f8e4183b2e3b274ae9c3fc2 Mon Sep 17 00:00:00 2001 From: Michael Eliachevitch Date: Wed, 27 Sep 2023 08:12:49 +0200 Subject: [PATCH] Button to set desired FSRS retention to optimal/calculated (#2685) * Draft set optimal/calculated retention button Temporarily save the calculated optimal retention and display it with a button that sets the desired retention above to this value.Don't show button until attention had been calculated. Disable button when optimal and desired attention are equal. I find this nicer than the current alert-popup solution, as it avoids a popup and gives a choice to the user to accept the calculated retention or not, while also persisting the calculated retention on the screen for a bit. TODO: What's still missing is that the `optimalRetention` variable is global and persists when I change presets. When changing presets the variable should reset to `undefined`, which would also makes the button disappear. Ideally it should also disappear when changing the FSRS parameters. So probably it should be made part of some deck options state and subscribe to some events. But with that I might need some help. Also I thought whether that variable should go into the deck options schema but tbh it's not something we want to persist between sessions, users should recalculate it. * Add me to contributors for tests so pass * Add formatting ant type fixes to make tests pass * Minor fixes (dae) * Remove the period --- ftl/core/deck-config.ftl | 2 +- ts/deck-options/FsrsOptions.svelte | 35 +++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/ftl/core/deck-config.ftl b/ftl/core/deck-config.ftl index f7c7ff950..3bf817754 100644 --- a/ftl/core/deck-config.ftl +++ b/ftl/core/deck-config.ftl @@ -337,7 +337,7 @@ deck-config-get-params = Get Params deck-config-fsrs-on-all-clients = Please ensure all of your Anki clients are Anki(Mobile) 23.10+ or AnkiDroid 2.17+. FSRS will not work correctly if one of your clients is older. -deck-config-your-optimal-retention = Your optimal retention is { $num }. +deck-config-set-optimal-retention = Set desired retention to { $num } ## NO NEED TO TRANSLATE. This text is no longer used by Anki, and will be removed in the future. diff --git a/ts/deck-options/FsrsOptions.svelte b/ts/deck-options/FsrsOptions.svelte index 7a33b7780..610d483b3 100644 --- a/ts/deck-options/FsrsOptions.svelte +++ b/ts/deck-options/FsrsOptions.svelte @@ -33,6 +33,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html let computingWeights = false; let checkingWeights = false; let computingRetention = false; + let optimalRetention = 0; + $: if ($presetName) { + optimalRetention = 0; + } $: computing = computingWeights || checkingWeights || computingRetention; $: customSearch = `preset:"${$presetName}"`; @@ -136,11 +140,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html optimalRetentionRequest.weights = $config.fsrsWeights; optimalRetentionRequest.search = `preset:"${state.getCurrentName()}"`; const resp = await computeOptimalRetention(optimalRetentionRequest); - alert( - tr.deckConfigYourOptimalRetention({ - num: resp.optimalRetention, - }), - ); + optimalRetention = resp.optimalRetention; if (computeRetentionProgress) { computeRetentionProgress.current = computeRetentionProgress.total; @@ -184,6 +184,20 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html const pct = ((val.current / val.total) * 100).toFixed(0); return `${pct}%`; } + + function stringForSetOptimalRetention(retention: number): String { + if (!retention) { + return ""; + } + return tr.deckConfigSetOptimalRetention({ num: retention.toFixed(2) }); + } + + function setDesiredRetentionToOptimal() { + if (!optimalRetention) { + return; + } + $config.desiredRetention = optimalRetention; + } + + {#if optimalRetention} + + {/if}
{computeRetentionProgressString}