feat: add new search dialog
This commit is contained in:
17 files changed
+751
-7
No files matched your search
@@ -15,6 +15,7 @@ import { useShallow } from "zustand/shallow";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
import useHeaderStore from "@/utils/store/header";
|
||||
import useSearchStore from "@/utils/store/search";
|
||||
import {
|
||||
setSettingsDialogOpen,
|
||||
setSettingsTabValue,
|
||||
@@ -42,6 +43,10 @@ export const AppBar = () => {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
|
||||
const toggleSearchDialog = useSearchStore(
|
||||
useShallow((s) => s.toggleSearchDialog),
|
||||
);
|
||||
|
||||
const display = !HIDDEN_PATHS.some(
|
||||
(path) =>
|
||||
(location.pathname.startsWith(path) &&
|
||||
@@ -87,7 +92,7 @@ export const AppBar = () => {
|
||||
};
|
||||
}, []);
|
||||
|
||||
const handleNavigateToSearch = useCallback(
|
||||
const _handleNavigateToSearch = useCallback(
|
||||
() => navigate({ to: "/search", search: { query: "" } }),
|
||||
[navigate],
|
||||
);
|
||||
@@ -142,7 +147,7 @@ export const AppBar = () => {
|
||||
</div>
|
||||
|
||||
<div className="flex flex-row" style={{ gap: "0.6em" }}>
|
||||
<IconButton onClick={handleNavigateToSearch}>
|
||||
<IconButton onClick={toggleSearchDialog}>
|
||||
<div className="material-symbols-rounded">search</div>
|
||||
</IconButton>
|
||||
<IconButton onClick={handleNavigateToFavorite}>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
.carousel {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
overflow: visible;
|
||||
height: 62vh;
|
||||
margin-bottom: 2em;
|
||||
display: grid;
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 14px;
|
||||
border-left: 1px solid rgb(255 255 255 / 0.1);
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
|
||||
@@ -0,0 +1,400 @@
|
||||
import { ItemSortBy } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
|
||||
import { getSearchApi } from "@jellyfin/sdk/lib/utils/api/search-api";
|
||||
import {
|
||||
alpha,
|
||||
Box,
|
||||
Button,
|
||||
Dialog,
|
||||
IconButton,
|
||||
InputBase,
|
||||
LinearProgress,
|
||||
Stack,
|
||||
Typography,
|
||||
useTheme,
|
||||
} from "@mui/material";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import { register } from "@tauri-apps/plugin-global-shortcut";
|
||||
import React, {
|
||||
type ChangeEvent,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useState,
|
||||
} from "react";
|
||||
import { useShallow } from "zustand/shallow";
|
||||
import useDebounce from "@/utils/hooks/useDebounce";
|
||||
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
import useSearchStore from "@/utils/store/search";
|
||||
import SearchItem from "./item";
|
||||
|
||||
const Search = () => {
|
||||
const theme = useTheme();
|
||||
const { isOpen, handleClose, toggleSearchDialog } = useSearchStore(
|
||||
useShallow((s) => ({
|
||||
isOpen: s.showSearchDialog,
|
||||
handleClose: s.toggleSearchDialog,
|
||||
toggleSearchDialog: s.toggleSearchDialog,
|
||||
})),
|
||||
);
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const userId = useCentralStore((s) => s.currentUser?.Id || "");
|
||||
const suggestions = useQuery({
|
||||
queryKey: ["search", "suggestions"],
|
||||
queryFn: async () =>
|
||||
api &&
|
||||
(
|
||||
await getItemsApi(api).getItems({
|
||||
userId: userId,
|
||||
limit: 5,
|
||||
sortBy: [ItemSortBy.IsFavoriteOrLiked, ItemSortBy.Random],
|
||||
includeItemTypes: ["Movie", "Series", "MusicArtist"],
|
||||
enableImages: true,
|
||||
recursive: true,
|
||||
})
|
||||
).data,
|
||||
});
|
||||
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
const debouncedSearchTerm = useDebounce(searchTerm, 300);
|
||||
|
||||
const handleSearchChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
setSearchTerm(e.target.value);
|
||||
};
|
||||
|
||||
const searchResults = useQuery({
|
||||
queryKey: ["search", debouncedSearchTerm],
|
||||
queryFn: async () => {
|
||||
if (!api) return null;
|
||||
if (debouncedSearchTerm.trim() === "") {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
await getSearchApi(api).getSearchHints({
|
||||
searchTerm: debouncedSearchTerm,
|
||||
userId: userId,
|
||||
limit: 10,
|
||||
includeItemTypes: [
|
||||
"Movie",
|
||||
"Series",
|
||||
"MusicAlbum",
|
||||
"Person",
|
||||
"Audio",
|
||||
"Photo",
|
||||
"PhotoAlbum",
|
||||
"Playlist",
|
||||
],
|
||||
// enableImages: true,
|
||||
})
|
||||
).data;
|
||||
},
|
||||
});
|
||||
|
||||
const showSuggestions = useMemo(
|
||||
() =>
|
||||
(debouncedSearchTerm.length === 0 || searchResults.isLoading) &&
|
||||
(suggestions.data?.Items?.length ?? 0) > 0,
|
||||
[
|
||||
debouncedSearchTerm.length,
|
||||
searchResults.isLoading,
|
||||
suggestions.data?.Items?.length,
|
||||
],
|
||||
);
|
||||
|
||||
const navigate = useNavigate();
|
||||
const handleClearSearch = useCallback(() => {
|
||||
setSearchTerm("");
|
||||
}, []);
|
||||
const handleAdvancedSearch = useCallback(() => {
|
||||
navigate({ to: "/search", search: { query: debouncedSearchTerm } });
|
||||
toggleSearchDialog();
|
||||
}, [navigate, toggleSearchDialog, debouncedSearchTerm]);
|
||||
|
||||
useEffect(() => {
|
||||
async function registerglobalShortcut() {
|
||||
await register("CommandOrControl+K", (e) => {
|
||||
if (e.state === "Pressed") {
|
||||
toggleSearchDialog();
|
||||
}
|
||||
});
|
||||
}
|
||||
registerglobalShortcut();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
open={isOpen}
|
||||
onClose={handleClose}
|
||||
fullWidth
|
||||
maxWidth="sm"
|
||||
PaperProps={{
|
||||
sx: {
|
||||
backgroundColor: "rgba(20, 20, 30, 0.7)",
|
||||
backdropFilter: "blur(24px) saturate(180%)",
|
||||
backgroundImage:
|
||||
"linear-gradient(rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0))",
|
||||
border: "1px solid rgba(255, 255, 255, 0.08)",
|
||||
boxShadow: "0 20px 50px rgba(0,0,0,0.5)",
|
||||
borderRadius: 4,
|
||||
overflow: "hidden",
|
||||
},
|
||||
}}
|
||||
>
|
||||
<Box sx={{ position: "relative" }}>
|
||||
<Stack
|
||||
direction="row"
|
||||
alignItems="center"
|
||||
spacing={1.5}
|
||||
sx={{
|
||||
p: "16px 24px",
|
||||
}}
|
||||
>
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{
|
||||
color: "var(--mui-palette-text-secondary)",
|
||||
fontSize: "1.75rem",
|
||||
opacity: 0.7,
|
||||
}}
|
||||
>
|
||||
search
|
||||
</span>
|
||||
<InputBase
|
||||
placeholder="Search movies, shows, and more..."
|
||||
onChange={handleSearchChange}
|
||||
value={searchTerm}
|
||||
fullWidth
|
||||
autoFocus
|
||||
sx={{
|
||||
fontSize: "1.25rem",
|
||||
fontWeight: 400,
|
||||
color: "text.primary",
|
||||
"& input::placeholder": {
|
||||
color: "text.disabled",
|
||||
opacity: 1,
|
||||
},
|
||||
}}
|
||||
/>
|
||||
{searchTerm && (
|
||||
<IconButton
|
||||
onClick={handleClearSearch}
|
||||
size="small"
|
||||
sx={{
|
||||
color: "text.secondary",
|
||||
bgcolor: "rgba(255,255,255,0.05)",
|
||||
"&:hover": {
|
||||
bgcolor: "rgba(255,255,255,0.15)",
|
||||
},
|
||||
}}
|
||||
>
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{ fontSize: "1.25rem" }}
|
||||
>
|
||||
close
|
||||
</span>
|
||||
</IconButton>
|
||||
)}
|
||||
</Stack>
|
||||
{searchResults.isLoading && (
|
||||
<LinearProgress
|
||||
sx={{
|
||||
height: 2,
|
||||
backgroundColor: "transparent",
|
||||
"& .MuiLinearProgress-bar": {
|
||||
backgroundImage: `linear-gradient(90deg, ${theme.palette.primary.main}, ${theme.palette.secondary.main})`,
|
||||
},
|
||||
position: "absolute",
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<Box
|
||||
sx={{
|
||||
height: "1px",
|
||||
bgcolor: "divider",
|
||||
opacity: 0.1,
|
||||
mx: 2,
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Stack
|
||||
spacing={1}
|
||||
sx={{
|
||||
p: 1,
|
||||
maxHeight: "55vh",
|
||||
overflowY: "auto",
|
||||
minHeight:
|
||||
showSuggestions ||
|
||||
(debouncedSearchTerm &&
|
||||
searchResults.data?.SearchHints?.length !== 0)
|
||||
? "auto"
|
||||
: "150px",
|
||||
"&::-webkit-scrollbar": {
|
||||
width: "8px",
|
||||
},
|
||||
"&::-webkit-scrollbar-thumb": {
|
||||
background: "rgba(255,255,255,0.1)",
|
||||
borderRadius: "4px",
|
||||
},
|
||||
}}
|
||||
>
|
||||
{debouncedSearchTerm.length > 0 &&
|
||||
searchResults.data?.SearchHints &&
|
||||
searchResults.data.SearchHints.length > 0 && (
|
||||
<Box>
|
||||
<Typography
|
||||
variant="caption"
|
||||
fontWeight={600}
|
||||
sx={{
|
||||
px: 2,
|
||||
py: 1.5,
|
||||
color: "text.secondary",
|
||||
textTransform: "uppercase",
|
||||
letterSpacing: "0.05em",
|
||||
display: "block",
|
||||
}}
|
||||
>
|
||||
Results
|
||||
</Typography>
|
||||
<Stack spacing={0.5} sx={{ px: 1 }}>
|
||||
{searchResults.data.SearchHints.map((item) => (
|
||||
<SearchItem
|
||||
key={item.Id}
|
||||
itemName={item.Name || "Untitled"}
|
||||
imageUrl={
|
||||
api &&
|
||||
item.PrimaryImageTag &&
|
||||
getImageUrlsApi(api).getItemImageUrl(item, "Primary", {
|
||||
maxWidth: 90,
|
||||
maxHeight: 140,
|
||||
tag: item.PrimaryImageTag,
|
||||
})
|
||||
}
|
||||
itemYear={
|
||||
item.Type === "Series"
|
||||
? `${item.ProductionYear?.toString()} - ${new Date(item.EndDate ?? "").getFullYear().toString()}`
|
||||
: item.ProductionYear?.toString()
|
||||
}
|
||||
itemType={item.Type}
|
||||
itemId={item.Id ?? ""}
|
||||
/>
|
||||
))}
|
||||
</Stack>
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{showSuggestions && (
|
||||
<Box>
|
||||
<Typography
|
||||
variant="caption"
|
||||
fontWeight={600}
|
||||
sx={{
|
||||
px: 2,
|
||||
py: 1.5,
|
||||
color: "text.secondary",
|
||||
textTransform: "uppercase",
|
||||
letterSpacing: "0.05em",
|
||||
display: "block",
|
||||
}}
|
||||
>
|
||||
Suggestions
|
||||
</Typography>
|
||||
<Stack spacing={0.5} sx={{ px: 1 }}>
|
||||
{suggestions.data?.Items?.map((item) => (
|
||||
<SearchItem
|
||||
key={item.Id}
|
||||
itemName={item.Name || "Untitled"}
|
||||
imageUrl={
|
||||
api &&
|
||||
item.ImageTags?.Primary &&
|
||||
getImageUrlsApi(api).getItemImageUrl(item, "Primary", {
|
||||
maxWidth: 90,
|
||||
maxHeight: 140,
|
||||
})
|
||||
}
|
||||
itemYear={
|
||||
item.Type === "Series"
|
||||
? `${item.ProductionYear?.toString()} - ${new Date(item.EndDate ?? "").getFullYear().toString()}`
|
||||
: item.ProductionYear?.toString()
|
||||
}
|
||||
itemType={item.Type}
|
||||
itemId={item.Id ?? ""}
|
||||
/>
|
||||
))}
|
||||
</Stack>
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{searchResults.isSuccess &&
|
||||
searchResults.data?.SearchHints?.length === 0 && (
|
||||
<Stack
|
||||
alignItems="center"
|
||||
justifyContent="center"
|
||||
sx={{
|
||||
height: "100%",
|
||||
minHeight: "200px",
|
||||
color: "text.secondary",
|
||||
gap: 2,
|
||||
}}
|
||||
>
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{ fontSize: "48px", opacity: 0.2 }}
|
||||
>
|
||||
search_off
|
||||
</span>
|
||||
<Typography variant="body1">
|
||||
No results found for "{debouncedSearchTerm}"
|
||||
</Typography>
|
||||
</Stack>
|
||||
)}
|
||||
</Stack>
|
||||
|
||||
<Stack
|
||||
direction="row"
|
||||
justifyContent="flex-end"
|
||||
sx={{
|
||||
p: 1.5,
|
||||
mt: 1,
|
||||
backgroundImage:
|
||||
"linear-gradient(to top, rgba(0,0,0,0.2), transparent)",
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
onClick={handleAdvancedSearch}
|
||||
endIcon={
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{ fontSize: "1.25rem" }}
|
||||
>
|
||||
arrow_forward
|
||||
</span>
|
||||
}
|
||||
sx={{
|
||||
color: "text.secondary",
|
||||
textTransform: "none",
|
||||
fontWeight: 500,
|
||||
padding: "6px 16px",
|
||||
borderRadius: "8px",
|
||||
"&:hover": {
|
||||
color: "primary.main",
|
||||
backgroundColor: "rgba(255,255,255,0.05)",
|
||||
},
|
||||
}}
|
||||
>
|
||||
Advanced Search
|
||||
</Button>
|
||||
</Stack>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
export default Search;
|
||||
@@ -0,0 +1,132 @@
|
||||
import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { Box, Button, Stack, Typography } from "@mui/material";
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import React from "react";
|
||||
import { useShallow } from "zustand/react/shallow";
|
||||
import useSearchStore from "@/utils/store/search";
|
||||
import { getTypeIcon } from "../utils/iconsCollection";
|
||||
|
||||
type SearchItemProps = {
|
||||
itemName: string;
|
||||
imageUrl?: string | null;
|
||||
itemYear?: string;
|
||||
itemType?: BaseItemKind;
|
||||
itemId: string;
|
||||
};
|
||||
|
||||
const SearchItem = (props: SearchItemProps) => {
|
||||
const { itemName, imageUrl, itemYear, itemType, itemId } = props;
|
||||
const toggleSearchDialog = useSearchStore(
|
||||
useShallow((s) => s.toggleSearchDialog),
|
||||
);
|
||||
const navigate = useNavigate();
|
||||
const handleOnClick = () => {
|
||||
toggleSearchDialog();
|
||||
switch (itemType) {
|
||||
case BaseItemKind.BoxSet:
|
||||
navigate({ to: "/boxset/$id", params: { id: itemId } });
|
||||
break;
|
||||
case BaseItemKind.Episode:
|
||||
navigate({ to: "/episode/$id", params: { id: itemId } });
|
||||
break;
|
||||
case BaseItemKind.MusicAlbum:
|
||||
navigate({ to: "/album/$id", params: { id: itemId } });
|
||||
break;
|
||||
case BaseItemKind.MusicArtist:
|
||||
navigate({ to: "/artist/$id", params: { id: itemId } });
|
||||
break;
|
||||
case BaseItemKind.Person:
|
||||
navigate({ to: "/person/$id", params: { id: itemId } });
|
||||
break;
|
||||
case BaseItemKind.Series:
|
||||
navigate({ to: "/series/$id", params: { id: itemId } });
|
||||
break;
|
||||
case BaseItemKind.Playlist:
|
||||
navigate({ to: "/playlist/$id", params: { id: itemId } });
|
||||
break;
|
||||
default:
|
||||
navigate({ to: "/item/$id", params: { id: itemId } });
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Button
|
||||
onClick={handleOnClick}
|
||||
fullWidth
|
||||
sx={{
|
||||
justifyContent: "flex-start",
|
||||
textAlign: "left",
|
||||
p: 1,
|
||||
borderRadius: 2,
|
||||
textTransform: "none",
|
||||
color: "text.primary",
|
||||
"&:hover": {
|
||||
bgcolor: "action.hover",
|
||||
},
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
sx={{
|
||||
width: 50,
|
||||
height: 75,
|
||||
mr: 2,
|
||||
borderRadius: 1,
|
||||
overflow: "hidden",
|
||||
bgcolor: "action.selected",
|
||||
flexShrink: 0,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
>
|
||||
{imageUrl ? (
|
||||
<Box
|
||||
component="img"
|
||||
src={imageUrl}
|
||||
alt={itemName}
|
||||
sx={{
|
||||
height: "100%",
|
||||
width: "100%",
|
||||
objectFit: "cover",
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{
|
||||
fontSize: "2rem",
|
||||
color: "var(--mui-palette-text-secondary)",
|
||||
}}
|
||||
>
|
||||
{getTypeIcon(itemType ?? "unknown")}
|
||||
</span>
|
||||
)}
|
||||
</Box>
|
||||
<Stack sx={{ minWidth: 0, flex: 1 }}>
|
||||
<Typography variant="body1" noWrap fontWeight={500}>
|
||||
{itemName}
|
||||
</Typography>
|
||||
<Stack direction="row" spacing={1} alignItems="center">
|
||||
{itemYear && (
|
||||
<Typography variant="caption" color="text.secondary">
|
||||
{itemYear}
|
||||
</Typography>
|
||||
)}
|
||||
{itemYear && itemType && (
|
||||
<Typography variant="caption" color="text.secondary">
|
||||
•
|
||||
</Typography>
|
||||
)}
|
||||
{itemType && (
|
||||
<Typography variant="caption" color="text.secondary">
|
||||
{itemType}
|
||||
</Typography>
|
||||
)}
|
||||
</Stack>
|
||||
</Stack>
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
|
||||
export default SearchItem;
|
||||
@@ -29,6 +29,7 @@ import { HTML5Backend } from "react-dnd-html5-backend";
|
||||
import Backdrop from "@/components/backdrop";
|
||||
import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice";
|
||||
import RouterLoading from "@/components/routerLoading";
|
||||
import Search from "@/components/search";
|
||||
import Updater from "@/components/updater";
|
||||
import { EasterEgg } from "@/components/utils/easterEgg";
|
||||
|
||||
@@ -56,6 +57,7 @@ export const Route = createRootRouteWithContext<ApiContext>()({
|
||||
|
||||
<Updater />
|
||||
<Backdrop />
|
||||
<Search />
|
||||
<AppBar />
|
||||
<AudioPlayer />
|
||||
<Outlet />
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
.hero-carousel {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
overflow: visible;
|
||||
isolation: isolate;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
@@ -16,6 +16,7 @@
|
||||
border-radius: 20px;
|
||||
grid-area: main;
|
||||
border: 1.2px solid rgb(255 255 255 / 0.1);
|
||||
box-shadow: 0 0 20px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
&-background {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { create } from "zustand";
|
||||
|
||||
type SearchStore = {
|
||||
showSearchDialog: boolean;
|
||||
toggleSearchDialog: () => void;
|
||||
};
|
||||
|
||||
const useSearchStore = create<SearchStore>((set) => ({
|
||||
showSearchDialog: false,
|
||||
toggleSearchDialog: () =>
|
||||
set((state) => ({ showSearchDialog: !state.showSearchDialog })),
|
||||
}));
|
||||
|
||||
export default useSearchStore;
|
||||
Reference in new issue
Block a user