🐛 Search bar not respecting the open target #666

This commit is contained in:
Manuel
2023-01-30 21:12:45 +01:00
parent 561055d5d6
commit 84a6c38d9c

View File

@@ -20,6 +20,7 @@ import React, { forwardRef, useEffect, useRef, useState } from 'react';
import { useConfigContext } from '../../../config/provider'; import { useConfigContext } from '../../../config/provider';
import { OverseerrMediaDisplay } from '../../../modules/common'; import { OverseerrMediaDisplay } from '../../../modules/common';
import { IModule } from '../../../modules/ModuleTypes'; import { IModule } from '../../../modules/ModuleTypes';
import { ConfigType } from '../../../types/config';
import { searchUrls } from '../../Settings/Common/SearchEngine/SearchEngineSelector'; import { searchUrls } from '../../Settings/Common/SearchEngine/SearchEngineSelector';
import Tip from '../Tip'; import Tip from '../Tip';
import { useCardStyles } from '../useCardStyles'; import { useCardStyles } from '../useCardStyles';
@@ -137,9 +138,7 @@ export function Search() {
const textInput = useRef<HTMLInputElement>(null); const textInput = useRef<HTMLInputElement>(null);
useHotkeys([['mod+K', () => textInput.current?.focus()]]); useHotkeys([['mod+K', () => textInput.current?.focus()]]);
const { classes } = useStyles(); const { classes } = useStyles();
const openInNewTab = config?.settings.common.searchEngine.properties.openInNewTab const openTarget = getOpenTarget(config);
? '_blank'
: '_self';
const [opened, setOpened] = useState(false); const [opened, setOpened] = useState(false);
const { const {
@@ -166,6 +165,7 @@ export function Search() {
if (!isModuleEnabled) { if (!isModuleEnabled) {
return null; return null;
} }
//TODO: Fix the bug where clicking anything inside the Modal to ask for a movie //TODO: Fix the bug where clicking anything inside the Modal to ask for a movie
// will close it (Because it closes the underlying Popover) // will close it (Because it closes the underlying Popover)
return ( return (
@@ -194,7 +194,7 @@ export function Search() {
setOpened(false); setOpened(false);
if (item.url) { if (item.url) {
setSearchQuery(''); setSearchQuery('');
window.open(item.openedUrl ? item.openedUrl : item.url, openInNewTab); window.open(item.openedUrl ? item.openedUrl : item.url, openTarget);
} }
}} }}
// Replace %s if it is in selectedSearchEngine.url with searchQuery, otherwise append searchQuery at the end of it // Replace %s if it is in selectedSearchEngine.url with searchQuery, otherwise append searchQuery at the end of it
@@ -205,9 +205,9 @@ export function Search() {
autocompleteData.length === 0 autocompleteData.length === 0
) { ) {
if (selectedSearchEngine.url.includes('%s')) { if (selectedSearchEngine.url.includes('%s')) {
window.open(selectedSearchEngine.url.replace('%s', searchQuery), openInNewTab); window.open(selectedSearchEngine.url.replace('%s', searchQuery), openTarget);
} else { } else {
window.open(selectedSearchEngine.url + searchQuery, openInNewTab); window.open(selectedSearchEngine.url + searchQuery, openTarget);
} }
} }
}} }}
@@ -220,14 +220,15 @@ export function Search() {
</Popover.Target> </Popover.Target>
<Popover.Dropdown> <Popover.Dropdown>
<ScrollArea style={{ height: '80vh', maxWidth: '90vw' }} offsetScrollbars> <ScrollArea style={{ height: '80vh', maxWidth: '90vw' }} offsetScrollbars>
{OverseerrResults && OverseerrResults.slice(0, 4).map((result: any, index: number) => ( {OverseerrResults &&
<React.Fragment key={index}> OverseerrResults.slice(0, 4).map((result: any, index: number) => (
<OverseerrMediaDisplay key={result.id} media={result} /> <React.Fragment key={index}>
{index < OverseerrResults.length - 1 && index < 3 && ( <OverseerrMediaDisplay key={result.id} media={result} />
<Divider variant="dashed" my="xs" /> {index < OverseerrResults.length - 1 && index < 3 && (
)} <Divider variant="dashed" my="xs" />
</React.Fragment> )}
))} </React.Fragment>
))}
</ScrollArea> </ScrollArea>
</Popover.Dropdown> </Popover.Dropdown>
</Popover> </Popover>
@@ -299,3 +300,11 @@ export function Search() {
}); });
} }
} }
const getOpenTarget = (config: ConfigType | undefined): '_blank' | '_self' => {
if (!config || config.settings.common.searchEngine.properties.openInNewTab === undefined) {
return '_blank';
}
return config.settings.common.searchEngine.properties.openInNewTab ? '_blank' : '_self';
};