feat: add new preferences page
This commit is contained in:
22 files changed
+790
-131
No files matched your search
@@ -57,25 +57,6 @@ type SortByObject = { title: string; value: string };
|
||||
type ViewObject = { title: string; value: BaseItemKind | "Artist" };
|
||||
// type allowedFilters = ["movies", "tvshows", "music", "books"];
|
||||
|
||||
const useWindowWidth = () => {
|
||||
const [width, setWidth] = React.useState(window.innerWidth);
|
||||
|
||||
React.useEffect(() => {
|
||||
const onResize = () => setWidth(window.innerWidth);
|
||||
|
||||
window.addEventListener("resize", onResize, {
|
||||
capture: false,
|
||||
passive: true,
|
||||
});
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("resize", onResize);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return width;
|
||||
};
|
||||
|
||||
export const Route = createFileRoute("/_api/library/$id")({
|
||||
component: Library,
|
||||
});
|
||||
@@ -725,36 +706,6 @@ function Library() {
|
||||
}
|
||||
}, [currentViewType]);
|
||||
|
||||
const cardSize = useMemo(
|
||||
() =>
|
||||
items.data?.Items?.[0]?.Type === BaseItemKind.MusicAlbum ||
|
||||
items.data?.Items?.[0]?.Type === BaseItemKind.Audio ||
|
||||
items.data?.Items?.[0]?.Type === BaseItemKind.Genre ||
|
||||
items.data?.Items?.[0]?.Type === BaseItemKind.MusicGenre ||
|
||||
items.data?.Items?.[0]?.Type === BaseItemKind.Studio ||
|
||||
items.data?.Items?.[0]?.Type === BaseItemKind.Playlist
|
||||
? 260
|
||||
: 356,
|
||||
[items.dataUpdatedAt],
|
||||
); // This sets the approx height of each card in library to estimate no of virtual rows to render
|
||||
const windowWidth = useWindowWidth();
|
||||
const itemsPerRow = useMemo(
|
||||
() => Math.max(1, Math.floor(windowWidth / 200)),
|
||||
[windowWidth],
|
||||
);
|
||||
const count = useMemo(
|
||||
() =>
|
||||
(items.data?.TotalRecordCount ?? 1) > itemsPerRow
|
||||
? Math.ceil((items.data?.TotalRecordCount ?? 1) / itemsPerRow)
|
||||
: 1,
|
||||
[itemsPerRow, items.dataUpdatedAt],
|
||||
);
|
||||
const virtualizer = useWindowVirtualizer({
|
||||
count,
|
||||
estimateSize: () => cardSize,
|
||||
overscan: 1,
|
||||
});
|
||||
|
||||
const rowVirtualizer = useWindowVirtualizer({
|
||||
count: items.data?.TotalRecordCount ?? 1,
|
||||
estimateSize: () => 80,
|
||||
|
||||
@@ -68,6 +68,7 @@ import BubbleSlider from "@/components/bubbleSlider";
|
||||
import videoPlayerReducer, {
|
||||
VideoPlayerActionKind,
|
||||
} from "@/utils/reducers/videoPlayerReducer";
|
||||
import { getDisplayPreferencesApi } from "@jellyfin/sdk/lib/utils/api/display-preferences-api";
|
||||
|
||||
const ticksDisplay = (ticks: number) => {
|
||||
const time = Math.round(ticks / 10000);
|
||||
@@ -161,6 +162,7 @@ function VideoPlayer() {
|
||||
mediaSource,
|
||||
playsessionId,
|
||||
mediaSegments,
|
||||
initVolume,
|
||||
] = usePlaybackStore((state) => [
|
||||
state.playbackStream,
|
||||
state.item,
|
||||
@@ -171,6 +173,7 @@ function VideoPlayer() {
|
||||
state.mediaSource,
|
||||
state.playsessionId,
|
||||
state.intro,
|
||||
state.volume,
|
||||
]);
|
||||
|
||||
const introInfo = mediaSegments?.Items?.find(
|
||||
@@ -198,7 +201,6 @@ function VideoPlayer() {
|
||||
const [showVolumeControl, setShowVolumeControl] = useState(false);
|
||||
|
||||
// Control States
|
||||
|
||||
const [
|
||||
{
|
||||
ref,
|
||||
@@ -219,7 +221,7 @@ function VideoPlayer() {
|
||||
isPlayerPlaying: true,
|
||||
isPlayerMuted: false,
|
||||
isPlayerFullscreen: false,
|
||||
playerVolume: 1,
|
||||
playerVolume: initVolume ?? 1,
|
||||
isSeeking: false,
|
||||
sliderSeek: startPosition,
|
||||
progress: startPosition,
|
||||
@@ -632,6 +634,25 @@ function VideoPlayer() {
|
||||
player.current?.seekTo(ticksToSec(next?.StartPositionTicks ?? 0));
|
||||
}, [progress, playsessionId]);
|
||||
|
||||
useEffect(() => {
|
||||
async function setVolumeInServer() {
|
||||
if (!api) return null;
|
||||
await getDisplayPreferencesApi(api).updateDisplayPreferences({
|
||||
userId: user?.Id,
|
||||
client: "blink",
|
||||
displayPreferencesId: api.deviceInfo.id,
|
||||
displayPreferencesDto: {
|
||||
CustomPrefs: {
|
||||
Volume: String(playerVolume),
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
if (user?.Id && initVolume !== playerVolume && initVolume !== undefined) {
|
||||
setVolumeInServer();
|
||||
}
|
||||
}, [playerVolume]);
|
||||
|
||||
return (
|
||||
<div className="video-player">
|
||||
<AnimatePresence>
|
||||
@@ -944,16 +965,18 @@ function VideoPlayer() {
|
||||
max={1}
|
||||
size="small"
|
||||
value={isPlayerMuted ? 0 : playerVolume}
|
||||
onChange={(_, newValue) => {
|
||||
Array.isArray(newValue)
|
||||
? dispatch({
|
||||
type: VideoPlayerActionKind.SET_PLAYER_VOLUME,
|
||||
payload: newValue[0],
|
||||
})
|
||||
: dispatch({
|
||||
type: VideoPlayerActionKind.SET_PLAYER_VOLUME,
|
||||
payload: newValue,
|
||||
});
|
||||
onChange={async (_, newValue) => {
|
||||
if (api && Array.isArray(newValue)) {
|
||||
dispatch({
|
||||
type: VideoPlayerActionKind.SET_PLAYER_VOLUME,
|
||||
payload: newValue[0],
|
||||
});
|
||||
} else {
|
||||
dispatch({
|
||||
type: VideoPlayerActionKind.SET_PLAYER_VOLUME,
|
||||
payload: newValue,
|
||||
});
|
||||
}
|
||||
if (newValue === 0)
|
||||
dispatch({
|
||||
type: VideoPlayerActionKind.SET_PLAYER_MUTED,
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
.settings {
|
||||
&-page {
|
||||
&-container {
|
||||
display: grid;
|
||||
grid-template-columns: 16em 1fr;
|
||||
padding: 0;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
}
|
||||
&-scrollY {
|
||||
padding: 2em;
|
||||
}
|
||||
}
|
||||
&-form{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
justify-content: flex-start;
|
||||
gap: 1em;
|
||||
width: 100%;
|
||||
margin-top: 2em;
|
||||
}
|
||||
&-sidebar {
|
||||
// padding-top: 4.4em !important;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
background: rgb(0 0 0 / 0.4);
|
||||
border-right: 1px solid rgba(255, 255, 255, 0.12);
|
||||
// padding-top: 1em;s
|
||||
&-controls {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
gap: 0.5em;
|
||||
width: 100%;
|
||||
padding: 1em;
|
||||
}
|
||||
&-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
width: 100%;
|
||||
padding: 1em;
|
||||
flex-direction: row;
|
||||
gap: 1em;
|
||||
&-image {
|
||||
$size: 3em;
|
||||
width: $size;
|
||||
height: $size;
|
||||
border-radius: 50%;
|
||||
}
|
||||
}
|
||||
&-list-item {
|
||||
width: 100%;
|
||||
.MuiButtonBase-root {
|
||||
border-radius: 5px !important;
|
||||
}
|
||||
&.active .MuiButtonBase-root {
|
||||
--fill: 1;
|
||||
background: $clr-gradient-default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import { useBackdropStore } from "@/utils/store/backdrop";
|
||||
import {
|
||||
Link,
|
||||
Outlet,
|
||||
createFileRoute,
|
||||
useNavigate,
|
||||
} from "@tanstack/react-router";
|
||||
import React, { useCallback, useEffect } from "react";
|
||||
|
||||
import "./settings.scss";
|
||||
import BackButton from "@/components/buttons/backButton";
|
||||
import ListItemLink from "@/components/listItemLink";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
import { Button, Divider, IconButton, List, Typography } from "@mui/material";
|
||||
|
||||
export const Route = createFileRoute("/_api/settings")({
|
||||
component: SettingsRoute,
|
||||
});
|
||||
|
||||
function SettingsRoute() {
|
||||
const setBackdrop = useBackdropStore((s) => s.setBackdrop);
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const user = useCentralStore((s) => s.currentUser);
|
||||
useEffect(() => {
|
||||
setBackdrop("", "none");
|
||||
});
|
||||
const navigate = useNavigate();
|
||||
const handleNavigateHome = useCallback(() => {
|
||||
navigate({ to: "/home" });
|
||||
}, []);
|
||||
return (
|
||||
<div className="settings-page-container">
|
||||
<div className="settings-sidebar">
|
||||
<div className="settings-sidebar-controls">
|
||||
<BackButton />
|
||||
<IconButton onClick={handleNavigateHome}>
|
||||
<span className="material-symbols-rounded">home</span>
|
||||
</IconButton>
|
||||
</div>
|
||||
<Divider flexItem />
|
||||
<div className="settings-sidebar-header">
|
||||
<img
|
||||
className="settings-sidebar-header-image"
|
||||
src={`${api?.basePath}/Users/${user?.Id}/Images/Primary`}
|
||||
alt="user"
|
||||
/>
|
||||
<div className="flex flex-column">
|
||||
<Typography variant="h6">{user?.Name}</Typography>
|
||||
<Typography variant="caption" style={{ opacity: 0.5 }}>
|
||||
{user?.Policy?.IsAdministrator ? "administrator" : "user"}
|
||||
</Typography>
|
||||
</div>
|
||||
</div>
|
||||
<Divider flexItem variant="middle" />
|
||||
<List
|
||||
component="nav"
|
||||
aria-label="main mailbox folders"
|
||||
className="settings-sidebar-list"
|
||||
style={{
|
||||
width: "100%",
|
||||
}}
|
||||
>
|
||||
<ListItemLink
|
||||
to="/settings/preferences"
|
||||
icon="tune"
|
||||
primary="Preferences"
|
||||
className="settings-sidebar-list-item"
|
||||
/>
|
||||
</List>
|
||||
</div>
|
||||
<Outlet />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
import {
|
||||
Button,
|
||||
FormControlLabel,
|
||||
MenuItem,
|
||||
Switch,
|
||||
TextField,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import React from "react";
|
||||
|
||||
import "../settings.scss";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
import { getLocalizationApi } from "@jellyfin/sdk/lib/utils/api/localization-api";
|
||||
import { useQuery, useSuspenseQuery } from "@tanstack/react-query";
|
||||
|
||||
import CircularPageLoadingAnimation from "@/components/circularPageLoadingAnimation";
|
||||
// import { getDisplayPreferencesApi } from "@jellyfin/sdk/lib/utils/api/display-preferences-api";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { useForm } from "@tanstack/react-form";
|
||||
import { useSnackbar } from "notistack";
|
||||
|
||||
export const Route = createFileRoute("/_api/settings/preferences")({
|
||||
component: RouteComponent,
|
||||
pendingComponent: () => <CircularPageLoadingAnimation />,
|
||||
});
|
||||
|
||||
function RouteComponent() {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const user = useCentralStore((s) => s.currentUser);
|
||||
const cultures = useSuspenseQuery({
|
||||
queryKey: ["settings", "cultures"],
|
||||
queryFn: async () => {
|
||||
if (!api) return;
|
||||
const result = await getLocalizationApi(api).getCultures();
|
||||
return result.data;
|
||||
},
|
||||
});
|
||||
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
|
||||
const form = useForm({
|
||||
defaultValues: {
|
||||
preferredAudioLanguage:
|
||||
user?.Configuration?.AudioLanguagePreference ?? "anyLanguage",
|
||||
playDefaultAudioTrack: user?.Configuration?.PlayDefaultAudioTrack,
|
||||
},
|
||||
onSubmit: async (values) => {
|
||||
if (!api) return;
|
||||
await getUserApi(api).updateUserConfiguration({
|
||||
userId: user?.Id,
|
||||
userConfiguration: {
|
||||
AudioLanguagePreference: values.value.preferredAudioLanguage,
|
||||
PlayDefaultAudioTrack: values.value.playDefaultAudioTrack,
|
||||
},
|
||||
});
|
||||
// await getDisplayPreferencesApi(api).updateDisplayPreferences({
|
||||
// userId: user?.Id,
|
||||
// displayPreferencesId: api.deviceInfo.id,
|
||||
// client: "blink",
|
||||
// displayPreferencesDto: {
|
||||
// ...displayPreferences.data,
|
||||
// CustomPrefs: {
|
||||
// RememberVolume: JSON.stringify(values.value.rememberVolume),
|
||||
// },
|
||||
// },
|
||||
// });
|
||||
enqueueSnackbar("Settings saved", {
|
||||
variant: "success",
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="settings-page-scrollY">
|
||||
<Typography variant="h4">Preferences</Typography>
|
||||
{/* <form.Pro */}
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
form.handleSubmit();
|
||||
}}
|
||||
onError={() =>
|
||||
enqueueSnackbar("Error saving settings", { variant: "error" })
|
||||
}
|
||||
className="settings-form"
|
||||
>
|
||||
<form.Field
|
||||
name="preferredAudioLanguage"
|
||||
// children={}
|
||||
>
|
||||
{(field) => {
|
||||
return (
|
||||
<FormControlLabel
|
||||
control={
|
||||
<TextField
|
||||
defaultValue={field.state.value}
|
||||
select
|
||||
hiddenLabel
|
||||
variant="filled"
|
||||
onChange={(e) => field.handleChange(e.target.value)}
|
||||
onBlur={field.handleBlur}
|
||||
style={{
|
||||
width: "18em",
|
||||
}}
|
||||
>
|
||||
<MenuItem key={"anyLanguage"} value={"anyLanguage"}>
|
||||
Any Language
|
||||
</MenuItem>
|
||||
{cultures.data?.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}>
|
||||
Preferred Audio Language
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="caption"
|
||||
className="settings-option-info-caption"
|
||||
>
|
||||
Choose your preferred audio language.
|
||||
</Typography>
|
||||
</div>
|
||||
}
|
||||
labelPlacement="start"
|
||||
className="settings-option"
|
||||
/>
|
||||
);
|
||||
}}
|
||||
</form.Field>
|
||||
<form.Field
|
||||
name="playDefaultAudioTrack"
|
||||
// children={}
|
||||
>
|
||||
{(field) => {
|
||||
return (
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Switch
|
||||
checked={field.state.value}
|
||||
onChange={(_, checked) => field.handleChange(checked)}
|
||||
onBlur={field.handleBlur}
|
||||
/>
|
||||
}
|
||||
label={
|
||||
<div className="settings-option-info">
|
||||
<Typography variant="subtitle1" fontWeight={400}>
|
||||
Play default audio track regardless of language
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="caption"
|
||||
className="settings-option-info-caption"
|
||||
>
|
||||
Play the default audio track of the media item, even if it
|
||||
does not match your preferred audio language.
|
||||
</Typography>
|
||||
</div>
|
||||
}
|
||||
labelPlacement="start"
|
||||
className="settings-option"
|
||||
/>
|
||||
);
|
||||
}}
|
||||
</form.Field>
|
||||
<Button type="submit" size="large" variant="contained">
|
||||
Save
|
||||
</Button>
|
||||
</form>
|
||||
{/* <FormControlLabel
|
||||
value={currentCulture}
|
||||
control={
|
||||
<TextField select onChange={(e) => setCurrentCulture(e.target.value)}>
|
||||
<MenuItem key={"anyLanguage"} value={"anyLanguage"}>
|
||||
Any Language
|
||||
</MenuItem>
|
||||
{cultures.data?.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"
|
||||
/> */}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user