anki/ts/deck-options/DailyLimits.svelte
RumovZ cc929687ae
Deck-specific Limits (#1955)
* Add deck-specific limits to DeckNormal

* Add deck-specific limits to schema11

* Add DeckLimitsDialog

* deck_limits_qt6.py needs to be a symlink

* Clear duplicate deck setting keys on downgrade

* Export deck limits when exporting with scheduling

* Revert "deck_limits_qt6.py needs to be a symlink"

This reverts commit 4ee7be1e10c4e8c49bb20de3bf45ac18b5e2d4f6.

* Revert "Add DeckLimitsDialog"

This reverts commit eb0e2a62d33df0b518d9204a27b09e97966ce82a.

* Add day limits to DeckNormal

* Add deck and day limits mock to deck options

* Revert "Add deck and day limits mock to deck options"

This reverts commit 0775814989e8cb486483d06727b1af266bb4513a.

* Add Tabs component for daily limits

* Add borders to tabs component

* Revert "Add borders to tabs component"

This reverts commit aaaf5538932540f944d92725c63bb04cfe97ea14.

* Implement tabbed limits properly

* Add comment to translations

* Update rslib/src/decks/limits.rs

Co-authored-by: Damien Elmes <dae@users.noreply.github.com>

* Fix camel case in clear_other_duplicates()

* day_limit → current_limit

* Also import day limits

* Remember last used day limits

* Add day limits to schema 11

* Tweak comment (dae)

* Exclude day limit in export (dae)

* Tweak tab wording (dae)

* Update preset limits on preset change

* Explain tabs in tooltip (dae)

* Omit deck and today limits if v2 is enabled

* Preserve deck limit when switching to today limit
2022-07-19 18:27:25 +10:00

160 lines
5.0 KiB
Svelte

<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="ts">
import DynamicallySlottable from "../components/DynamicallySlottable.svelte";
import Item from "../components/Item.svelte";
import * as tr from "../lib/ftl";
import type { DeckOptionsState } from "./lib";
import { ValueTab } from "./lib";
import SpinBoxRow from "./SpinBoxRow.svelte";
import TabbedValue from "./TabbedValue.svelte";
import TitledContainer from "./TitledContainer.svelte";
import Warning from "./Warning.svelte";
export let state: DeckOptionsState;
export let api: Record<string, never>;
export function onPresetChange() {
newTabs[0] = new ValueTab(
tr.deckConfigSharedPreset(),
$config.newPerDay,
(value) => ($config.newPerDay = value!),
$config.newPerDay,
null,
);
reviewTabs[0] = new ValueTab(
tr.deckConfigSharedPreset(),
$config.reviewsPerDay,
(value) => ($config.reviewsPerDay = value!),
$config.reviewsPerDay,
null,
);
}
const config = state.currentConfig;
const limits = state.deckLimits;
const defaults = state.defaults;
const parentLimits = state.parentLimits;
const v3Extra = state.v3Scheduler
? "\n\n" +
tr.deckConfigLimitNewBoundByReviews() +
"\n\n" +
tr.deckConfigLimitInterdayBoundByReviews() +
"\n\n" +
tr.deckConfigLimitDeckV3() +
"\n\n" +
tr.deckConfigTabDescription()
: "";
$: newCardsGreaterThanParent =
!state.v3Scheduler && newValue > $parentLimits.newCards
? tr.deckConfigDailyLimitWillBeCapped({ cards: $parentLimits.newCards })
: "";
$: reviewsTooLow =
Math.min(9999, newValue * 10) > reviewsValue
? tr.deckConfigReviewsTooLow({
cards: newValue,
expected: Math.min(9999, newValue * 10),
})
: "";
const newTabs: ValueTab[] = [
new ValueTab(
tr.deckConfigSharedPreset(),
$config.newPerDay,
(value) => ($config.newPerDay = value!),
$config.newPerDay,
null,
),
].concat(
state.v3Scheduler
? [
new ValueTab(
tr.deckConfigDeckOnly(),
$limits.new ?? null,
(value) => ($limits.new = value),
null,
null,
),
new ValueTab(
tr.deckConfigTodayOnly(),
$limits.newTodayActive ? $limits.newToday ?? null : null,
(value) => ($limits.newToday = value),
null,
$limits.newToday ?? null,
),
]
: [],
);
const reviewTabs: ValueTab[] = [
new ValueTab(
tr.deckConfigSharedPreset(),
$config.reviewsPerDay,
(value) => ($config.reviewsPerDay = value!),
$config.reviewsPerDay,
null,
),
].concat(
state.v3Scheduler
? [
new ValueTab(
tr.deckConfigDeckOnly(),
$limits.review ?? null,
(value) => ($limits.review = value),
null,
null,
),
new ValueTab(
tr.deckConfigTodayOnly(),
$limits.reviewTodayActive ? $limits.reviewToday ?? null : null,
(value) => ($limits.reviewToday = value),
null,
$limits.reviewToday ?? null,
),
]
: [],
);
let reviewsValue: number;
let newValue: number;
</script>
<TitledContainer title={tr.deckConfigDailyLimits()}>
<DynamicallySlottable slotHost={Item} {api}>
<TabbedValue tabs={newTabs} bind:value={newValue} />
<Item>
<SpinBoxRow
bind:value={newValue}
defaultValue={defaults.newPerDay}
markdownTooltip={tr.deckConfigNewLimitTooltip() + v3Extra}
>
{tr.schedulingNewCardsday()}
</SpinBoxRow>
</Item>
<Item>
<Warning warning={newCardsGreaterThanParent} />
</Item>
<TabbedValue tabs={reviewTabs} bind:value={reviewsValue} />
<Item>
<SpinBoxRow
bind:value={reviewsValue}
defaultValue={defaults.reviewsPerDay}
markdownTooltip={tr.deckConfigReviewLimitTooltip() + v3Extra}
>
{tr.schedulingMaximumReviewsday()}
</SpinBoxRow>
</Item>
<Item>
<Warning warning={reviewsTooLow} />
</Item>
</DynamicallySlottable>
</TitledContainer>