fix: add '0' shortcut for clearing ratings

pull/24620/head
cbochs 2025-12-16 07:44:46 -07:00
parent 6878d1a5b1
commit f4d9d715e8
No known key found for this signature in database
GPG Key ID: 5803BAE8E71DDC8E
1 changed files with 9 additions and 3 deletions

View File

@ -16,9 +16,9 @@
let { asset, onAction }: Props = $props();
const rateAsset = async (rating: number) => {
const rateAsset = async (rating: number | null) => {
try {
const updateAssetDto = { rating };
const updateAssetDto = rating === null ? {} : { rating };
await updateAsset({
id: asset.id,
@ -39,12 +39,17 @@
rating,
});
toastManager.success($t('rating_set', { values: { rating } }));
if (rating === null) {
toastManager.success($t('rating_clear'));
} else {
toastManager.success($t('rating_set', { values: { rating } }));
}
} catch (error) {
handleError(error, $t('errors.unable_to_set_rating'));
}
};
const onShortcut0 = () => rateAsset(null);
const onShortcut1 = () => rateAsset(1);
const onShortcut2 = () => rateAsset(2);
const onShortcut3 = () => rateAsset(3);
@ -55,6 +60,7 @@
<svelte:document
use:shortcuts={$preferences?.ratings.enabled
? [
{ shortcut: { key: '0' }, onShortcut: onShortcut0 },
{ shortcut: { key: '1' }, onShortcut: onShortcut1 },
{ shortcut: { key: '2' }, onShortcut: onShortcut2 },
{ shortcut: { key: '3' }, onShortcut: onShortcut3 },