1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-26 20:28:40 +00:00

Refactor head navbar icons (#34922)

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
wxiaoguang
2025-07-04 19:03:22 +08:00
committed by GitHub
parent d6d643fe86
commit 71e151cc22
9 changed files with 83 additions and 113 deletions

View File

@@ -6,6 +6,7 @@ package common
import (
goctx "context"
"errors"
"sync"
activities_model "code.gitea.io/gitea/models/activities"
"code.gitea.io/gitea/models/db"
@@ -22,8 +23,7 @@ type StopwatchTmplInfo struct {
Seconds int64
}
func getActiveStopwatch(goCtx goctx.Context) *StopwatchTmplInfo {
ctx := context.GetWebContext(goCtx)
func getActiveStopwatch(ctx *context.Context) *StopwatchTmplInfo {
if ctx.Doer == nil {
return nil
}
@@ -48,8 +48,7 @@ func getActiveStopwatch(goCtx goctx.Context) *StopwatchTmplInfo {
}
}
func notificationUnreadCount(goCtx goctx.Context) int64 {
ctx := context.GetWebContext(goCtx)
func notificationUnreadCount(ctx *context.Context) int64 {
if ctx.Doer == nil {
return 0
}
@@ -66,10 +65,19 @@ func notificationUnreadCount(goCtx goctx.Context) int64 {
return count
}
func PageTmplFunctions(ctx *context.Context) {
if ctx.IsSigned {
// defer the function call to the last moment when the tmpl renders
ctx.Data["NotificationUnreadCount"] = notificationUnreadCount
ctx.Data["GetActiveStopwatch"] = getActiveStopwatch
}
type pageGlobalDataType struct {
IsSigned bool
IsSiteAdmin bool
GetNotificationUnreadCount func() int64
GetActiveStopwatch func() *StopwatchTmplInfo
}
func PageGlobalData(ctx *context.Context) {
var data pageGlobalDataType
data.IsSigned = ctx.Doer != nil
data.IsSiteAdmin = ctx.Doer != nil && ctx.Doer.IsAdmin
data.GetNotificationUnreadCount = sync.OnceValue(func() int64 { return notificationUnreadCount(ctx) })
data.GetActiveStopwatch = sync.OnceValue(func() *StopwatchTmplInfo { return getActiveStopwatch(ctx) })
ctx.Data["PageGlobalData"] = data
}