Anki/ts/editor/PreviewButton.svelte
Hikaru Y 12ccdee25b
Fix some issues with closing previewer (#1563)
* Fix media playback not terminating when previewer is closed

https://forums.ankiweb.net/t/anki-2-1-50-beta/15608/78

* Fix _on_preview_closed being called twice unnecessarily

The function was being called twice when the preview button is clicked
while the previewer is open.

* Fix console error caused by leftover code

The following error was shown in the console when closing previewer:
`Uncaught TypeError: Cannot read property 'classList' of null`

* Toggle state of preview button via 'active' prop
2021-12-20 20:23:50 +10:00

30 lines
1,020 B
Svelte

<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script context="module" lang="ts">
import { writable } from "svelte/store";
const active = writable(false);
export const togglePreviewButtonState = (state: boolean) => active.set(state);
</script>
<script lang="ts">
import { bridgeCommand } from "../lib/bridgecommand";
import * as tr from "../lib/ftl";
import { withButton } from "../components/helpers";
import WithShortcut from "../components/WithShortcut.svelte";
import LabelButton from "../components/LabelButton.svelte";
</script>
<WithShortcut shortcut={"Control+Shift+P"} let:createShortcut let:shortcutLabel>
<LabelButton
tooltip={tr.browsingPreviewSelectedCard({ val: shortcutLabel })}
active={$active}
on:click={() => bridgeCommand("preview")}
on:mount={withButton(createShortcut)}
>
{tr.actionsPreview()}
</LabelButton>
</WithShortcut>