From cf74625bfc436f60db487f8264a35436210208bc Mon Sep 17 00:00:00 2001 From: Kendall Garner <17521368+kgarner7@users.noreply.github.com> Date: Sun, 18 May 2025 10:59:45 -0700 Subject: [PATCH] warn if a value in select no longer exists --- src/i18n/locales/en.json | 1 + .../select-with-invalid-data/index.tsx | 78 +++++++++++++++++++ src/renderer/components/select/index.tsx | 2 +- .../components/navidrome-album-filters.tsx | 9 ++- .../components/jellyfin-song-filters.tsx | 7 +- .../components/navidrome-song-filters.tsx | 7 +- 6 files changed, 93 insertions(+), 11 deletions(-) create mode 100644 src/renderer/components/select-with-invalid-data/index.tsx diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 5d3a21a6..6154d651 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -160,6 +160,7 @@ "audioDeviceFetchError": "an error occurred when trying to get audio devices", "authenticationFailed": "authentication failed", "badAlbum": "you are seeing this page because this song is not part of an album. you are most likely seeing this issue if you have a song at the top level of your music folder. jellyfin only groups tracks if they are in a folder.", + "badValue": "invalid option \"{{value}}\". this value no longer exists", "credentialsRequired": "credentials required", "endpointNotImplementedError": "endpoint {{endpoint}} is not implemented for {{serverType}}", "genericError": "an error occurred", diff --git a/src/renderer/components/select-with-invalid-data/index.tsx b/src/renderer/components/select-with-invalid-data/index.tsx new file mode 100644 index 00000000..46053094 --- /dev/null +++ b/src/renderer/components/select-with-invalid-data/index.tsx @@ -0,0 +1,78 @@ +import { MultiSelect, MultiSelectProps, Select, SelectProps } from '/@/renderer/components/select'; +import { useTranslation } from 'react-i18next'; +import { useMemo } from 'react'; + +export const SelectWithInvalidData = ({ data, defaultValue, ...props }: SelectProps) => { + const { t } = useTranslation(); + + const [fullData, hasError] = useMemo(() => { + if (typeof defaultValue === 'string') { + const missingField = + data.find((item) => + typeof item === 'string' ? item === defaultValue : item.value === defaultValue, + ) === undefined; + + if (missingField) { + return [data.concat(defaultValue), true]; + } + } + + return [data, false]; + }, [data, defaultValue]); + + return ( + - ; @@ -201,7 +202,7 @@ export const JellyfinSongFilters = ({ {!isGenrePage && ( - - ; @@ -149,7 +150,7 @@ export const NavidromeSongFilters = ({ onChange={(e) => handleYearFilter(e)} /> {!isGenrePage && ( -