Anki/ts/deck-options/LapseOptions.svelte
RumovZ 850043b49b
Tooltips for CSV import and import page refactoring (#2655)
* Make enum selector generic

* Refactor ImportCsvPage to support tooltips

* Improve csv import defaults

* Unify import pages

* Improve import page styling

* Fix life cycle issue with import properties

* Remove size constraints to fix scrollbar styling

* Add help strings and urls to csv import page

* Show ErrorPage on ImportPage error

* Fix escaping of import path

* Unify ImportPage and ImportLogPage

* Apply suggestions from code review (dae)

* Fix import progress

* Fix preview overflowing container

* Don't include <br> in FileIoErrors (dae)

e.g. 500: Failed to read '/home/dae/foo2.csv':<br>stream did not contain valid UTF-8

I thought about using {@html ...} here, but that's a potential security issue,
as the filename is not something we control.
2023-09-14 09:06:15 +10:00

150 lines
5 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 * as tr from "@tslib/ftl";
import { HelpPage } from "@tslib/help-page";
import type Carousel from "bootstrap/js/dist/carousel";
import type Modal from "bootstrap/js/dist/modal";
import DynamicallySlottable from "../components/DynamicallySlottable.svelte";
import EnumSelectorRow from "../components/EnumSelectorRow.svelte";
import HelpModal from "../components/HelpModal.svelte";
import Item from "../components/Item.svelte";
import SettingTitle from "../components/SettingTitle.svelte";
import TitledContainer from "../components/TitledContainer.svelte";
import type { HelpItem } from "../components/types";
import { leechChoices } from "./choices";
import type { DeckOptionsState } from "./lib";
import SpinBoxRow from "./SpinBoxRow.svelte";
import StepsInputRow from "./StepsInputRow.svelte";
import Warning from "./Warning.svelte";
export let state: DeckOptionsState;
export let api = {};
const config = state.currentConfig;
const defaults = state.defaults;
let stepsExceedMinimumInterval: string;
$: {
const lastRelearnStepInDays = $config.relearnSteps.length
? $config.relearnSteps[$config.relearnSteps.length - 1] / 60 / 24
: 0;
stepsExceedMinimumInterval =
lastRelearnStepInDays > $config.minimumLapseInterval
? tr.deckConfigRelearningStepsAboveMinimumInterval()
: "";
}
const settings = {
relearningSteps: {
title: tr.deckConfigRelearningSteps(),
help: tr.deckConfigRelearningStepsTooltip(),
url: HelpPage.DeckOptions.relearningSteps,
},
minimumInterval: {
title: tr.schedulingMinimumInterval(),
help: tr.deckConfigMinimumIntervalTooltip(),
url: HelpPage.DeckOptions.minimumInterval,
},
leechThreshold: {
title: tr.schedulingLeechThreshold(),
help: tr.deckConfigLeechThresholdTooltip(),
url: HelpPage.Leeches.leeches,
},
leechAction: {
title: tr.schedulingLeechAction(),
help: tr.deckConfigLeechActionTooltip(),
url: HelpPage.Leeches.waiting,
},
};
const helpSections = Object.values(settings) as HelpItem[];
let modal: Modal;
let carousel: Carousel;
function openHelpModal(index: number): void {
modal.show();
carousel.to(index);
}
</script>
<TitledContainer title={tr.schedulingLapses()}>
<HelpModal
title={tr.schedulingLapses()}
url={HelpPage.DeckOptions.lapses}
slot="tooltip"
{helpSections}
on:mount={(e) => {
modal = e.detail.modal;
carousel = e.detail.carousel;
}}
/>
<DynamicallySlottable slotHost={Item} {api}>
<Item>
<StepsInputRow
bind:value={$config.relearnSteps}
defaultValue={defaults.relearnSteps}
>
<SettingTitle
on:click={() =>
openHelpModal(Object.keys(settings).indexOf("relearningSteps"))}
>
{settings.relearningSteps.title}
</SettingTitle>
</StepsInputRow>
</Item>
<Item>
<SpinBoxRow
bind:value={$config.minimumLapseInterval}
defaultValue={defaults.minimumLapseInterval}
min={1}
>
<SettingTitle
on:click={() =>
openHelpModal(Object.keys(settings).indexOf("minimumInterval"))}
>
{settings.minimumInterval.title}
</SettingTitle>
</SpinBoxRow>
</Item>
<Item>
<Warning warning={stepsExceedMinimumInterval} />
</Item>
<Item>
<SpinBoxRow
bind:value={$config.leechThreshold}
defaultValue={defaults.leechThreshold}
min={1}
>
<SettingTitle
on:click={() =>
openHelpModal(Object.keys(settings).indexOf("leechThreshold"))}
>
{settings.leechThreshold.title}
</SettingTitle>
</SpinBoxRow>
</Item>
<Item>
<EnumSelectorRow
bind:value={$config.leechAction}
defaultValue={defaults.leechAction}
choices={leechChoices()}
breakpoint="md"
>
<SettingTitle
on:click={() =>
openHelpModal(Object.keys(settings).indexOf("leechAction"))}
>
{settings.leechAction.title}
</SettingTitle>
</EnumSelectorRow>
</Item>
</DynamicallySlottable>
</TitledContainer>