refactor: move most routing logic to tanstack
This commit is contained in:
1 parent
b8552ac35d
commit
c22dbefeea
22 files changed
+1191
-1502
No files matched your search
@@ -93,7 +93,6 @@ export const AppBar = () => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [display, setDisplay] = useState(false);
|
||||
const [backButtonVisible, setBackButtonVisible] = useState(false);
|
||||
|
||||
const location = useLocation();
|
||||
|
||||
@@ -133,8 +132,6 @@ export const AppBar = () => {
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const [tabValue] = useSettingsStore((state) => [state.tabValue]);
|
||||
|
||||
const handleLogout = async () => {
|
||||
console.log("Logging out user...");
|
||||
await api.logout();
|
||||
@@ -160,11 +157,6 @@ export const AppBar = () => {
|
||||
setDisplay(true);
|
||||
}
|
||||
|
||||
if (location.pathname === "/home") {
|
||||
setBackButtonVisible(false);
|
||||
} else {
|
||||
setBackButtonVisible(true);
|
||||
}
|
||||
}, [location]);
|
||||
|
||||
const [showDrawer, setShowDrawer] = useState(false);
|
||||
@@ -207,10 +199,10 @@ export const AppBar = () => {
|
||||
</div>
|
||||
|
||||
<div className="flex flex-row" style={{ gap: "0.6em" }}>
|
||||
<IconButton onClick={() => navigate("/search")}>
|
||||
<IconButton onClick={() => navigate({ to: "/search" })}>
|
||||
<div className="material-symbols-rounded">search</div>
|
||||
</IconButton>
|
||||
<IconButton onClick={() => navigate("/favorite")}>
|
||||
<IconButton onClick={() => navigate({ to: "/favorite" })}>
|
||||
<div className="material-symbols-rounded">favorite</div>
|
||||
</IconButton>
|
||||
<IconButton sx={{ p: 0 }} onClick={handleMenuOpen}>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { playItemFromQueue } from "@/utils/store/playback";
|
||||
import useQueue from "@/utils/store/queue";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
|
||||
@@ -13,6 +13,7 @@ import { getTypeIcon } from "../utils/iconsCollection";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import "./queueButton.scss";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useRouteContext } from "@tanstack/react-router";
|
||||
const QueueButton = () => {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
|
||||
@@ -64,14 +64,32 @@ export const Card = ({
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const navigate = useNavigate();
|
||||
const defaultOnClick = () => {
|
||||
if (availableSpecialRoutes.includes(item.Type)) {
|
||||
navigate({ to: `/${item.Type.toLocaleLowerCase()}/${item.Id}` });
|
||||
} else if (!!item.Role || item.Type === BaseItemKind.Person) {
|
||||
navigate({ to: `/person/${item.Id}` });
|
||||
} else if (item.Type === BaseItemKind.MusicArtist) {
|
||||
navigate({ to: `/artist/${item.Id}` });
|
||||
} else {
|
||||
navigate({ to: `/item/${item.Id}` });
|
||||
|
||||
switch (item.Type) {
|
||||
case BaseItemKind.BoxSet:
|
||||
navigate({ to: "/boxset/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.Episode:
|
||||
navigate({ to: "/episode/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.MusicAlbum:
|
||||
navigate({ to: "/album/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.MusicArtist:
|
||||
navigate({ to: "/artist/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.Person:
|
||||
navigate({ to: "/person/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.Series:
|
||||
navigate({ to: "/series/$id", params: { id: item.Id } });
|
||||
break;
|
||||
case BaseItemKind.Playlist:
|
||||
navigate({ to: "/playlist/$id", params: { id: item.Id } });
|
||||
break;
|
||||
default:
|
||||
navigate({ to: "/item/$id", params: { id: item.Id } });
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -17,10 +17,11 @@ import PlayButton from "../../buttons/playButton";
|
||||
|
||||
import TrackList from "../tracksList/index";
|
||||
import "./albumArtist.scss";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { Link, useRouteContext } from "@tanstack/react-router";
|
||||
|
||||
export const ArtistAlbum = ({ user, album, boxProps }) => {
|
||||
const api = useRouteContext({ from: "/" }).api;
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const albumTracks = useQuery({
|
||||
queryKey: ["artist", "album", album.Id],
|
||||
queryFn: async () => {
|
||||
|
||||
@@ -56,16 +56,18 @@ export const LatestMediaSection = ({ latestMediaLib }) => {
|
||||
imageType={"Primary"}
|
||||
cardCaption={
|
||||
item.Type === BaseItemKind.Episode
|
||||
? `S${item.ParentIndexNumber}:E${item.IndexNumber} - ${item.Name}`
|
||||
? `S${item.ParentIndexNumber ?? 0}:E${
|
||||
item.IndexNumber ?? 0
|
||||
} - ${item.Name ?? "Unknown"}`
|
||||
: item.Type === BaseItemKind.Series
|
||||
? `${item.ProductionYear} - ${
|
||||
? `${item.ProductionYear} - ${
|
||||
item.EndDate
|
||||
? new Date(item.EndDate).toLocaleString([], {
|
||||
year: "numeric",
|
||||
})
|
||||
})
|
||||
: "Present"
|
||||
}`
|
||||
: item.ProductionYear
|
||||
}`
|
||||
: item.ProductionYear
|
||||
}
|
||||
cardType={
|
||||
item.Type === BaseItemKind.MusicAlbum ||
|
||||
|
||||
@@ -8,6 +8,7 @@ import { getRuntimeMusic } from "../../../utils/date/time";
|
||||
import { useAudioPlayback } from "../../../utils/store/audioPlayback";
|
||||
import LikeButton from "../../buttons/likeButton";
|
||||
import "./tracksList.scss";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useRouteContext } from "@tanstack/react-router";
|
||||
|
||||
export default function TracksList({
|
||||
@@ -15,7 +16,7 @@ export default function TracksList({
|
||||
user,
|
||||
queryKey,
|
||||
}: { tracks: BaseItemDto[]; user: UserDto; queryKey: [] }) {
|
||||
const api = useRouteContext({ from: "/" }).api;
|
||||
const api = useApiInContext((s) => s.api);
|
||||
|
||||
const [
|
||||
currentItem,
|
||||
@@ -58,11 +59,11 @@ export default function TracksList({
|
||||
</div>
|
||||
{tracks.map((track, index) => (
|
||||
<div
|
||||
className={currentItem.Id === track.Id ? "track playing" : "track"}
|
||||
className={currentItem?.Id === track.Id ? "track playing" : "track"}
|
||||
key={track.Id}
|
||||
onClick={() => playTrack(index)}
|
||||
>
|
||||
{currentItem.Id === track.Id ? (
|
||||
{currentItem?.Id === track.Id ? (
|
||||
<span className="material-symbols-rounded ">equalizer</span>
|
||||
) : (
|
||||
<Typography>{track.IndexNumber ?? "-"}</Typography>
|
||||
@@ -81,7 +82,7 @@ export default function TracksList({
|
||||
>
|
||||
{track.Name}
|
||||
</Typography>
|
||||
<Typography>{getRuntimeMusic(track.RunTimeTicks)}</Typography>
|
||||
<Typography>{getRuntimeMusic(track?.RunTimeTicks)}</Typography>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -6,6 +6,7 @@ import LikeButton from "../buttons/likeButton";
|
||||
import PlayButton from "../buttons/playButton";
|
||||
import TextLink from "../textLink";
|
||||
import "./musicTrack.scss";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useRouteContext } from "@tanstack/react-router";
|
||||
|
||||
/**
|
||||
@@ -33,7 +34,7 @@ const MusicTrack = ({
|
||||
trackIndex,
|
||||
className = "",
|
||||
}) => {
|
||||
const api = useRouteContext({ from: "/" }).api;
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const [currentTrackItem] = useAudioPlayback((state) => [state.item]);
|
||||
|
||||
return (
|
||||
@@ -87,7 +88,7 @@ const MusicTrack = ({
|
||||
variant="subtitle1"
|
||||
style={{
|
||||
color:
|
||||
item.Id === currentTrackItem.Id ? "hsl(337, 96%, 56%)" : "white",
|
||||
item.Id === currentTrackItem?.Id ? "hsl(337, 96%, 56%)" : "white",
|
||||
}}
|
||||
>
|
||||
{item.Name}
|
||||
|
||||
@@ -432,10 +432,13 @@ const Settings = () => {
|
||||
<Typography variant="subtitle2">Client Version:</Typography>
|
||||
<Chip
|
||||
icon={
|
||||
<span className="material-symbols-rounded">
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{ "--wght": 500 }}
|
||||
>
|
||||
{updateInfo.data?.shouldUpdate
|
||||
? "update"
|
||||
: "update_disabled"}
|
||||
? "new_release"
|
||||
: "new_releases"}
|
||||
</span>
|
||||
}
|
||||
label={
|
||||
@@ -443,7 +446,9 @@ const Settings = () => {
|
||||
{applicationVersion}
|
||||
</Typography>
|
||||
}
|
||||
color={updateInfo.data?.shouldUpdate ? "error" : "info"}
|
||||
color={
|
||||
updateInfo.data?.shouldUpdate ? "error" : "success"
|
||||
}
|
||||
size="small"
|
||||
style={{
|
||||
width: "fit-content !important",
|
||||
@@ -461,7 +466,7 @@ const Settings = () => {
|
||||
<Chip
|
||||
icon={
|
||||
<span className="material-symbols-rounded">
|
||||
update
|
||||
new_releases
|
||||
</span>
|
||||
}
|
||||
label={
|
||||
|
||||
Reference in new issue
Block a user