Skip to content

Commit 5ee4755

Browse files
committed
clean up
1 parent b1dde04 commit 5ee4755

File tree

8 files changed

+21
-22
lines changed

8 files changed

+21
-22
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: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -651,18 +651,17 @@ func PrepareBranchList(ctx *context.Context) {
651651
ctx.Data["Branches"] = brs
652652
}
653653

654-
type preferencesForm struct {
655-
ShowFileViewTreeSidebar bool `json:"show_file_view_tree_sidebar"`
656-
}
657-
658654
func UpdatePreferences(ctx *context.Context) {
655+
type preferencesForm struct {
656+
CodeViewShowFileTree bool `json:"codeViewShowFileTree"`
657+
}
659658
form := &preferencesForm{}
660659
if err := json.NewDecoder(ctx.Req.Body).Decode(&form); err != nil {
661660
ctx.ServerError("DecodePreferencesForm", err)
662661
return
663662
}
664-
if err := user_model.SetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyShowFileViewTreeSidebar,
665-
strconv.FormatBool(form.ShowFileViewTreeSidebar)); err != nil {
663+
if err := user_model.SetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyCodeViewShowFileTree,
664+
strconv.FormatBool(form.CodeViewShowFileTree)); err != nil {
666665
log.Error("SetUserSetting: %v", err)
667666
}
668667

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

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", repo.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)