update
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
This commit is contained in:
1 parent
7fb3d6cfa4
commit
cbb750a413
67 files changed
+5399
-3413
No files matched your search
@@ -0,0 +1,72 @@
|
||||
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getUserViewApi } from "@jellyfin/sdk/lib/utils/api/user-view-api";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useMemo } from "react";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
|
||||
export type AppNavItem =
|
||||
| {
|
||||
kind: "home";
|
||||
key: "home";
|
||||
label: string;
|
||||
}
|
||||
| {
|
||||
kind: "library";
|
||||
key: "movies" | "tvshows" | "music";
|
||||
label: string;
|
||||
libraryId: string;
|
||||
};
|
||||
|
||||
const LIBRARY_NAV = [
|
||||
{ key: "movies", collectionType: "movies", label: "Фильмы" },
|
||||
{ key: "tvshows", collectionType: "tvshows", label: "Сериалы" },
|
||||
{ key: "music", collectionType: "music", label: "Музыка" },
|
||||
] as const;
|
||||
|
||||
/**
|
||||
* The four permanent sections of the app titlebar. Library items are resolved
|
||||
* from the same cached `getUserViews` query the home page already loads.
|
||||
*/
|
||||
export const useAppNavigation = (enabled: boolean) => {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const user = useCentralStore((s) => s.currentUser);
|
||||
|
||||
const libraries = useQuery({
|
||||
queryKey: ["libraries"],
|
||||
queryFn: async () => {
|
||||
if (!api?.accessToken || !user?.Id) return undefined;
|
||||
const response = await getUserViewApi(api).getUserViews({
|
||||
userId: user.Id,
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
enabled: enabled && !!api?.accessToken && !!user?.Id,
|
||||
staleTime: 5 * 60 * 1000,
|
||||
networkMode: "always",
|
||||
});
|
||||
|
||||
const items = useMemo<AppNavItem[]>(() => {
|
||||
const list: AppNavItem[] = [
|
||||
{ kind: "home", key: "home", label: "Главная" },
|
||||
];
|
||||
const views: BaseItemDto[] = libraries.data?.Items ?? [];
|
||||
|
||||
for (const entry of LIBRARY_NAV) {
|
||||
const library = views.find(
|
||||
(view) => view.Id && view.CollectionType === entry.collectionType,
|
||||
);
|
||||
if (!library?.Id) continue;
|
||||
list.push({
|
||||
kind: "library",
|
||||
key: entry.key,
|
||||
label: entry.label,
|
||||
libraryId: library.Id,
|
||||
});
|
||||
}
|
||||
|
||||
return list;
|
||||
}, [libraries.data]);
|
||||
|
||||
return items;
|
||||
};
|
||||
Reference in new issue
Block a user