fix: media request search bugs and availability indicators (#5824)
This commit is contained in:
1 parent
6230db53e0
commit
afa36bffa9
11 files changed
+114
-85
No files matched your search
@@ -131,7 +131,9 @@ export const mediaRequestsChildrenOptions = createChildrenOptions<MediaRequestCh
|
||||
return [
|
||||
{
|
||||
key: "request",
|
||||
hide: (option) => option.result.inLibrary || option.integration.permissions?.hasInteractAccess === false,
|
||||
hide: (option) =>
|
||||
(option.result.type === "movie" && option.result.inLibrary) ||
|
||||
option.integration.permissions?.hasInteractAccess === false,
|
||||
Component(option) {
|
||||
const t = useScopedI18n("search.mode.media");
|
||||
return (
|
||||
|
||||
@@ -19,6 +19,7 @@ import type { SearchMode } from "../../lib/mode";
|
||||
import { appIntegrationBoardMode } from "../app-integration-board";
|
||||
import { commandMode } from "../command";
|
||||
import { externalMode } from "../external";
|
||||
import { mediaMode } from "../media";
|
||||
import { pageMode } from "../page";
|
||||
import { userGroupMode } from "../user-group";
|
||||
|
||||
@@ -33,7 +34,7 @@ type QuickLinkOption = {
|
||||
export const useHomeEmptyGroups = () => {
|
||||
const { data: session } = useSession();
|
||||
const tPages = useScopedI18n("search.mode.page.group.page.option");
|
||||
const visibleSearchModes: SearchMode[] = [appIntegrationBoardMode, externalMode, commandMode, pageMode];
|
||||
const visibleSearchModes: SearchMode[] = [appIntegrationBoardMode, externalMode, mediaMode, commandMode, pageMode];
|
||||
|
||||
if (session?.user.permissions.includes("admin")) {
|
||||
visibleSearchModes.unshift(userGroupMode);
|
||||
@@ -87,7 +88,7 @@ export const useHomeEmptyGroups = () => {
|
||||
useInteraction: interaction.link(({ path }) => ({ href: path })),
|
||||
}),
|
||||
createGroup({
|
||||
keyPath: "character",
|
||||
keyPath: "modeKey",
|
||||
title: (t) => t("search.mode.help.group.mode.title"),
|
||||
options: visibleSearchModes.map(({ character, modeKey }) => ({ character, modeKey })),
|
||||
Component: ({ modeKey, character }) => {
|
||||
@@ -96,7 +97,7 @@ export const useHomeEmptyGroups = () => {
|
||||
return (
|
||||
<Group px="md" py="xs" w="100%" wrap="nowrap" align="center" justify="space-between">
|
||||
<Text>{t("help")}</Text>
|
||||
<Kbd size="sm">{character}</Kbd>
|
||||
{character && <Kbd size="sm">{character}</Kbd>}
|
||||
</Group>
|
||||
);
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Box, Group, Stack, Text } from "@mantine/core";
|
||||
import { IconMovie, IconSearch, IconSearchOff } from "@tabler/icons-react";
|
||||
import { IconSearch, IconSearchOff } from "@tabler/icons-react";
|
||||
|
||||
import type { RouterOutputs } from "@homarr/api";
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
@@ -64,10 +64,6 @@ export const homeSearchEngineGroup = createGroup<GroupItem>({
|
||||
clientApi.searchEngine.getDefaultSearchEngine.useQuery(undefined, {
|
||||
enabled: status !== "loading",
|
||||
});
|
||||
const { data: mediaRequestSearchTargets, ...mediaRequestSearchTargetsQuery } =
|
||||
clientApi.integration.mediaRequestSearchTargets.useQuery(undefined, {
|
||||
enabled: status !== "loading" && session?.user !== undefined,
|
||||
});
|
||||
const fromIntegrationEnabled = defaultSearchEngine?.type === "fromIntegration" && query.length > 0;
|
||||
const { data: results, ...resultQuery } = clientApi.integration.searchInIntegration.useQuery(
|
||||
{
|
||||
@@ -83,14 +79,12 @@ export const homeSearchEngineGroup = createGroup<GroupItem>({
|
||||
return {
|
||||
isLoading:
|
||||
defaultSearchEngineQuery.isLoading ||
|
||||
mediaRequestSearchTargetsQuery.isLoading ||
|
||||
(resultQuery.isLoading && fromIntegrationEnabled) ||
|
||||
status === "loading",
|
||||
isError:
|
||||
defaultSearchEngineQuery.isError ||
|
||||
mediaRequestSearchTargetsQuery.isError ||
|
||||
(resultQuery.isError && fromIntegrationEnabled),
|
||||
data: createDefaultSearchEntries(defaultSearchEngine, results, mediaRequestSearchTargets, session, query, t),
|
||||
data: createDefaultSearchEntries(defaultSearchEngine, results, session, query, t),
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -98,40 +92,14 @@ export const homeSearchEngineGroup = createGroup<GroupItem>({
|
||||
const createDefaultSearchEntries = (
|
||||
defaultSearchEngine: RouterOutputs["searchEngine"]["getDefaultSearchEngine"] | null,
|
||||
results: RouterOutputs["integration"]["searchInIntegration"] | undefined,
|
||||
mediaRequestSearchTargets: RouterOutputs["integration"]["mediaRequestSearchTargets"] | undefined,
|
||||
session: Session | null,
|
||||
query: string,
|
||||
t: TranslationFunction,
|
||||
): GroupItem[] => {
|
||||
const mediaRequestSearchEntry: GroupItem = {
|
||||
id: "media-request-search",
|
||||
name: t("search.mode.media.action.search.label"),
|
||||
description:
|
||||
mediaRequestSearchTargets && mediaRequestSearchTargets.length === 0
|
||||
? t("search.mode.media.action.search.disabled.noIntegration")
|
||||
: t("search.mode.media.action.search.description"),
|
||||
icon: IconMovie,
|
||||
disabled: !mediaRequestSearchTargets || mediaRequestSearchTargets.length === 0,
|
||||
useInteraction(query) {
|
||||
if (!mediaRequestSearchTargets || mediaRequestSearchTargets.length === 0) {
|
||||
return {
|
||||
type: "none",
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
type: "mode",
|
||||
mode: "media",
|
||||
query,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
if (!session?.user && !defaultSearchEngine) return [mediaRequestSearchEntry];
|
||||
if (!session?.user && !defaultSearchEngine) return [];
|
||||
|
||||
if (!defaultSearchEngine) {
|
||||
return [
|
||||
mediaRequestSearchEntry,
|
||||
{
|
||||
id: "no-default",
|
||||
name: t("search.mode.home.group.search.option.no-default.label"),
|
||||
@@ -150,7 +118,6 @@ const createDefaultSearchEntries = (
|
||||
|
||||
if (defaultSearchEngine.type === "generic") {
|
||||
return [
|
||||
mediaRequestSearchEntry,
|
||||
{
|
||||
id: "search",
|
||||
name: t("search.mode.home.group.search.option.search.label", {
|
||||
@@ -173,7 +140,6 @@ const createDefaultSearchEntries = (
|
||||
|
||||
if (!results) {
|
||||
return [
|
||||
mediaRequestSearchEntry,
|
||||
{
|
||||
id: "from-integration",
|
||||
name: defaultSearchEngine.name,
|
||||
@@ -188,16 +154,13 @@ const createDefaultSearchEntries = (
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
mediaRequestSearchEntry,
|
||||
...results.map((result) => ({
|
||||
id: `search-${result.id}`,
|
||||
name: result.name,
|
||||
description: result.text,
|
||||
icon: result.image ?? IconSearch,
|
||||
useInteraction() {
|
||||
return useFromIntegrationSearchInteraction(defaultSearchEngine, result);
|
||||
},
|
||||
})),
|
||||
];
|
||||
return results.map((result) => ({
|
||||
id: `search-${result.id}`,
|
||||
name: result.name,
|
||||
description: result.text,
|
||||
icon: result.image ?? IconSearch,
|
||||
useInteraction() {
|
||||
return useFromIntegrationSearchInteraction(defaultSearchEngine, result);
|
||||
},
|
||||
}));
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Group, Image, Stack, Text } from "@mantine/core";
|
||||
import { Badge, Group, Image, Stack, Text } from "@mantine/core";
|
||||
import { useDebouncedValue } from "@mantine/hooks";
|
||||
import { IconMovie, IconSearch } from "@tabler/icons-react";
|
||||
import { keepPreviousData } from "@tanstack/react-query";
|
||||
@@ -7,12 +7,22 @@ import { useAtomValue } from "jotai";
|
||||
import type { RouterOutputs } from "@homarr/api";
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { getIntegrationName } from "@homarr/definitions";
|
||||
import type { MediaAvailability } from "@homarr/integrations/types";
|
||||
import { mediaAvailabilityConfiguration } from "@homarr/integrations/types";
|
||||
import { useScopedI18n } from "@homarr/translation/client";
|
||||
|
||||
import { createGroup } from "../../lib/group";
|
||||
import { mediaRequestSearchScopeAtom } from "../../spotlight-store";
|
||||
import { useMediaRequestSearchInteraction } from "../external/search-engines-search-group";
|
||||
|
||||
const availabilityLabels: Partial<Record<MediaAvailability, string>> = {
|
||||
available: "Available",
|
||||
partiallyAvailable: "Partial",
|
||||
processing: "Processing",
|
||||
requested: "Requested",
|
||||
pending: "Requested",
|
||||
};
|
||||
|
||||
type MediaRequestSearchResult = RouterOutputs["integration"]["searchMediaRequests"][number];
|
||||
|
||||
type MediaRequestSearchOption =
|
||||
@@ -47,6 +57,11 @@ export const mediaRequestSearchGroup = createGroup<MediaRequestSearchOption>({
|
||||
}
|
||||
|
||||
const { result } = option;
|
||||
const badgeLabel = result.availability ? availabilityLabels[result.availability as MediaAvailability] : undefined;
|
||||
const badgeColor = result.availability
|
||||
? mediaAvailabilityConfiguration[result.availability as MediaAvailability]?.color
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
<Group w="100%" wrap="nowrap" align="center" px="md" py="xs">
|
||||
{result.image ? (
|
||||
@@ -54,8 +69,11 @@ export const mediaRequestSearchGroup = createGroup<MediaRequestSearchOption>({
|
||||
) : (
|
||||
<IconSearch stroke={1.5} size={35} />
|
||||
)}
|
||||
<Stack gap={2}>
|
||||
<Text>{result.name}</Text>
|
||||
<Stack gap={2} style={{ flex: 1 }}>
|
||||
<Group gap="xs" wrap="nowrap">
|
||||
<Text>{result.name}</Text>
|
||||
{badgeLabel && <Badge size="xs" color={badgeColor} variant="light">{badgeLabel}</Badge>}
|
||||
</Group>
|
||||
<Text c="dimmed" size="sm" lineClamp={2}>
|
||||
{result.text ?? getIntegrationName(result.integration.kind)}
|
||||
</Text>
|
||||
|
||||
Reference in new issue
Block a user