Merge pull request #648 from ajnart:502-adjust-size-of-results-in-the-search-box-to-screen-size
Rework media display for Overseerr
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
|||||||
import { useDebouncedValue, useHotkeys } from '@mantine/hooks';
|
import { useDebouncedValue, useHotkeys } from '@mantine/hooks';
|
||||||
import { showNotification } from '@mantine/notifications';
|
import { showNotification } from '@mantine/notifications';
|
||||||
import { IconBrandYoutube, IconDownload, IconMovie, IconSearch } from '@tabler/icons';
|
import { IconBrandYoutube, IconDownload, IconMovie, IconSearch } from '@tabler/icons';
|
||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { useTranslation } from 'next-i18next';
|
import { useTranslation } from 'next-i18next';
|
||||||
import React, { forwardRef, useEffect, useRef, useState } from 'react';
|
import React, { forwardRef, useEffect, useRef, useState } from 'react';
|
||||||
@@ -142,13 +143,25 @@ export function Search() {
|
|||||||
const [OverseerrResults, setOverseerrResults] = useState<any[]>([]);
|
const [OverseerrResults, setOverseerrResults] = useState<any[]>([]);
|
||||||
const [opened, setOpened] = useState(false);
|
const [opened, setOpened] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
const { data, isLoading, error } = useQuery(
|
||||||
if (debounced !== '' && selectedSearchEngine.value === 'overseerr' && searchQuery.length > 3) {
|
['overseerr', debounced],
|
||||||
axios.get(`/api/modules/overseerr?query=${searchQuery}`).then((res) => {
|
async () => {
|
||||||
setOverseerrResults(res.data.results ?? []);
|
if (debounced !== '' && selectedSearchEngine.value === 'overseerr' && debounced.length > 3) {
|
||||||
});
|
const res = await axios.get(`/api/modules/overseerr?query=${debounced}`);
|
||||||
|
return res.data.results ?? [];
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
},
|
||||||
|
{
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
refetchOnMount: false,
|
||||||
|
refetchInterval: false,
|
||||||
}
|
}
|
||||||
}, [debounced]);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setOverseerrResults(data ?? []);
|
||||||
|
}, [data]);
|
||||||
|
|
||||||
const isModuleEnabled = config?.settings.customization.layout.enabledSearchbar;
|
const isModuleEnabled = config?.settings.customization.layout.enabledSearchbar;
|
||||||
if (!isModuleEnabled) {
|
if (!isModuleEnabled) {
|
||||||
@@ -207,16 +220,14 @@ export function Search() {
|
|||||||
/>
|
/>
|
||||||
</Popover.Target>
|
</Popover.Target>
|
||||||
<Popover.Dropdown>
|
<Popover.Dropdown>
|
||||||
<div>
|
<ScrollArea style={{ height: '80vh', maxWidth: '90vw' }} offsetScrollbars>
|
||||||
<ScrollArea style={{ height: 400, width: 420 }} offsetScrollbars>
|
{OverseerrResults.slice(0, 4).map((result, index) => (
|
||||||
{OverseerrResults.slice(0, 5).map((result, index) => (
|
<React.Fragment key={index}>
|
||||||
<React.Fragment key={index}>
|
<OverseerrMediaDisplay key={result.id} media={result} />
|
||||||
<OverseerrMediaDisplay key={result.id} media={result} />
|
{index < OverseerrResults.length - 1 && index < 3 && <Divider variant="dashed" my="xs" />}
|
||||||
{index < OverseerrResults.length - 1 && <Divider variant="dashed" my="xl" />}
|
</React.Fragment>
|
||||||
</React.Fragment>
|
))}
|
||||||
))}
|
</ScrollArea>
|
||||||
</ScrollArea>
|
|
||||||
</div>
|
|
||||||
</Popover.Dropdown>
|
</Popover.Dropdown>
|
||||||
</Popover>
|
</Popover>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ export function MediaDisplay({ media }: { media: IMedia }) {
|
|||||||
const { t } = useTranslation('modules/common-media-cards');
|
const { t } = useTranslation('modules/common-media-cards');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Group mr="xs" align="stretch" noWrap style={{ maxHeight: 250, maxWidth: 400 }} spacing="xs">
|
<Group noWrap style={{ maxHeight: 250, maxWidth: 400 }} p={0} m={0} spacing="xs">
|
||||||
<Image src={media.poster} height={200} width={150} radius="md" fit="cover" />
|
<Image src={media.poster} height={200} width={150} radius="md" fit="cover" />
|
||||||
<Stack justify="space-around">
|
<Stack justify="space-around">
|
||||||
<Stack spacing="sm">
|
<Stack spacing="sm">
|
||||||
@@ -223,7 +223,7 @@ export function MediaDisplay({ media }: { media: IMedia }) {
|
|||||||
{media.overview}
|
{media.overview}
|
||||||
</Text>
|
</Text>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Group noWrap>
|
<Group spacing="xs">
|
||||||
{media.plexUrl && (
|
{media.plexUrl && (
|
||||||
<Button
|
<Button
|
||||||
component="a"
|
component="a"
|
||||||
|
|||||||
Reference in New Issue
Block a user