Skip to content

Commit f483e87

Browse files
author
Working On It
committed
feat: support Theme button(casibase#1356)
1 parent 00b7311 commit f483e87

File tree

14 files changed

+177
-37
lines changed

14 files changed

+177
-37
lines changed

conf/app.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ staticBaseUrl = "https://cdn.casibase.org"
3737
htmlTitle = "Casibase"
3838
faviconUrl = "https://cdn.casibase.com/static/favicon.png"
3939
logoUrl = "https://cdn.casibase.org/img/casibase-logo_1200x256.png"
40+
logoWhiteUrl = "https://cdn.casibase.org/img/casibase-logo_1200x256_white.png"
4041
navbarHtml = ""
4142
footerHtml = "Powered by <a target="_blank" href="https://github.com/casibase/casibase" rel="noreferrer"><img style="padding-bottom: 3px;" height="20" alt="Casibase" src="https://cdn.casibase.org/img/casibase-logo_1200x256.png" /></a>"
4243
appUrl = ""

conf/conf.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type WebConfig struct {
4242
HtmlTitle string `json:"htmlTitle"`
4343
FaviconUrl string `json:"faviconUrl"`
4444
LogoUrl string `json:"logoUrl"`
45+
LogoWhiteUrl string `json:"logoWhiteUrl"`
4546
NavbarHtml string `json:"navbarHtml"`
4647
FooterHtml string `json:"footerHtml"`
4748
AppUrl string `json:"appUrl"`
@@ -219,6 +220,7 @@ func GetWebConfig() *WebConfig {
219220
config.HtmlTitle = GetConfigString("htmlTitle")
220221
config.FaviconUrl = GetConfigString("faviconUrl")
221222
config.LogoUrl = GetConfigString("logoUrl")
223+
config.LogoWhiteUrl = GetConfigString("logoWhiteUrl")
222224
config.NavbarHtml = GetConfigString("navbarHtml")
223225
config.FooterHtml = GetConfigString("footerHtml")
224226
config.AppUrl = GetConfigString("appUrl")

web/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6-
"@ant-design/cssinjs": "^1.12.0",
7-
"@ant-design/icons": "4.6.2",
6+
"@ant-design/cssinjs": "^1.23.0",
7+
"@ant-design/icons": "^5.6.1",
88
"@ant-design/x": "^1.0.5",
99
"@bpmn-io/cm-theme": "0.1.0-alpha.2",
1010
"@bpmn-io/properties-panel": "^3.26.4",
@@ -13,6 +13,7 @@
1313
"@dnd-kit/core": "^6.3.1",
1414
"aliplayer-react": "^0.7.0",
1515
"antd": "5.24.0",
16+
"antd-token-previewer": "^2.0.8",
1617
"bpmn-font": "^0.12.1",
1718
"bpmn-js": "^18.4.0",
1819
"bpmn-js-properties-panel": "^5.35.0",

web/src/App.js

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import SigninPage from "./SigninPage";
3939
import i18next from "i18next";
4040
import {withTranslation} from "react-i18next";
4141
import LanguageSelect from "./LanguageSelect";
42+
import ThemeSelect from "./ThemeSelect";
4243
import ChatEditPage from "./ChatEditPage";
4344
import ChatListPage from "./ChatListPage";
4445
import MessageListPage from "./MessageListPage";
@@ -86,12 +87,21 @@ const {Header, Footer, Content} = Layout;
8687
class 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();
@@ -713,7 +748,7 @@ class App extends Component {
713748
renderContent() {
714749
if (Setting.getUrlParam("isRaw") !== null) {
715750
return (
716-
<HomePage account={this.state.account} />
751+
<HomePage account={this.state.account} themeAlgorithm={this.state.themeAlgorithm} />
717752
);
718753
} else if (Setting.getSubdomain() === "portal") {
719754
return (
@@ -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.themeAlgorithm.includes("dark") ? Conf.LogoWhiteUrl : Conf.LogoUrl} 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
{

web/src/App.less

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ img {
3333
flex-direction: column;
3434
height: 100%;
3535
min-height: 100vh;
36-
background-color: white;
3736
}
3837

3938
.content-warp-card {
@@ -66,10 +65,6 @@ img {
6665
height: 65px;
6766
float: right;
6867
cursor: pointer;
69-
70-
&:hover {
71-
background-color: #f5f5f5;
72-
}
7368
}
7469

7570
.select-box {
@@ -81,10 +76,6 @@ img {
8176
height: 64px;
8277
float: right;
8378
cursor: pointer;
84-
85-
&:hover {
86-
background-color: #f5f5f5 !important;
87-
}
8879
}
8980

9081
.rightDropDown {
@@ -95,11 +86,6 @@ img {
9586
float: right;
9687
cursor: pointer;
9788
margin-right: 3px;
98-
99-
&:hover {
100-
background-color: #f5f5f5;
101-
color: black;
102-
}
10389
}
10490

10591
.cs-conversation-header__content .cs-conversation-header__user-name {

web/src/ArticleEditPage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ class ArticleEditPage extends React.Component {
407407
{/* </Col>*/}
408408
<Col span={5} >
409409
<Affix offsetTop={0} style={{marginRight: "10px"}}>
410-
<div style={{backgroundColor: "white", height: "100vh", overflowY: "auto", borderRight: 0}}>
410+
<div style={{height: "100vh", overflowY: "auto", borderRight: 0}}>
411411
<ArticleMenu table={blocks} onGoToRow={(table, i) => {
412412
if (this.articleTableRef.current) {
413413
this.articleTableRef.current.goToRow(table, i);

web/src/ChatPage.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ class ChatPage extends BaseListPage {
702702
}
703703

704704
return (
705-
<div style={{display: "flex", backgroundColor: "white", height: (Setting.getUrlParam("isRaw") !== null) ? "calc(100vh)" : (window.location.pathname.startsWith("/chat")) ? "calc(100vh - 135px)" : Setting.isMobile() ? "calc(100vh - 136px)" : "calc(100vh - 186px)"}}>
705+
<div style={{display: "flex", height: (Setting.getUrlParam("isRaw") !== null) ? "calc(100vh)" : (window.location.pathname.startsWith("/chat")) ? "calc(100vh - 135px)" : Setting.isMobile() ? "calc(100vh - 136px)" : "calc(100vh - 186px)"}}>
706706
{
707707
this.renderModal()
708708
}
@@ -711,7 +711,7 @@ class ChatPage extends BaseListPage {
711711
}
712712
{
713713
!(Setting.isMobile() || Setting.getUrlParam("isRaw") !== null) && !this.state.chatMenuCollapsed && (
714-
<div style={{width: "250px", height: "100%", backgroundColor: "white", marginRight: "2px"}}>
714+
<div style={{width: "250px", height: "100%", marginRight: "2px"}}>
715715
<ChatMenu ref={this.menu} chats={chats} chatName={this.getChat()} onSelectChat={onSelectChat} onAddChat={onAddChat} onDeleteChat={onDeleteChat} onUpdateChatName={onUpdateChatName} stores={this.state.stores} currentStoreName={currentStoreName} />
716716
</div>
717717
)
@@ -724,7 +724,7 @@ class ChatPage extends BaseListPage {
724724
</Drawer>
725725
)}
726726

727-
<div style={{flex: 1, height: "100%", backgroundColor: "white", position: "relative", display: "flex", flexDirection: "column"}}>
727+
<div style={{flex: 1, height: "100%", position: "relative", display: "flex", flexDirection: "column"}}>
728728
{this.state.chat && this.state.paneCount === 1 && (
729729
<div style={{display: "flex", alignItems: "center", marginLeft: "15px"}}>
730730
{Setting.isMobile() && (

web/src/Conf.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export let StaticBaseUrl = "";
2424
export let HtmlTitle = "";
2525
export let FaviconUrl = "";
2626
export let LogoUrl = "";
27+
export let LogoWhiteUrl = "";
2728
export let NavbarHtml = "";
2829
export let FooterHtml = "";
2930
export let AppUrl = "";
@@ -53,6 +54,7 @@ export function setConfig(config) {
5354
if (config.htmlTitle !== undefined) {HtmlTitle = config.htmlTitle;}
5455
if (config.faviconUrl !== undefined) {FaviconUrl = config.faviconUrl;}
5556
if (config.logoUrl !== undefined) {LogoUrl = config.logoUrl;}
57+
if (config.logoWhiteUrl !== undefined) {LogoWhiteUrl = config.logoWhiteUrl;}
5658
if (config.navbarHtml !== undefined) {NavbarHtml = config.navbarHtml;}
5759
if (config.footerHtml !== undefined) {FooterHtml = config.footerHtml;}
5860
if (config.appUrl !== undefined) {AppUrl = config.appUrl;}

web/src/MultiPaneManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ const MultiPaneManager = ({
425425
);
426426

427427
return (
428-
<div style={{flex: 1, height: "100%", backgroundColor: "white", position: "relative", display: "flex", flexDirection: "column"}}>
428+
<div style={{flex: 1, height: "100%", position: "relative", display: "flex", flexDirection: "column"}}>
429429
<div style={{flex: 1, display: "grid", gridTemplateColumns: `repeat(${paneCount}, 1fr)`, gap: "2px", overflow: "hidden"}}>
430430
{Array.from({length: paneCount}, (_, index) => {
431431
const pane = panes[index] || {};

web/src/Setting.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import {Tag, Tooltip, message} from "antd";
15+
import {Tag, Tooltip, message, theme} from "antd";
1616
import {QuestionCircleTwoTone, SyncOutlined} from "@ant-design/icons";
1717
import {isMobile as isMobileDevice} from "react-device-detect";
1818
import i18next from "i18next";
@@ -2036,3 +2036,23 @@ export function getThinkingModelMaxTokens(subType) {
20362036
}
20372037
return 0;
20382038
}
2039+
2040+
export function getAlgorithm(themeAlgorithmNames) {
2041+
return themeAlgorithmNames.sort().reverse().map((algorithmName) => {
2042+
if (algorithmName === "dark") {
2043+
return theme.darkAlgorithm;
2044+
}
2045+
if (algorithmName === "compact") {
2046+
return theme.compactAlgorithm;
2047+
}
2048+
return theme.defaultAlgorithm;
2049+
});
2050+
}
2051+
2052+
export function getLogo(themes) {
2053+
if (themes.includes("dark")) {
2054+
return `${StaticBaseUrl}/img/casdoor-logo_1185x256_dark.png`;
2055+
} else {
2056+
return `${StaticBaseUrl}/img/casdoor-logo_1185x256.png`;
2057+
}
2058+
}

0 commit comments

Comments
 (0)