feat: add new preferences page
This commit is contained in:
22 files changed
+790
-131
No files matched your search
@@ -45,40 +45,8 @@ import {
|
||||
ListItemText,
|
||||
} from "@mui/material";
|
||||
import BackButton from "../buttons/backButton";
|
||||
import ListItemLink from "../listItemLink";
|
||||
|
||||
interface ListItemLinkProps {
|
||||
icon?: ReactNode;
|
||||
primary: string;
|
||||
to: string;
|
||||
}
|
||||
|
||||
function ListItemLink(props: ListItemLinkProps) {
|
||||
const { icon, primary, to } = props;
|
||||
|
||||
return (
|
||||
<li>
|
||||
{/* @ts-ignore */}
|
||||
<ListItem
|
||||
component={Link}
|
||||
activeClassName="active"
|
||||
className="library-drawer-item"
|
||||
to={to}
|
||||
>
|
||||
<ListItemButton
|
||||
style={{
|
||||
borderRadius: "100px",
|
||||
gap: "0.85em",
|
||||
color: "white",
|
||||
textDecoration: "none",
|
||||
}}
|
||||
>
|
||||
<div className="material-symbols-rounded">{icon}</div>
|
||||
<ListItemText primary={primary} />
|
||||
</ListItemButton>
|
||||
</ListItem>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
||||
const MemoizeBackButton = React.memo(BackButton);
|
||||
|
||||
@@ -151,7 +119,8 @@ export const AppBar = () => {
|
||||
location.pathname.includes("server") ||
|
||||
location.pathname === "/player" ||
|
||||
location.pathname.includes("error") ||
|
||||
location.pathname === "/"
|
||||
location.pathname === "/" ||
|
||||
location.pathname.includes("settings")
|
||||
) {
|
||||
setDisplay(false);
|
||||
} else {
|
||||
@@ -290,6 +259,18 @@ export const AppBar = () => {
|
||||
</ListItemIcon>
|
||||
Settings
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
onClick={() => {
|
||||
navigate({ to: "/settings/preferences" });
|
||||
setSettingsTabValue(1);
|
||||
handleMenuClose();
|
||||
}}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<div className="material-symbols-rounded">tune</div>
|
||||
</ListItemIcon>
|
||||
Preferences
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
onClick={() => {
|
||||
setSettingsDialogOpen(true);
|
||||
@@ -327,10 +308,16 @@ export const AppBar = () => {
|
||||
</List>
|
||||
<Divider variant="middle" />
|
||||
<List>
|
||||
<ListItemLink to="/home" icon="home" primary="Home" />
|
||||
<ListItemLink
|
||||
className="library-drawer-item"
|
||||
to="/home"
|
||||
icon="home"
|
||||
primary="Home"
|
||||
/>
|
||||
{libraries.isSuccess &&
|
||||
libraries.data?.Items?.map((library) => (
|
||||
<ListItemLink
|
||||
className="library-drawer-item"
|
||||
key={library.Id}
|
||||
to={`/library/${library.Id}`}
|
||||
icon={
|
||||
|
||||
@@ -34,6 +34,7 @@ import getSubtitle from "@/utils/methods/getSubtitles";
|
||||
import playbackProfile from "@/utils/playback-profiles";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { usePhotosPlayback } from "@/utils/store/photosPlayback";
|
||||
import { getDisplayPreferencesApi } from "@jellyfin/sdk/lib/utils/api/display-preferences-api";
|
||||
import { getMediaInfoApi } from "@jellyfin/sdk/lib/utils/api/media-info-api";
|
||||
import { getMediaSegmentsApi } from "@jellyfin/sdk/lib/utils/api/media-segments-api";
|
||||
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
|
||||
@@ -428,7 +429,7 @@ const PlayButton = ({
|
||||
episodeIndex: index,
|
||||
};
|
||||
},
|
||||
onSuccess: (result: PlayResult | null) => {
|
||||
onSuccess: async (result: PlayResult | null) => {
|
||||
if (!api) {
|
||||
console.error("API is not available");
|
||||
enqueueSnackbar("API is not available", { variant: "error" });
|
||||
@@ -450,6 +451,14 @@ const PlayButton = ({
|
||||
return;
|
||||
}
|
||||
|
||||
const displayPreferences = await getDisplayPreferencesApi(
|
||||
api,
|
||||
).getDisplayPreferences({
|
||||
userId: userId,
|
||||
displayPreferencesId: api.deviceInfo.id,
|
||||
client: "blink",
|
||||
});
|
||||
|
||||
if (audio) {
|
||||
// Album/Individual audio track playback
|
||||
const playbackUrl = generateAudioStreamUrl(
|
||||
@@ -531,6 +540,14 @@ const PlayButton = ({
|
||||
const startPosition =
|
||||
result?.item?.Items?.[episodeIndex].UserData?.PlaybackPositionTicks;
|
||||
|
||||
let initVolume = "1";
|
||||
if (
|
||||
displayPreferences.data.CustomPrefs?.RememberVolume &&
|
||||
displayPreferences.data.CustomPrefs?.Volume
|
||||
) {
|
||||
initVolume = displayPreferences.data.CustomPrefs?.Volume;
|
||||
}
|
||||
|
||||
playItem(
|
||||
itemName,
|
||||
episodeTitle,
|
||||
@@ -549,6 +566,7 @@ const PlayButton = ({
|
||||
subtitle,
|
||||
result?.introInfo,
|
||||
audio,
|
||||
Number(initVolume),
|
||||
);
|
||||
navigate({ to: "/player" });
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ const CardComponent = ({
|
||||
};
|
||||
|
||||
const { ref, inView } = useInView({
|
||||
threshold: 0,
|
||||
threshold: 0.1,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// Write a react component that included an MUI circluar progress element utilizing NProgrss
|
||||
|
||||
import { CircularProgress } from "@mui/material";
|
||||
import { useNProgress } from "@tanem/react-nprogress";
|
||||
import React from "react";
|
||||
|
||||
const CircularPageLoadingAnimation = () => {
|
||||
const { progress } = useNProgress({
|
||||
isAnimating: true,
|
||||
});
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
pointerEvents: "none",
|
||||
position: "absolute",
|
||||
top: "50%",
|
||||
left: "50%",
|
||||
transform: "translate(-50%, -50%)",
|
||||
zIndex: "10001",
|
||||
}}
|
||||
>
|
||||
<CircularProgress
|
||||
// variant="indeterminate"
|
||||
sx={{
|
||||
transitionDuration: "0.3s",
|
||||
transform: `scale(${progress})`,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default CircularPageLoadingAnimation;
|
||||
@@ -0,0 +1,37 @@
|
||||
import { ListItem, ListItemButton, ListItemText } from "@mui/material";
|
||||
import { Link, type ReactNode } from "@tanstack/react-router";
|
||||
import React from "react";
|
||||
|
||||
interface ListItemLinkProps {
|
||||
icon?: ReactNode;
|
||||
primary: string;
|
||||
to: string;
|
||||
className?: string;
|
||||
}
|
||||
export default function ListItemLink(props: ListItemLinkProps) {
|
||||
const { icon, primary, to, className } = props;
|
||||
|
||||
return (
|
||||
<li>
|
||||
{/* @ts-ignore */}
|
||||
<ListItem
|
||||
component={Link}
|
||||
activeClassName="active"
|
||||
className={className}
|
||||
to={to}
|
||||
>
|
||||
<ListItemButton
|
||||
style={{
|
||||
borderRadius: "100px",
|
||||
gap: "0.85em",
|
||||
color: "white",
|
||||
textDecoration: "none",
|
||||
}}
|
||||
>
|
||||
<div className="material-symbols-rounded">{icon}</div>
|
||||
<ListItemText primary={primary} />
|
||||
</ListItemButton>
|
||||
</ListItem>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import type { CultureDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import {
|
||||
FormControlLabel,
|
||||
MenuItem,
|
||||
TextField,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import React, { useState } from "react";
|
||||
|
||||
const SettingOptionSelect = ({
|
||||
setting,
|
||||
options,
|
||||
userValue,
|
||||
}: {
|
||||
setting: { name: string; description: string };
|
||||
options: CultureDto[];
|
||||
userValue: string | null;
|
||||
}) => {
|
||||
const [value, setValue] = useState(
|
||||
userValue === "" ? "anyLanguage" : userValue,
|
||||
);
|
||||
return (
|
||||
<FormControlLabel
|
||||
value={value}
|
||||
control={
|
||||
<TextField select onChange={(e) => setValue(e.target.value)}>
|
||||
<MenuItem key={"anyLanguage"} value={"anyLanguage"}>
|
||||
Any Language
|
||||
</MenuItem>
|
||||
{options.map((option) => (
|
||||
<MenuItem
|
||||
key={option.ThreeLetterISOLanguageName}
|
||||
value={option.ThreeLetterISOLanguageName ?? "none"}
|
||||
>
|
||||
{option.DisplayName}
|
||||
</MenuItem>
|
||||
))}
|
||||
</TextField>
|
||||
}
|
||||
label={
|
||||
<div className="settings-option-info">
|
||||
<Typography variant="subtitle1" fontWeight={400}>
|
||||
{setting.name}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="caption"
|
||||
className="settings-option-info-caption"
|
||||
>
|
||||
{setting.description}
|
||||
</Typography>
|
||||
</div>
|
||||
}
|
||||
labelPlacement="start"
|
||||
className="settings-option"
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default SettingOptionSelect;
|
||||
@@ -25,6 +25,8 @@ import logo from "@/assets/logo.png";
|
||||
|
||||
import { jellyfin, useApiInContext } from "@/utils/store/api";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
import { getDisplayPreferencesApi } from "@jellyfin/sdk/lib/utils/api/display-preferences-api";
|
||||
import { getLocalizationApi } from "@jellyfin/sdk/lib/utils/api/localization-api";
|
||||
import { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import "./settings.scss";
|
||||
@@ -46,6 +48,7 @@ import { relaunch } from "@tauri-apps/plugin-process";
|
||||
import { check } from "@tauri-apps/plugin-updater";
|
||||
import { useSnackbar } from "notistack";
|
||||
import SettingOption from "../settingOption";
|
||||
import SettingOptionSelect from "../settingOptionSelect";
|
||||
|
||||
const motionConfig = {
|
||||
initial: {
|
||||
@@ -65,6 +68,8 @@ const Settings = () => {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const createApi = useApiInContext((s) => s.createApi);
|
||||
|
||||
const user = useCentralStore((state) => state.currentUser);
|
||||
|
||||
const systemInfo = useQuery({
|
||||
queryKey: ["about", "systemInfo"],
|
||||
queryFn: async () => {
|
||||
@@ -98,8 +103,34 @@ const Settings = () => {
|
||||
enabled: open,
|
||||
});
|
||||
|
||||
const cultures = useQuery({
|
||||
queryKey: ["settings", "cultures"],
|
||||
queryFn: async () => {
|
||||
if (!api) return;
|
||||
const result = await getLocalizationApi(api).getCultures();
|
||||
return result.data;
|
||||
},
|
||||
enabled: open,
|
||||
});
|
||||
|
||||
const clientSettingsOnServer = useQuery({
|
||||
queryKey: ["settings", "clientSettings"],
|
||||
queryFn: async () => {
|
||||
if (!api) return;
|
||||
const result = await getDisplayPreferencesApi(api).getDisplayPreferences({
|
||||
client: "blink",
|
||||
userId: user?.Id,
|
||||
displayPreferencesId: api.deviceInfo.id,
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
enabled: open,
|
||||
});
|
||||
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
// Server Management
|
||||
const [updating, setUpdating] = useState(false);
|
||||
const [addServerDialog, setAddServerDialog] = useState(false);
|
||||
const [serverIp, setServerIp] = useState("");
|
||||
@@ -203,7 +234,7 @@ const Settings = () => {
|
||||
open={open}
|
||||
fullWidth
|
||||
maxWidth="md"
|
||||
PaperProps={paperProps}
|
||||
slotProps={{ paper: paperProps }}
|
||||
hideBackdrop
|
||||
onClose={handleClose}
|
||||
>
|
||||
@@ -239,6 +270,17 @@ const Settings = () => {
|
||||
height: "48px",
|
||||
}}
|
||||
/>
|
||||
<Tab
|
||||
icon={<span className="material-symbols-rounded">tune</span>}
|
||||
iconPosition="start"
|
||||
value={3}
|
||||
label="Perferences"
|
||||
className="settings-tab"
|
||||
sx={{
|
||||
minHeight: "48px",
|
||||
height: "48px",
|
||||
}}
|
||||
/>
|
||||
<Tab
|
||||
icon={<span className="material-symbols-rounded">info</span>}
|
||||
iconPosition="start"
|
||||
@@ -411,6 +453,22 @@ const Settings = () => {
|
||||
</motion.div>
|
||||
)}
|
||||
|
||||
{/* Preferences */}
|
||||
{tabValue === 3 && cultures.isSuccess && (
|
||||
<div className="settings-container">
|
||||
<SettingOptionSelect
|
||||
setting={{
|
||||
name: "Preferred Audio Language",
|
||||
description: "Select your preferred audio language.",
|
||||
}}
|
||||
userValue={
|
||||
user?.Configuration?.AudioLanguagePreference ?? "anyLanguage"
|
||||
}
|
||||
options={cultures.data ?? []}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* About */}
|
||||
{tabValue === 10 && (
|
||||
<div className="settings-container settings-about">
|
||||
|
||||
Reference in new issue
Block a user