feat: remember last search query
This commit is contained in:
10 files changed
+125
-86
No files matched your search
@@ -14,7 +14,7 @@ export const EmptyNotice = ({ extraMsg }) => {
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
flexFlow: "column",
|
||||
position: "absolute",
|
||||
position: "static",
|
||||
top: 0,
|
||||
left: 0,
|
||||
}}
|
||||
|
||||
@@ -267,7 +267,12 @@ const AudioPlayer = () => {
|
||||
initial={{
|
||||
transform: "translateY(100%)",
|
||||
}}
|
||||
animate={{ transform: "translateY(0)" }}
|
||||
animate={{
|
||||
transform:
|
||||
location.pathname === "/player/audio"
|
||||
? "translateY(100%)"
|
||||
: "translateY(0%)",
|
||||
}}
|
||||
exit={{
|
||||
transform: "translateY(100%)",
|
||||
}}
|
||||
|
||||
@@ -9,7 +9,7 @@ const TagChip = ({
|
||||
linkProps,
|
||||
}: { label: string; linkProps: LinkProps }) => {
|
||||
return (
|
||||
<Link className="tag" {...linkProps}>
|
||||
<Link className="tag" to="/search" search={{ query: label }} {...linkProps}>
|
||||
<Typography variant="subtitle2" fontWeight={300}>
|
||||
{label}
|
||||
</Typography>
|
||||
|
||||
+29
-9
@@ -14,6 +14,7 @@ import { Route as rootRoute } from './routes/__root'
|
||||
import { Route as ApiImport } from './routes/_api'
|
||||
import { Route as IndexImport } from './routes/index'
|
||||
import { Route as ErrorCodeImport } from './routes/error/$code'
|
||||
import { Route as ApiSearchImport } from './routes/_api/search'
|
||||
import { Route as ApiLoginImport } from './routes/_api/login'
|
||||
import { Route as ApiSearchIndexImport } from './routes/_api/search/index'
|
||||
import { Route as ApiPlayerIndexImport } from './routes/_api/player/index'
|
||||
@@ -53,14 +54,19 @@ const ErrorCodeRoute = ErrorCodeImport.update({
|
||||
getParentRoute: () => rootRoute,
|
||||
} as any)
|
||||
|
||||
const ApiSearchRoute = ApiSearchImport.update({
|
||||
path: '/search',
|
||||
getParentRoute: () => ApiRoute,
|
||||
} as any)
|
||||
|
||||
const ApiLoginRoute = ApiLoginImport.update({
|
||||
path: '/login',
|
||||
getParentRoute: () => ApiRoute,
|
||||
} as any)
|
||||
|
||||
const ApiSearchIndexRoute = ApiSearchIndexImport.update({
|
||||
path: '/search/',
|
||||
getParentRoute: () => ApiRoute,
|
||||
path: '/',
|
||||
getParentRoute: () => ApiSearchRoute,
|
||||
} as any)
|
||||
|
||||
const ApiPlayerIndexRoute = ApiPlayerIndexImport.update({
|
||||
@@ -183,6 +189,13 @@ declare module '@tanstack/react-router' {
|
||||
preLoaderRoute: typeof ApiLoginImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
'/_api/search': {
|
||||
id: '/_api/search'
|
||||
path: '/search'
|
||||
fullPath: '/search'
|
||||
preLoaderRoute: typeof ApiSearchImport
|
||||
parentRoute: typeof ApiImport
|
||||
}
|
||||
'/error/$code': {
|
||||
id: '/error/$code'
|
||||
path: '/error/$code'
|
||||
@@ -318,10 +331,10 @@ declare module '@tanstack/react-router' {
|
||||
}
|
||||
'/_api/search/': {
|
||||
id: '/_api/search/'
|
||||
path: '/search'
|
||||
fullPath: '/search'
|
||||
path: '/'
|
||||
fullPath: '/search/'
|
||||
preLoaderRoute: typeof ApiSearchIndexImport
|
||||
parentRoute: typeof ApiImport
|
||||
parentRoute: typeof ApiSearchImport
|
||||
}
|
||||
'/_api/login/$userId/$userName': {
|
||||
id: '/_api/login/$userId/$userName'
|
||||
@@ -343,6 +356,7 @@ export const routeTree = rootRoute.addChildren({
|
||||
ApiLoginManualRoute,
|
||||
ApiLoginUserIdUserNameRoute,
|
||||
}),
|
||||
ApiSearchRoute: ApiSearchRoute.addChildren({ ApiSearchIndexRoute }),
|
||||
ApiAlbumIdRoute,
|
||||
ApiArtistIdRoute,
|
||||
ApiBoxsetIdRoute,
|
||||
@@ -356,7 +370,6 @@ export const routeTree = rootRoute.addChildren({
|
||||
ApiFavoriteIndexRoute,
|
||||
ApiHomeIndexRoute,
|
||||
ApiPlayerIndexRoute,
|
||||
ApiSearchIndexRoute,
|
||||
}),
|
||||
ErrorCodeRoute,
|
||||
SetupServerAddRoute,
|
||||
@@ -387,6 +400,7 @@ export const routeTree = rootRoute.addChildren({
|
||||
"filePath": "_api.tsx",
|
||||
"children": [
|
||||
"/_api/login",
|
||||
"/_api/search",
|
||||
"/_api/album/$id",
|
||||
"/_api/artist/$id",
|
||||
"/_api/boxset/$id",
|
||||
@@ -399,8 +413,7 @@ export const routeTree = rootRoute.addChildren({
|
||||
"/_api/series/$id",
|
||||
"/_api/favorite/",
|
||||
"/_api/home/",
|
||||
"/_api/player/",
|
||||
"/_api/search/"
|
||||
"/_api/player/"
|
||||
]
|
||||
},
|
||||
"/_api/login": {
|
||||
@@ -412,6 +425,13 @@ export const routeTree = rootRoute.addChildren({
|
||||
"/_api/login/$userId/$userName"
|
||||
]
|
||||
},
|
||||
"/_api/search": {
|
||||
"filePath": "_api/search.tsx",
|
||||
"parent": "/_api",
|
||||
"children": [
|
||||
"/_api/search/"
|
||||
]
|
||||
},
|
||||
"/error/$code": {
|
||||
"filePath": "error/$code.tsx"
|
||||
},
|
||||
@@ -486,7 +506,7 @@ export const routeTree = rootRoute.addChildren({
|
||||
},
|
||||
"/_api/search/": {
|
||||
"filePath": "_api/search/index.jsx",
|
||||
"parent": "/_api"
|
||||
"parent": "/_api/search"
|
||||
},
|
||||
"/_api/login/$userId/$userName": {
|
||||
"filePath": "_api/login/$userId.$userName.tsx",
|
||||
|
||||
@@ -264,7 +264,7 @@ export const Route = createRootRouteWithContext<ApiContext>()({
|
||||
<AudioPlayer />
|
||||
<Outlet />
|
||||
<ReactQueryDevtools />
|
||||
{/* <TanStackRouterDevtools /> */}
|
||||
<TanStackRouterDevtools />
|
||||
</SnackbarProvider>
|
||||
</ThemeProvider>
|
||||
</Suspense>
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
.audio {
|
||||
&-hidden{
|
||||
transform: translateY(-100%);
|
||||
}
|
||||
&-info {
|
||||
width: 100%;
|
||||
padding: 4em;
|
||||
@@ -23,6 +26,14 @@
|
||||
border-radius: $border-radius-default;
|
||||
overflow: hidden;
|
||||
}
|
||||
&-icon {
|
||||
font-size: 4em;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
background: rgb(255 255 255 / 0.2);
|
||||
}
|
||||
}
|
||||
&-controls {
|
||||
width: 100%;
|
||||
@@ -51,7 +62,7 @@
|
||||
}
|
||||
&.active{
|
||||
.audio-queue-track-info-name{
|
||||
color: $clr-accent-light;
|
||||
color: $clr-accent-default;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ import PlayNextButton from "@/components/buttons/playNextButton";
|
||||
import PlayPreviousButton from "@/components/buttons/playPreviousButtom";
|
||||
import QueueTrack from "@/components/queueTrack";
|
||||
import { getRuntimeMusic, secToTicks, ticksToSec } from "@/utils/date/time";
|
||||
import { useDrop } from "react-dnd";
|
||||
import { Identifier } from "typescript";
|
||||
import { getLyricsApi } from "@jellyfin/sdk/lib/utils/api/lyrics-api";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
export const Route = createFileRoute("/_api/player/audio")({
|
||||
component: AudioPlayerRoute,
|
||||
@@ -32,6 +32,16 @@ function AudioPlayerRoute() {
|
||||
const [progress, setProgress] = useState<number | number[]>(
|
||||
audioPlayer?.currentTime ?? 0,
|
||||
);
|
||||
|
||||
const lyrics = useQuery({
|
||||
queryKey: ["player", "audio", item?.Id, "lyrics"],
|
||||
queryFn: async () =>
|
||||
await getLyricsApi(api).getLyrics({
|
||||
itemId: item?.Id,
|
||||
}),
|
||||
enabled: Boolean(item?.Id),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
audioPlayer?.addEventListener("timeupdate", () => {
|
||||
setProgress(audioPlayer.currentTime);
|
||||
@@ -42,7 +52,7 @@ function AudioPlayerRoute() {
|
||||
<div className="scrollY padded-top flex flex-column" style={{ gap: "1em" }}>
|
||||
<div className="audio-info-container">
|
||||
<div className="audio-info-image-container">
|
||||
{item?.ImageTags ? (
|
||||
{item?.ImageTags?.Primary ? (
|
||||
<img
|
||||
alt={item.Name ?? "Music"}
|
||||
src={api.getItemImageUrl(item.Id, "Primary", {
|
||||
@@ -51,7 +61,9 @@ function AudioPlayerRoute() {
|
||||
className="audio-info-image"
|
||||
/>
|
||||
) : (
|
||||
<span className="material-symbols-rounded fill">music_note</span>
|
||||
<span className="material-symbols-rounded fill audio-info-image-icon">
|
||||
music_note
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="audio-info">
|
||||
@@ -116,6 +128,7 @@ function AudioPlayerRoute() {
|
||||
<span className="material-symbols-rounded">fast_rewind</span>
|
||||
</IconButton>
|
||||
<Fab
|
||||
disabled={!audioPlayer?.readyState}
|
||||
color="white"
|
||||
size="large"
|
||||
onClick={() =>
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
|
||||
export const Route = createFileRoute("/_api/search")({
|
||||
validateSearch: (search: Record<string, string>): { query: string } => {
|
||||
return {
|
||||
query: search?.query as string,
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -21,8 +21,8 @@ import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
|
||||
import { getPersonsApi } from "@jellyfin/sdk/lib/utils/api/persons-api";
|
||||
import { getSearchApi } from "@jellyfin/sdk/lib/utils/api/search-api";
|
||||
import "./search.scss";
|
||||
import { Dialog } from "@mui/material";
|
||||
import { Outlet, createFileRoute } from "@tanstack/react-router";
|
||||
import { Dialog, Fab } from "@mui/material";
|
||||
import { Outlet, createFileRoute, useNavigate } from "@tanstack/react-router";
|
||||
|
||||
export const Route = createFileRoute("/_api/search/")({
|
||||
component: SearchPage,
|
||||
@@ -31,8 +31,11 @@ export const Route = createFileRoute("/_api/search/")({
|
||||
function SearchPage() {
|
||||
const api = Route.useRouteContext().api;
|
||||
|
||||
const navigate = useNavigate();
|
||||
const { query } = Route.useSearch();
|
||||
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
const searchParam = useDebounce(searchTerm, 500);
|
||||
// const searchParam = useDebounce(query, 500);
|
||||
|
||||
const user = useQuery({
|
||||
queryKey: ["user"],
|
||||
@@ -47,11 +50,11 @@ function SearchPage() {
|
||||
const itemLimit = 12;
|
||||
|
||||
const movies = useQuery({
|
||||
queryKey: ["search", "items", "Movie", searchParam],
|
||||
queryKey: ["search", "items", "Movie", query],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data?.Id,
|
||||
searchTerm,
|
||||
searchTerm: query,
|
||||
includeItemTypes: [BaseItemKind.Movie],
|
||||
recursive: true,
|
||||
limit: itemLimit,
|
||||
@@ -61,11 +64,11 @@ function SearchPage() {
|
||||
enabled: user.isSuccess,
|
||||
});
|
||||
const series = useQuery({
|
||||
queryKey: ["search", "items", "Series", searchParam],
|
||||
queryKey: ["search", "items", "Series", query],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data?.Id,
|
||||
searchTerm,
|
||||
searchTerm: query,
|
||||
includeItemTypes: [BaseItemKind.Series],
|
||||
recursive: true,
|
||||
limit: itemLimit,
|
||||
@@ -75,11 +78,11 @@ function SearchPage() {
|
||||
enabled: user.isSuccess,
|
||||
});
|
||||
const musicAlbum = useQuery({
|
||||
queryKey: ["search", "items", "MusicAlbum", searchParam],
|
||||
queryKey: ["search", "items", "MusicAlbum", query],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data?.Id,
|
||||
searchTerm,
|
||||
searchTerm: query,
|
||||
includeItemTypes: [BaseItemKind.MusicAlbum],
|
||||
recursive: true,
|
||||
limit: itemLimit,
|
||||
@@ -89,11 +92,11 @@ function SearchPage() {
|
||||
enabled: user.isSuccess,
|
||||
});
|
||||
const audio = useQuery({
|
||||
queryKey: ["search", "items", "Audio", searchParam],
|
||||
queryKey: ["search", "items", "Audio", query],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data?.Id,
|
||||
searchTerm,
|
||||
searchTerm: query,
|
||||
includeItemTypes: [BaseItemKind.Audio],
|
||||
recursive: true,
|
||||
limit: itemLimit,
|
||||
@@ -103,11 +106,11 @@ function SearchPage() {
|
||||
enabled: user.isSuccess,
|
||||
});
|
||||
const book = useQuery({
|
||||
queryKey: ["search", "items", "Book", searchParam],
|
||||
queryKey: ["search", "items", "Book", query],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data?.Id,
|
||||
searchTerm,
|
||||
searchTerm: query,
|
||||
includeItemTypes: [BaseItemKind.Book],
|
||||
recursive: true,
|
||||
limit: itemLimit,
|
||||
@@ -117,11 +120,11 @@ function SearchPage() {
|
||||
enabled: user.isSuccess,
|
||||
});
|
||||
const musicArtists = useQuery({
|
||||
queryKey: ["search", "items", "MusicArtists", searchParam],
|
||||
queryKey: ["search", "items", "MusicArtists", query],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.data?.Id,
|
||||
searchTerm,
|
||||
searchTerm: query,
|
||||
includeItemTypes: [BaseItemKind.MusicArtist],
|
||||
recursive: true,
|
||||
limit: itemLimit,
|
||||
@@ -131,11 +134,11 @@ function SearchPage() {
|
||||
enabled: user.isSuccess,
|
||||
});
|
||||
const person = useQuery({
|
||||
queryKey: ["search", "items", "Person", searchParam],
|
||||
queryKey: ["search", "items", "Person", query],
|
||||
queryFn: async () => {
|
||||
const result = await getPersonsApi(api).getPersons({
|
||||
userId: user.data?.Id,
|
||||
searchTerm,
|
||||
searchTerm: query,
|
||||
limit: itemLimit,
|
||||
});
|
||||
return result.data;
|
||||
@@ -143,11 +146,11 @@ function SearchPage() {
|
||||
enabled: user.isSuccess,
|
||||
});
|
||||
const episodes = useQuery({
|
||||
queryKey: ["search", "items", "Episodes", searchParam],
|
||||
queryKey: ["search", "items", "Episodes", query],
|
||||
queryFn: async () => {
|
||||
const result = await getSearchApi(api).getSearchHints({
|
||||
userId: user.data?.Id,
|
||||
searchTerm,
|
||||
searchTerm: query,
|
||||
limit: itemLimit,
|
||||
includeItemTypes: ["Episode"],
|
||||
});
|
||||
@@ -182,50 +185,28 @@ function SearchPage() {
|
||||
placeholder="Search"
|
||||
hiddenLabel
|
||||
className="search-searchbar"
|
||||
inputProps={{
|
||||
className: "search-searchbar-input",
|
||||
}}
|
||||
InputProps={{
|
||||
style: {
|
||||
border: "100px !important",
|
||||
slotProps={{
|
||||
input: {
|
||||
style: {
|
||||
border: "100px !important",
|
||||
},
|
||||
autoFocus: true,
|
||||
},
|
||||
htmlInput: {
|
||||
className: "search-searchbar-input",
|
||||
},
|
||||
autoFocus: true,
|
||||
startAdornment: (
|
||||
<InputAdornment position="start">
|
||||
<div
|
||||
style={{
|
||||
position: "relative",
|
||||
display: "inline-flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
>
|
||||
<CircularProgress
|
||||
style={{
|
||||
position: "absolute",
|
||||
transition: "opacity 250ms",
|
||||
opacity:
|
||||
Boolean(searchTerm) &&
|
||||
(movies.isPending ||
|
||||
series.isPending ||
|
||||
audio.isPending ||
|
||||
musicAlbum.isPending ||
|
||||
musicArtists.isPending ||
|
||||
person.isPending ||
|
||||
book.isPending)
|
||||
? 1
|
||||
: 0,
|
||||
}}
|
||||
size={35}
|
||||
/>
|
||||
<span className="material-symbols-rounded">search</span>
|
||||
</div>
|
||||
</InputAdornment>
|
||||
),
|
||||
}}
|
||||
value={searchTerm}
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
onChange={(e) => setSearchTerm(e.currentTarget.value)}
|
||||
/>
|
||||
<Fab
|
||||
size="medium"
|
||||
onClick={() =>
|
||||
navigate({ search: { query: searchTerm }, replace: true })
|
||||
}
|
||||
>
|
||||
<span className="material-symbols-rounded">search</span>
|
||||
</Fab>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
@@ -242,7 +223,7 @@ function SearchPage() {
|
||||
imageType={"Primary"}
|
||||
cardCaption={item.ProductionYear}
|
||||
cardType="portrait"
|
||||
queryKey={["search", "items", "Movie", searchParam]}
|
||||
queryKey={["search", "items", "Movie", query]}
|
||||
userId={user.data.Id}
|
||||
imageBlurhash={
|
||||
!!item.ImageBlurHashes?.Primary &&
|
||||
@@ -270,7 +251,7 @@ function SearchPage() {
|
||||
: "Present"
|
||||
}`}
|
||||
cardType="portrait"
|
||||
queryKey={["search", "items", "Series", searchParam]}
|
||||
queryKey={["search", "items", "Series", query]}
|
||||
userId={user.data.Id}
|
||||
imageBlurhash={
|
||||
!!item.ImageBlurHashes?.Primary &&
|
||||
@@ -291,7 +272,7 @@ function SearchPage() {
|
||||
item={episode}
|
||||
cardTitle={episode.Series}
|
||||
cardCaption={`S${episode.ParentIndexNumber}:E${episode.IndexNumber} - ${episode.Name}`}
|
||||
queryKey={["search", "items", "Episodes", searchParam]}
|
||||
queryKey={["search", "items", "Episodes", query]}
|
||||
userId={user.data.Id}
|
||||
disableRunTime
|
||||
/>
|
||||
@@ -309,7 +290,7 @@ function SearchPage() {
|
||||
imageType={"Primary"}
|
||||
cardCaption={item.ProductionYear}
|
||||
cardType="square"
|
||||
queryKey={["search", "items", "Audio", searchParam]}
|
||||
queryKey={["search", "items", "Audio", query]}
|
||||
userId={user.data.Id}
|
||||
imageBlurhash={
|
||||
!!item.ImageBlurHashes?.Primary &&
|
||||
@@ -332,7 +313,7 @@ function SearchPage() {
|
||||
imageType={"Primary"}
|
||||
cardCaption={item.AlbumArtist}
|
||||
cardType={"square"}
|
||||
queryKey={["search", "items", "MusicAlbum", searchParam]}
|
||||
queryKey={["search", "items", "MusicAlbum", query]}
|
||||
userId={user.data.Id}
|
||||
imageBlurhash={
|
||||
!!item.ImageBlurHashes?.Primary &&
|
||||
@@ -355,7 +336,7 @@ function SearchPage() {
|
||||
cardCaption={item.ProductionYear}
|
||||
disableOverlay
|
||||
cardType={"portrait"}
|
||||
queryKey={["search", "items", "Book", searchParam]}
|
||||
queryKey={["search", "items", "Book", query]}
|
||||
userId={user.data.Id}
|
||||
imageBlurhash={
|
||||
!!item.ImageBlurHashes?.Primary &&
|
||||
@@ -377,7 +358,7 @@ function SearchPage() {
|
||||
imageType={"Primary"}
|
||||
disableOverlay
|
||||
cardType={"square"}
|
||||
queryKey={["search", "items", "MusicArtists", searchParam]}
|
||||
queryKey={["search", "items", "MusicArtists", query]}
|
||||
userId={user.data.Id}
|
||||
imageBlurhash={
|
||||
!!item.ImageBlurHashes?.Primary &&
|
||||
@@ -399,7 +380,7 @@ function SearchPage() {
|
||||
imageType={"Primary"}
|
||||
disableOverlay
|
||||
cardType={"square"}
|
||||
queryKey={["search", "items", "Person", searchParam]}
|
||||
queryKey={["search", "items", "Person", query]}
|
||||
userId={user.data.Id}
|
||||
imageBlurhash={
|
||||
!!item.ImageBlurHashes?.Primary &&
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
}
|
||||
&-input {
|
||||
text-align: center;
|
||||
padding: 0.75em 1.5em !important;
|
||||
padding: 0.8em 1.5em !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user