@@ -27,31 +27,31 @@ import { NotificationsProvider } from "../components/Notifications";
2727import Text from "../components/Text" ;
2828import LoadingContext from "../utils/LoadingContext" ;
2929
30- const getThemeColours = ( theme , primary = "#f45d48" ) => {
31- switch ( theme ) {
30+ const getThemeColours = ( themeName , customTheme = { } ) => {
31+ switch ( themeName ) {
3232 case "light" :
3333 return {
34- primary,
35- background : "#ffffff" ,
36- sidebar : "#f8f8f8" ,
37- text : "#202224" ,
38- grey : "#747474" ,
34+ primary : customTheme . primary ?? "#f45d48" ,
35+ background : customTheme . background ?? "#ffffff" ,
36+ sidebar : customTheme . sidebar ?? "#f8f8f8" ,
37+ border : customTheme . border ?? "#deebf1" ,
38+ text : customTheme . text ?? "#202224" ,
39+ grey : customTheme . grey ?? "#747474" ,
3940 error : "#f33" ,
4041 success : "#44d944" ,
4142 info : "#427ee1" ,
42- border : "#deebf1" ,
4343 } ;
4444 case "dark" :
4545 return {
46- primary,
47- background : "#1f2023" ,
48- sidebar : "#27282b" ,
49- text : "#f8f8f8" ,
50- grey : "#aaa" ,
46+ primary : customTheme . primary ?? "#f45d48" ,
47+ background : customTheme . background ?? "#1f2023" ,
48+ sidebar : customTheme . sidebar ?? "#27282b" ,
49+ border : customTheme . border ?? "#303236" ,
50+ text : customTheme . text ?? "#f8f8f8" ,
51+ grey : customTheme . grey ?? "#aaa" ,
5152 error : "#f33" ,
5253 success : "#44d944" ,
5354 info : "#427ee1" ,
54- border : "#303236" ,
5555 } ;
5656 }
5757} ;
@@ -169,13 +169,17 @@ const SqTracker = ({ Component, pageProps, initialTheme }) => {
169169
170170 const {
171171 publicRuntimeConfig : {
172- SQ_THEME_COLOUR ,
172+ SQ_CUSTOM_THEME ,
173173 SQ_SITE_WIDE_FREELEECH ,
174174 SQ_API_URL ,
175175 SQ_MINIMUM_RATIO ,
176176 } ,
177177 } = getConfig ( ) ;
178178
179+ const allowThemeToggle = ! Object . keys ( SQ_CUSTOM_THEME ?? { } ) . some (
180+ ( key ) => key !== "primary"
181+ ) ;
182+
179183 const setThemeAndSave = ( theme ) => {
180184 setTheme ( theme ) ;
181185 setCookie ( "theme" , theme , {
@@ -193,12 +197,14 @@ const SqTracker = ({ Component, pageProps, initialTheme }) => {
193197 setIsMobile ( matches ) ;
194198 } ) ;
195199
196- const { theme : themeCookie } = cookies ;
197- const themeQuery = window . matchMedia ( "(prefers-color-scheme: light)" ) ;
198- if ( ! themeCookie ) setThemeAndSave ( themeQuery . matches ? "light" : "dark" ) ;
199- themeQuery . addEventListener ( "change" , ( { matches } ) => {
200- setThemeAndSave ( matches ? "light" : "dark" ) ;
201- } ) ;
200+ if ( allowThemeToggle ) {
201+ const { theme : themeCookie } = cookies ;
202+ const themeQuery = window . matchMedia ( "(prefers-color-scheme: light)" ) ;
203+ if ( ! themeCookie ) setThemeAndSave ( themeQuery . matches ? "light" : "dark" ) ;
204+ themeQuery . addEventListener ( "change" , ( { matches } ) => {
205+ setThemeAndSave ( matches ? "light" : "dark" ) ;
206+ } ) ;
207+ }
202208
203209 Router . events . on ( "routeChangeStart" , ( ) => setLoading ( true ) ) ;
204210 Router . events . on ( "routeChangeComplete" , ( ) => setLoading ( false ) ) ;
@@ -226,7 +232,7 @@ const SqTracker = ({ Component, pageProps, initialTheme }) => {
226232
227233 const appTheme = {
228234 ...baseTheme ,
229- colors : getThemeColours ( theme , SQ_THEME_COLOUR ) ,
235+ colors : getThemeColours ( theme , SQ_CUSTOM_THEME ) ,
230236 name : theme ,
231237 } ;
232238
@@ -353,22 +359,24 @@ const SqTracker = ({ Component, pageProps, initialTheme }) => {
353359 ref = { searchRef }
354360 />
355361 </ Box >
356- < Button
357- variant = "secondary"
358- onClick = { ( ) => {
359- setThemeAndSave ( theme === "light" ? "dark" : "light" ) ;
360- } }
361- width = "40px"
362- px = { 2 }
363- py = { 2 }
364- ml = { 3 }
365- >
366- { theme === "light" ? (
367- < Sun size = { 24 } />
368- ) : (
369- < Moon size = { 24 } />
370- ) }
371- </ Button >
362+ { allowThemeToggle && (
363+ < Button
364+ variant = "secondary"
365+ onClick = { ( ) => {
366+ setThemeAndSave ( theme === "light" ? "dark" : "light" ) ;
367+ } }
368+ width = "40px"
369+ px = { 2 }
370+ py = { 2 }
371+ ml = { 3 }
372+ >
373+ { theme === "light" ? (
374+ < Sun size = { 24 } />
375+ ) : (
376+ < Moon size = { 24 } />
377+ ) }
378+ </ Button >
379+ ) }
372380 </ Box >
373381 ) }
374382 </ Box >
0 commit comments