@@ -39,6 +39,7 @@ import SigninPage from "./SigninPage";
3939import i18next from "i18next" ;
4040import { withTranslation } from "react-i18next" ;
4141import LanguageSelect from "./LanguageSelect" ;
42+ import ThemeSelect from "./ThemeSelect" ;
4243import ChatEditPage from "./ChatEditPage" ;
4344import ChatListPage from "./ChatListPage" ;
4445import MessageListPage from "./MessageListPage" ;
@@ -86,12 +87,21 @@ const {Header, Footer, Content} = Layout;
8687class App extends Component {
8788 constructor ( props ) {
8889 super ( props ) ;
90+ this . setThemeAlgorithm ( ) ;
91+ let storageThemeAlgorithm = [ ] ;
92+ try {
93+ storageThemeAlgorithm = localStorage . getItem ( "themeAlgorithm" ) ? JSON . parse ( localStorage . getItem ( "themeAlgorithm" ) ) : [ "default" ] ;
94+ } catch {
95+ storageThemeAlgorithm = [ "default" ] ;
96+ }
8997 this . state = {
9098 classes : props ,
9199 selectedMenuKey : 0 ,
92100 account : undefined ,
93101 uri : null ,
102+ themeAlgorithm : storageThemeAlgorithm ,
94103 themeData : Conf . ThemeDefault ,
104+ logo : this . getLogo ( storageThemeAlgorithm ) ,
95105 menuVisible : false ,
96106 forms : [ ] ,
97107 } ;
@@ -304,6 +314,27 @@ class App extends Component {
304314 } ) ;
305315 } ;
306316
317+ setThemeAlgorithm ( ) {
318+ const currentUrl = window . location . href ;
319+ const url = new URL ( currentUrl ) ;
320+ const themeType = url . searchParams . get ( "theme" ) ;
321+ if ( themeType === "dark" || themeType === "default" ) {
322+ localStorage . setItem ( "themeAlgorithm" , JSON . stringify ( [ themeType ] ) ) ;
323+ }
324+ }
325+
326+ setLogoAndThemeAlgorithm = ( nextThemeAlgorithm ) => {
327+ this . setState ( {
328+ themeAlgorithm : nextThemeAlgorithm ,
329+ logo : this . getLogo ( nextThemeAlgorithm ) ,
330+ } ) ;
331+ localStorage . setItem ( "themeAlgorithm" , JSON . stringify ( nextThemeAlgorithm ) ) ;
332+ } ;
333+
334+ getLogo ( themes ) {
335+ return Setting . getLogo ( themes ) ;
336+ }
337+
307338 renderAvatar ( ) {
308339 if ( this . state . account . avatar === "" ) {
309340 return (
@@ -399,6 +430,9 @@ class App extends Component {
399430 { i18next . t ( "account:Sign In" ) }
400431 </ a >
401432 </ div >
433+ < div style = { { float : "right" , margin : "0px" , padding : "0px" } } >
434+ < ThemeSelect themeAlgorithm = { this . state . themeAlgorithm } onChange = { this . setLogoAndThemeAlgorithm } />
435+ </ div >
402436 < div style = { { float : "right" , margin : "0px" , padding : "0px" } } >
403437 < LanguageSelect />
404438 </ div >
@@ -408,6 +442,7 @@ class App extends Component {
408442 return (
409443 < React . Fragment >
410444 { this . renderRightDropdown ( ) }
445+ < ThemeSelect themeAlgorithm = { this . state . themeAlgorithm } onChange = { this . setLogoAndThemeAlgorithm } />
411446 < LanguageSelect />
412447 < div style = { { float : "right" , marginRight : "20px" , padding : "0px" } } >
413448 < div dangerouslySetInnerHTML = { { __html : Conf . NavbarHtml } } />
@@ -515,7 +550,7 @@ class App extends Component {
515550 Setting . goToLinkSoft ( this , "/videos" ) ;
516551 }
517552 } else {
518- const textColor = "black" ;
553+ const textColor = this . state . themeAlgorithm . includes ( "dark" ) ? "white" : "black" ;
519554 const twoToneColor = this . state . themeData . colorPrimary ;
520555
521556 res . pop ( ) ;
@@ -762,11 +797,11 @@ class App extends Component {
762797 } ;
763798
764799 return (
765- < Header style = { { padding : "0" , marginBottom : "3px" , backgroundColor : "white" , display : "flex" , justifyContent : "space-between" } } >
800+ < Header style = { { padding : "0" , marginBottom : "3px" , backgroundColor : this . state . themeAlgorithm . includes ( "dark" ) ? "black" : "white" , display : "flex" , justifyContent : "space-between" } } >
766801 < div style = { { display : "flex" , alignItems : "center" , flex : 1 , overflow : "hidden" } } >
767802 { Setting . isMobile ( ) ? null : (
768803 < Link to = { "/" } >
769- < img className = "logo" src = { Conf . LogoUrl } alt = "logo" />
804+ < img className = "logo" src = { this . state . logo } alt = "logo" />
770805 </ Link >
771806 ) }
772807 { Setting . isMobile ( ) ? (
@@ -809,8 +844,6 @@ class App extends Component {
809844 < React . Fragment >
810845 < Footer id = "footer" style = {
811846 {
812- borderTop : "1px solid #e8e8e8" ,
813- backgroundColor : "white" ,
814847 textAlign : "center" ,
815848 height : "67px" ,
816849 }
@@ -849,7 +882,7 @@ class App extends Component {
849882 colorInfo : this . state . themeData . colorPrimary ,
850883 borderRadius : this . state . themeData . borderRadius ,
851884 } ,
852- // algorithm: Setting.getAlgorithm(this.state.themeAlgorithm),
885+ algorithm : Setting . getAlgorithm ( this . state . themeAlgorithm ) ,
853886 } } >
854887 < StyleProvider hashPriority = "high" transformers = { [ legacyLogicalPropertiesTransformer ] } >
855888 {
0 commit comments