Skip to content

Commit 14f914c

Browse files
committed
clean up
1 parent b1dde04 commit 14f914c

File tree

9 files changed

+42
-36
lines changed

9 files changed

+42
-36
lines changed

models/user/setting_keys.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ const (
1010
SettingsKeyDiffWhitespaceBehavior = "diff.whitespace_behaviour"
1111
// SettingsKeyShowOutdatedComments is the setting key wether or not to show outdated comments in PRs
1212
SettingsKeyShowOutdatedComments = "comment_code.show_outdated"
13+
1314
// UserActivityPubPrivPem is user's private key
1415
UserActivityPubPrivPem = "activitypub.priv_pem"
1516
// UserActivityPubPubPem is user's public key
1617
UserActivityPubPubPem = "activitypub.pub_pem"
1718
// SignupIP is the IP address that the user signed up with
1819
SignupIP = "signup.ip"
1920
// SignupUserAgent is the user agent that the user signed up with
20-
SignupUserAgent = "signup.user_agent"
21-
SettingsKeyShowFileViewTreeSidebar = "tree.show_file_view_tree_sidebar"
21+
SignupUserAgent = "signup.user_agent"
22+
23+
SettingsKeyCodeViewShowFileTree = "code_view.show_file_tree"
2224
)

modules/git/parse_nogogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func ParseTreeEntries(data []byte) ([]*TreeEntry, error) {
1919
return parseTreeEntries(data, nil)
2020
}
2121

22-
// parseTreeEntries FIXME this function's design is not right, it should make the caller read all data into memory
22+
// parseTreeEntries FIXME this function's design is not right, it should not make the caller read all data into memory
2323
func parseTreeEntries(data []byte, ptree *Tree) ([]*TreeEntry, error) {
2424
entries := make([]*TreeEntry, 0, bytes.Count(data, []byte{'\n'})+1)
2525
for pos := 0; pos < len(data); {

routers/web/repo/repo.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010
"net/http"
1111
"slices"
12-
"strconv"
1312
"strings"
1413

1514
"code.gitea.io/gitea/models/db"
@@ -21,7 +20,6 @@ import (
2120
user_model "code.gitea.io/gitea/models/user"
2221
"code.gitea.io/gitea/modules/cache"
2322
"code.gitea.io/gitea/modules/git"
24-
"code.gitea.io/gitea/modules/json"
2523
"code.gitea.io/gitea/modules/log"
2624
"code.gitea.io/gitea/modules/optional"
2725
repo_module "code.gitea.io/gitea/modules/repository"
@@ -650,21 +648,3 @@ func PrepareBranchList(ctx *context.Context) {
650648
}
651649
ctx.Data["Branches"] = brs
652650
}
653-
654-
type preferencesForm struct {
655-
ShowFileViewTreeSidebar bool `json:"show_file_view_tree_sidebar"`
656-
}
657-
658-
func UpdatePreferences(ctx *context.Context) {
659-
form := &preferencesForm{}
660-
if err := json.NewDecoder(ctx.Req.Body).Decode(&form); err != nil {
661-
ctx.ServerError("DecodePreferencesForm", err)
662-
return
663-
}
664-
if err := user_model.SetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyShowFileViewTreeSidebar,
665-
strconv.FormatBool(form.ShowFileViewTreeSidebar)); err != nil {
666-
log.Error("SetUserSetting: %v", err)
667-
}
668-
669-
ctx.JSONOK()
670-
}

routers/web/repo/view_home.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,18 +331,16 @@ func handleRepoHomeFeed(ctx *context.Context) bool {
331331
}
332332

333333
func prepareHomeTreeSideBarSwitch(ctx *context.Context) {
334-
showFileViewTreeSidebar := true
334+
showFileTree := true
335335
if ctx.Doer != nil {
336-
v, err := user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyShowFileViewTreeSidebar, "true")
336+
v, err := user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyCodeViewShowFileTree, "true")
337337
if err != nil {
338338
log.Error("GetUserSetting: %v", err)
339339
} else {
340-
showFileViewTreeSidebar, _ = strconv.ParseBool(v)
340+
showFileTree, _ = strconv.ParseBool(v)
341341
}
342342
}
343-
ctx.Data["RepoPreferences"] = &preferencesForm{
344-
ShowFileViewTreeSidebar: showFileViewTreeSidebar,
345-
}
343+
ctx.Data["UserSettingCodeViewShowFileTree"] = showFileTree
346344
}
347345

348346
// Home render repository home page
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package setting
5+
6+
import (
7+
"net/http"
8+
"strconv"
9+
10+
user_model "code.gitea.io/gitea/models/user"
11+
"code.gitea.io/gitea/modules/json"
12+
"code.gitea.io/gitea/services/context"
13+
)
14+
15+
func UpdatePreferences(ctx *context.Context) {
16+
type preferencesForm struct {
17+
CodeViewShowFileTree bool `json:"codeViewShowFileTree"`
18+
}
19+
form := &preferencesForm{}
20+
if err := json.NewDecoder(ctx.Req.Body).Decode(&form); err != nil {
21+
ctx.HTTPError(http.StatusBadRequest, "json decode failed")
22+
return
23+
}
24+
_ = user_model.SetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyCodeViewShowFileTree, strconv.FormatBool(form.CodeViewShowFileTree))
25+
ctx.JSONOK()
26+
}

routers/web/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ func registerRoutes(m *web.Router) {
580580
m.Group("/user/settings", func() {
581581
m.Get("", user_setting.Profile)
582582
m.Post("", web.Bind(forms.UpdateProfileForm{}), user_setting.ProfilePost)
583+
m.Post("/update_preferences", user_setting.UpdatePreferences)
583584
m.Get("/change_password", auth.MustChangePassword)
584585
m.Post("/change_password", web.Bind(forms.MustChangePasswordForm{}), auth.MustChangePasswordPost)
585586
m.Post("/avatar", web.Bind(forms.AvatarForm{}), user_setting.AvatarPost)
@@ -1001,7 +1002,6 @@ func registerRoutes(m *web.Router) {
10011002
m.Get("/migrate", repo.Migrate)
10021003
m.Post("/migrate", web.Bind(forms.MigrateRepoForm{}), repo.MigratePost)
10031004
m.Get("/search", repo.SearchRepo)
1004-
m.Put("/preferences", repo.UpdatePreferences)
10051005
}, reqSignIn)
10061006
// end "/repo": create, migrate, search
10071007

templates/repo/view.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
{{template "repo/code/recently_pushed_new_branches" .}}
1818

19-
<div class="repo-view-container {{Iif .RepoPreferences.ShowFileViewTreeSidebar "repo-view-with-sidebar" "repo-view-content-only"}}">
20-
<div class="repo-view-file-tree-sidebar not-mobile {{if not .RepoPreferences.ShowFileViewTreeSidebar}}tw-hidden{{end}}" {{if .IsSigned}} data-is-signed {{end}}>{{template "repo/view_file_tree_sidebar" .}}</div>
19+
<div class="repo-view-container {{Iif .UserSettingCodeViewShowFileTree "repo-view-with-sidebar" "repo-view-content-only"}}">
20+
<div class="repo-view-file-tree-sidebar not-mobile {{if not .UserSettingCodeViewShowFileTree}}tw-hidden{{end}}" {{if .IsSigned}} data-is-signed {{end}}>{{template "repo/view_file_tree_sidebar" .}}</div>
2121
<div class="repo-view-content">
2222
{{template "repo/view_content" .}}
2323
</div>

templates/repo/view_content.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class="repo-button-row">
55
<div class="repo-button-row-left">
66
{{if not $isTreePathRoot}}
7-
<button class="show-tree-sidebar-button ui compact basic button icon not-mobile {{if .RepoPreferences.ShowFileViewTreeSidebar}}tw-hidden{{end}}" title="{{ctx.Locale.Tr "repo.diff.show_file_tree"}}">
7+
<button class="show-tree-sidebar-button ui compact basic button icon not-mobile {{if .UserSettingCodeViewShowFileTree}}tw-hidden{{end}}" title="{{ctx.Locale.Tr "repo.diff.show_file_tree"}}">
88
{{svg "octicon-sidebar-collapse"}}
99
</button>
1010
{{end}}

web_src/js/features/repo-view-file-tree-sidebar.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {createApp, ref} from 'vue';
22
import {toggleElem} from '../utils/dom.ts';
33
import {pathEscapeSegments, pathUnescapeSegments} from '../utils/url.ts';
4-
import {GET, PUT} from '../modules/fetch.ts';
4+
import {GET, POST} from '../modules/fetch.ts';
55
import ViewFileTree from '../components/ViewFileTree.vue';
66

77
const {appSubUrl} = window.config;
@@ -19,9 +19,9 @@ async function toggleSidebar(sidebarEl: HTMLElement, shouldShow: boolean) {
1919
if (!sidebarEl.hasAttribute('data-is-signed')) return;
2020

2121
// save to session
22-
await PUT(`${appSubUrl}/repo/preferences`, {
22+
await POST(`${appSubUrl}/user/settings/update_preferences`, {
2323
data: {
24-
show_file_view_tree_sidebar: shouldShow,
24+
codeViewShowFileTree: shouldShow,
2525
},
2626
});
2727
}

0 commit comments

Comments
 (0)