Skip to content

Commit 2c150e7

Browse files
committed
Add theme selector button to footer
1 parent 4378f9d commit 2c150e7

File tree

9 files changed

+50
-23
lines changed

9 files changed

+50
-23
lines changed

modules/templates/helper.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,20 @@ func NewFuncMap() template.FuncMap {
138138
}
139139
return user.Theme
140140
},
141+
"ThemeIcon": func(theme string) string {
142+
if theme == "gitea-dark" {
143+
return "octicon-moon"
144+
} else if theme == "gitea-light" {
145+
return "octicon-sun"
146+
} else if theme == "gitea-auto" {
147+
return "gitea-eclipse"
148+
} else {
149+
return "octicon-paintbrush"
150+
}
151+
},
152+
"Themes": func() []string {
153+
return setting.UI.Themes
154+
},
141155
"NotificationSettings": func() map[string]any {
142156
return map[string]any{
143157
"MinTimeout": int(setting.UI.Notification.MinTimeout / time.Millisecond),

public/assets/img/svg/gitea-eclipse.svg

Lines changed: 1 addition & 0 deletions
Loading

routers/web/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ func registerRoutes(m *web.Route) {
629629
})
630630
addWebhookEditRoutes()
631631
}, webhooksEnabled)
632-
}, reqSignIn, ctxDataSet("PageIsUserSettings", true, "AllThemes", setting.UI.Themes, "EnablePackages", setting.Packages.Enabled))
632+
}, reqSignIn, ctxDataSet("PageIsUserSettings", true, "EnablePackages", setting.Packages.Enabled))
633633

634634
m.Group("/user", func() {
635635
m.Get("/activate", auth.Activate)

templates/base/footer_content.tmpl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515
{{end}}
1616
</div>
1717
<div class="right-links" role="group" aria-label="{{ctx.Locale.Tr "aria.footer.links"}}">
18+
<div class="ui dropdown upward">
19+
{{$currentTheme := ThemeName .SignedUser}}
20+
<span class="flex-text-inline">{{svg (ThemeIcon $currentTheme) 14}} {{$currentTheme}}</span>
21+
<div class="menu theme-menu">
22+
{{range Themes}}
23+
<a data-value="{{.}}" class="item {{if eq $currentTheme .}}active selected{{end}}">
24+
{{svg (ThemeIcon .) 14}} {{.}}
25+
</a>
26+
{{end}}
27+
</div>
28+
</div>
1829
<div class="ui dropdown upward language">
1930
<span class="flex-text-inline">{{svg "octicon-globe" 14}} {{ctx.Locale.LangName}}</span>
2031
<div class="menu language-menu">

templates/user/settings/appearance.tmpl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,17 @@
1313

1414
<form class="ui form" action="{{.Link}}/theme" method="post">
1515
{{.CsrfTokenHtml}}
16+
{{$currentTheme := ThemeName .SignedUser}}
1617
<div class="field">
1718
<label for="ui">{{ctx.Locale.Tr "settings.ui"}}</label>
1819
<div class="ui selection dropdown" id="ui">
19-
<input name="theme" type="hidden" value="{{.SignedUser.Theme}}">
20+
<input name="theme" type="hidden" value="{{$currentTheme}}">
2021
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
21-
<div class="text">
22-
{{range $i,$a := .AllThemes}}
23-
{{if eq $.SignedUser.Theme $a}}{{$a}}{{end}}
24-
{{end}}
25-
</div>
26-
22+
<div class="text">{{$currentTheme}}</div>
2723
<div class="menu">
28-
{{range $i,$a := .AllThemes}}
29-
<div class="item{{if eq $.SignedUser.Theme $a}} active selected{{end}}" data-value="{{$a}}">
30-
{{$a}}
24+
{{range Themes}}
25+
<div class="item{{if eq $currentTheme .}} active selected{{end}}" data-value="{{.}}">
26+
{{.}}
3127
</div>
3228
{{end}}
3329
</div>

web_src/css/home.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@
6767
justify-content: center;
6868
}
6969

70-
.page-footer .right-links > a {
70+
.page-footer .right-links > * + * {
7171
border-left: 1px solid var(--color-secondary-dark-1);
72-
padding-left: 8px;
73-
margin-left: 5px;
72+
padding-left: 7px;
73+
margin-left: 7px;
7474
}
7575

7676
.page-footer .ui.dropdown.language .menu {

web_src/js/features/common-global.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {showTemporaryTooltip} from '../modules/tippy.js';
1212
import {confirmModal} from './comp/ConfirmModal.js';
1313
import {showErrorToast} from '../modules/toast.js';
1414
import {request} from '../modules/fetch.js';
15+
import {POST} from '../modules/fetch.js';
1516

1617
const {appUrl, appSubUrl, csrfToken, i18n} = window.config;
1718

@@ -35,15 +36,18 @@ export function initHeadNavbarContentToggle() {
3536
});
3637
}
3738

38-
export function initFootLanguageMenu() {
39-
function linkLanguageAction() {
40-
const $this = $(this);
41-
$.get($this.data('url')).always(() => {
39+
export function initFooterMenus() {
40+
$('.language-menu a[lang]').on('click', function() {
41+
$.get($(this).data('url')).always(() => {
4242
window.location.reload();
4343
});
44-
}
45-
46-
$('.language-menu a[lang]').on('click', linkLanguageAction);
44+
});
45+
$('.theme-menu .item').on('click', async (e) => {
46+
const res = await POST(`${appSubUrl}/user/settings/appearance/theme`, {
47+
data: new URLSearchParams({theme: e.target.getAttribute('data-value')}),
48+
});
49+
if (res.ok) window.location.reload();
50+
});
4751
}
4852

4953

web_src/js/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
initCommitStatuses,
4040
} from './features/repo-commit.js';
4141
import {
42-
initFootLanguageMenu,
42+
initFooterMenus,
4343
initGlobalButtonClickOnEnter,
4444
initGlobalButtons,
4545
initGlobalCommon,
@@ -111,7 +111,7 @@ onDomReady(() => {
111111
initInstall();
112112

113113
initHeadNavbarContentToggle();
114-
initFootLanguageMenu();
114+
initFooterMenus();
115115

116116
initCommentContent();
117117
initContextPopups();

web_src/svg/gitea-eclipse.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)