From 97db9ba713c122286a7b12190346937aab78fa4d Mon Sep 17 00:00:00 2001 From: Aj - Thomas Date: Fri, 6 May 2022 22:45:51 +0200 Subject: [PATCH 1/2] Conditional rendering when no API key provided --- components/calendar/CalendarComponent.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/calendar/CalendarComponent.tsx b/components/calendar/CalendarComponent.tsx index e6fe567d9..58c7c52ca 100644 --- a/components/calendar/CalendarComponent.tsx +++ b/components/calendar/CalendarComponent.tsx @@ -1,5 +1,5 @@ /* eslint-disable react/no-children-prop */ -import { Indicator, Popover, Box, ScrollArea, Divider } from '@mantine/core'; +import { Popover, Box, ScrollArea, Divider, Indicator } from '@mantine/core'; import { useEffect, useState } from 'react'; import { Calendar } from '@mantine/dates'; import { RadarrMediaDisplay, SonarrMediaDisplay } from './MediaDisplay'; @@ -21,18 +21,18 @@ export default function CalendarComponent(props: any) { const sonarrService = filtered.filter((service) => service.type === 'Sonarr').at(0); const radarrService = filtered.filter((service) => service.type === 'Radarr').at(0); const nextMonth = new Date(new Date().setMonth(new Date().getMonth() + 2)).toISOString(); - if (sonarrService) { + if (sonarrService && sonarrService.apiKey) { fetch( `${sonarrService?.url}api/calendar?apikey=${sonarrService?.apiKey}&end=${nextMonth}` ).then((response) => { - response.json().then((data) => setSonarrMedias(data)); + response.ok && response.json().then((data) => setSonarrMedias(data)); }); } - if (radarrService) { + if (radarrService && radarrService.apiKey) { fetch( `${radarrService?.url}api/v3/calendar?apikey=${radarrService?.apiKey}&end=${nextMonth}` ).then((response) => { - response.json().then((data) => setRadarrMedias(data)); + response.ok && response.json().then((data) => setRadarrMedias(data)); }); } }, [config.services]); From 42cae6f0da9421b3d2b20c62ac8ca953ed44730b Mon Sep 17 00:00:00 2001 From: Aj - Thomas Date: Fri, 6 May 2022 23:10:00 +0200 Subject: [PATCH 2/2] Add an option to directly change the querry url in settings --- components/Settings/SettingsMenu.tsx | 53 ++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/components/Settings/SettingsMenu.tsx b/components/Settings/SettingsMenu.tsx index 4d0607458..6c20b1fa7 100644 --- a/components/Settings/SettingsMenu.tsx +++ b/components/Settings/SettingsMenu.tsx @@ -1,4 +1,14 @@ -import { ActionIcon, Group, Modal, Switch, Title, Text, Tooltip, TextInput } from '@mantine/core'; +import { + ActionIcon, + Group, + Modal, + Switch, + Title, + Text, + Tooltip, + TextInput, + SegmentedControl, +} from '@mantine/core'; import { useState } from 'react'; import { Settings as SettingsIcon } from 'tabler-icons-react'; import { useConfig } from '../../tools/state'; @@ -6,22 +16,35 @@ import SaveConfigComponent from '../Config/SaveConfig'; function SettingsMenu(props: any) { const { config, setConfig } = useConfig(); - + const matches = [ + { label: 'Google', value: 'https://google.com/search?q=' }, + { label: 'DuckDuckGo', value: 'https://duckduckgo.com/?q=' }, + { label: 'Bing', value: 'https://bing.com/search?q=' }, + ]; return ( - - setConfig({ - ...config, - settings: { - ...config.settings, - searchUrl: e.target.value, - }, - }) - } - /> + + match.value === config.settings.searchUrl)?.value || 'Google' + } + onChange={ + // Set config.settings.searchUrl to the value of the selected item + (e) => + setConfig({ + ...config, + settings: { + ...config.settings, + searchUrl: e, + }, + }) + } + data={matches} + /> + Search engine +