1- import { Typography , Box } from "@mui/material" ;
1+ import { Typography , Box , Divider , CircularProgress } from "@mui/material" ;
22import React , { useEffect } from "react" ;
3- import {
4- getAllLibraries
5- } from "../../plex" ;
3+ import { getAllLibraries } from "../../plex" ;
64import CheckBoxOption from "../../components/settings/CheckBoxOption" ;
75import { useUserSettings } from "../../states/UserSettingsState" ;
86
9-
107function SettingsLibraries ( ) {
11- const [ libraries , setLibraries ] = React . useState < Plex . LibarySection [ ] > ( [ ] ) ;
12- const [ loading , setLoading ] = React . useState ( true ) ;
13- const { settings, setSetting } = useUserSettings ( ) ;
8+ const [ libraries , setLibraries ] = React . useState < Plex . LibarySection [ ] > ( [ ] ) ;
9+ const [ loading , setLoading ] = React . useState ( true ) ;
10+ const { settings, setSetting } = useUserSettings ( ) ;
1411
15- useEffect ( ( ) => {
16- async function fetchData ( ) {
17- setLoading ( true ) ;
18- try {
19- const librariesData = await getAllLibraries ( ) ;
20-
21-
22- const filteredLibraries = librariesData . filter ( ( lib ) =>
23- [ "movie" , "show" ] . includes ( lib . type )
24- ) ;
12+ useEffect ( ( ) => {
13+ async function fetchData ( ) {
14+ setLoading ( true ) ;
15+ try {
16+ const librariesData = await getAllLibraries ( ) ;
17+
18+ const filteredLibraries = librariesData . filter ( ( lib ) =>
19+ [ "movie" , "show" ] . includes ( lib . type )
20+ ) ;
2521
26- setLibraries ( filteredLibraries ) ;
22+ setLibraries ( filteredLibraries ) ;
2723
28- console . log ( "filteredLibraries" , filteredLibraries )
29-
30- } catch ( error ) {
31- console . error ( "Error fetching data" , error ) ;
32- } finally {
33- setLoading ( false ) ;
34- }
35- }
36-
37- fetchData ( ) ;
38- } , [ ] ) ;
24+ console . log ( "filteredLibraries" , filteredLibraries ) ;
25+ } catch ( error ) {
26+ console . error ( "Error fetching data" , error ) ;
27+ } finally {
28+ setLoading ( false ) ;
29+ }
30+ }
31+
32+ fetchData ( ) ;
33+ } , [ ] ) ;
3934
4035 return (
4136 < >
@@ -51,35 +46,50 @@ function SettingsLibraries() {
5146 } }
5247 />
5348
54- < Box sx = { { mt : 2 , display : "flex" , flexDirection : "column" , gap : 2 } } >
55-
56- < Typography variant = "subtitle1" >
57- Enable or disable libraries to show throughout Nevu. < br />
58- Disabled libraries will not be shown in the home page, recommendations, search results, or any other place.
59- </ Typography >
49+ < Box sx = { { mt : 2 , display : "flex" , flexDirection : "column" , gap : 2 , width : "100%" } } >
50+ < CheckBoxOption
51+ title = "Disable Home Libraries Section"
52+ subtitle = "Disables the section on the home screen where the libraries are displayed."
53+ checked = { settings . DISABLE_HOME_SCREEN_LIBRARIES === "true" }
54+ onChange = { ( ) => {
55+ setSetting (
56+ "DISABLE_HOME_SCREEN_LIBRARIES" ,
57+ settings [ "DISABLE_HOME_SCREEN_LIBRARIES" ] === "true"
58+ ? "false"
59+ : "true"
60+ ) ;
61+ } }
62+ />
6063
61- { libraries . map ( ( library ) => {
62- const key = `LIBRARY_${ library . uuid } ` ;
63- const rawValue = settings [ key ] ;
64+ < Divider sx = { { my : 2 } } />
6465
65- const checked = rawValue === undefined ? true : rawValue === "true" ;
66+ { loading && (
67+ < CircularProgress
68+ sx = { { alignSelf : "center" , mt : 2 } }
69+ size = { 24 }
70+ />
71+ ) }
6672
67- return (
68- < CheckBoxOption
69- key = { library . key }
70- title = { library . title }
71- subtitle = { `Type: ${ library . type . toUpperCase ( ) } ` }
72- checked = { checked }
73- onChange = { ( ) => {
74- setSetting ( key , checked ? "false" : "true" ) ;
75- } }
76- />
77- ) ;
78- } ) }
73+ { libraries . map ( ( library ) => {
74+ const key = `LIBRARY_${ library . uuid } ` ;
75+ const rawValue = settings [ key ] ;
7976
77+ const checked = rawValue === undefined ? true : rawValue === "true" ;
8078
79+ return (
80+ < CheckBoxOption
81+ key = { library . key }
82+ title = { library . title }
83+ subtitle = { `Type: ${ library . type . toUpperCase ( ) } ` }
84+ checked = { checked }
85+ onChange = { ( ) => {
86+ setSetting ( key , checked ? "false" : "true" ) ;
87+ } }
88+ />
89+ ) ;
90+ } ) }
8191 </ Box >
8292 </ >
8393 ) ;
8494}
85- export default SettingsLibraries ;
95+ export default SettingsLibraries ;
0 commit comments