Skip to content

Commit 0af1d75

Browse files
committed
improve
1 parent 8a865de commit 0af1d75

File tree

4 files changed

+55
-53
lines changed

4 files changed

+55
-53
lines changed

templates/repo/home.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
{{template "repo/home_search_code" .}}
2626
</div>
2727
<div class="flex-list only-mobile">
28-
{{template "repo/home_share_sidebar" .}}
28+
{{template "repo/home_share_sidebar" (dict "ctxData" . "viewType" "mobile")}}
2929
</div>
3030
{{end}}
3131
{{template "repo/sub_menu" .}}
@@ -152,7 +152,7 @@
152152

153153
<div class="flex-list">
154154
<div class="not-mobile">
155-
{{template "repo/home_share_sidebar" .}}
155+
{{template "repo/home_share_sidebar" (dict "ctxData" . "viewType" "desktop")}}
156156
</div>
157157

158158
{{if .LatestRelease}}

templates/repo/home_share_sidebar.tmpl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,51 @@
33
<div class="flex-item-title">
44
{{ctx.Locale.Tr "repo.repo_desc"}}
55
</div>
6-
{{if and (not .HideRepoInfo) (not .IsBlame)}}
6+
{{if and (not .ctxData.HideRepoInfo) (not .ctxData.IsBlame)}}
77
<div class="flex-item-body repo-description tw-break-anywhere tw-gap-2 tw-mt-2">
8-
{{- $description := .Repository.DescriptionHTML ctx -}}
8+
{{- $description := .ctxData.Repository.DescriptionHTML ctx -}}
99
{{if $description}}{{$description | RenderCodeBlock}}{{else}}{{ctx.Locale.Tr "repo.repo_no_desc"}}{{end}}
10-
{{if .Repository.Website}}{{svg "octicon-link"}}<a href="{{.Repository.Website}}">{{.Repository.Website}}</a>{{end}}
10+
{{if .ctxData.Repository.Website}}{{svg "octicon-link"}}<a href="{{.ctxData.Repository.Website}}">{{.ctxData.Repository.Website}}</a>{{end}}
1111
</div>
12-
<div class="tw-flex tw-items-center tw-flex-wrap tw-gap-2 tw-my-2" id="repo-topics">
12+
<div class="tw-flex tw-items-center tw-flex-wrap tw-gap-2 tw-my-2" id="repo-topics-{{.viewType}}">
1313
{{/* it should match the code in issue-home.js */}}
14-
{{range .Topics}}<a class="repo-topic ui large label gt-ellipsis" title={{.Name}} href="{{AppSubUrl}}/explore/repos?q={{.Name}}&topic=1">{{.Name}}</a>{{end}}
14+
{{range .ctxData.Topics}}<a class="repo-topic ui large label gt-ellipsis" title={{.Name}} href="{{AppSubUrl}}/explore/repos?q={{.Name}}&topic=1">{{.Name}}</a>{{end}}
1515
</div>
16-
{{if and .Permission.IsAdmin (not .Repository.IsArchived)}}<button id="manage_topic" class="btn interact-fg tw-text-12">{{ctx.Locale.Tr "repo.topic.manage_topics"}}</button>{{end}}
16+
{{if and .ctxData.Permission.IsAdmin (not .ctxData.Repository.IsArchived)}}<button id="manage_topic_{{.viewType}}" class="btn interact-fg tw-text-12">{{ctx.Locale.Tr "repo.topic.manage_topics"}}</button>{{end}}
1717
{{end}}
18-
{{if and .Permission.IsAdmin (not .Repository.IsArchived)}}
19-
<div class="ui form tw-hidden flex-item-body tw-gap-2 tw-my-2" id="topic_edit">
18+
{{if and .ctxData.Permission.IsAdmin (not .ctxData.Repository.IsArchived)}}
19+
<div class="ui form tw-hidden flex-item-body tw-gap-2 tw-my-2" id="topic_edit_{{.viewType}}">
2020
<div class="ui fluid multiple search selection dropdown tw-flex-wrap tw-flex-1">
21-
<input type="hidden" name="topics" value="{{range $i, $v := .Topics}}{{.Name}}{{if Eval $i "+" 1 "<" (len $.Topics)}},{{end}}{{end}}">
22-
{{range .Topics}}
21+
<input type="hidden" name="topics" value="{{range $i, $v := .ctxData.Topics}}{{.Name}}{{if Eval $i "+" 1 "<" (len $.ctxData.Topics)}},{{end}}{{end}}">
22+
{{range .ctxData.Topics}}
2323
{{/* keep the same layout as Fomantic UI generated labels */}}
2424
<a class="ui label transition visible tw-cursor-default tw-inline-block repo-topic" data-value="{{.Name}}">{{.Name}}{{svg "octicon-x" 16 "delete icon"}}</a>
2525
{{end}}
2626
<div class="text"></div>
2727
</div>
2828
<div>
29-
<button class="ui primary button" id="save_topic" data-link="{{.RepoLink}}/topics">{{ctx.Locale.Tr "save"}}</button>
30-
<button class="ui basic button" id="cancel_topic_edit">{{ctx.Locale.Tr "cancel"}}</button>
29+
<button class="ui primary button" id="save_topic_{{.viewType}}" data-link="{{.ctxData.RepoLink}}/topics">{{ctx.Locale.Tr "save"}}</button>
30+
<button class="ui basic button" id="cancel_topic_edit_{{.viewType}}">{{ctx.Locale.Tr "cancel"}}</button>
3131
</div>
3232
</div>
3333
{{end}}
34-
{{if .ReadmeExist}}
34+
{{if .ctxData.ReadmeExist}}
3535
<div class="flex-item-body tw-mt-2">
36-
<a class="tw-flex tw-items-center tw-gap-2 muted" href="{{.TreeLink}}/{{.FileName}}">
36+
<a class="tw-flex tw-items-center tw-gap-2 muted" href="{{.ctxData.TreeLink}}/{{.ctxData.FileName}}">
3737
{{svg "octicon-book"}}{{ctx.Locale.Tr "readme"}}
3838
</a>
3939
</div>
4040
{{end}}
41-
{{if .DetectedRepoLicenses}}
41+
{{if .ctxData.DetectedRepoLicenses}}
4242
<div class="flex-item-body">
43-
<a class="tw-flex tw-items-center tw-gap-2 muted" href="{{.RepoLink}}/src/{{.Repository.DefaultBranch}}/{{PathEscapeSegments .LicenseFileName}}" data-tooltip-placement="top" data-tooltip-content="{{StringUtils.Join .DetectedRepoLicenses ", "}}">
44-
{{svg "octicon-law"}}{{if eq (len .DetectedRepoLicenses) 1}}{{index .DetectedRepoLicenses 0}}{{else}}{{ctx.Locale.Tr "repo.multiple_licenses"}}{{end}}
43+
<a class="tw-flex tw-items-center tw-gap-2 muted" href="{{.ctxData.RepoLink}}/src/{{.ctxData.Repository.DefaultBranch}}/{{PathEscapeSegments .ctxData.LicenseFileName}}" data-tooltip-placement="top" data-tooltip-content="{{StringUtils.Join .ctxData.DetectedRepoLicenses ", "}}">
44+
{{svg "octicon-law"}}{{if eq (len .ctxData.DetectedRepoLicenses) 1}}{{index .ctxData.DetectedRepoLicenses 0}}{{else}}{{ctx.Locale.Tr "repo.multiple_licenses"}}{{end}}
4545
</a>
4646
</div>
4747
{{end}}
48-
{{if .CitiationExist}}
48+
{{if .ctxData.CitiationExist}}
4949
<div class="flex-item-body">
50-
<a class="tw-flex tw-items-center tw-gap-2 muted" id="cite-repo-button">
50+
<a class="tw-flex tw-items-center tw-gap-2 muted" id="cite-repo-button-{{.viewType}}">
5151
{{svg "octicon-cross-reference"}}{{ctx.Locale.Tr "repo.cite_this_repo"}}
5252
</a>
5353
</div>

web_src/js/features/citation.ts

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,36 @@ export async function initCitationFileCopyContent() {
4242
citationCopyApa.classList.toggle('primary', !isBibtex);
4343
};
4444

45-
document.querySelector('#cite-repo-button')?.addEventListener('click', async () => {
46-
fomanticQuery(elModal).modal('show');
47-
elModal.classList.add('is-loading');
45+
for (const viewType of ['desktop', 'mobile']) {
46+
document.querySelector(`#cite-repo-button-${viewType}`)?.addEventListener('click', async () => {
47+
fomanticQuery(elModal).modal('show');
48+
elModal.classList.add('is-loading');
4849

49-
try {
5050
try {
51-
await initInputCitationValue(citationCopyApa, citationCopyBibtex);
52-
} catch (e) {
53-
console.error(`initCitationFileCopyContent error: ${e}`, e);
54-
return;
55-
}
56-
updateUi();
57-
58-
citationCopyApa.addEventListener('click', () => {
59-
localStorage.setItem('citation-copy-format', 'apa');
51+
try {
52+
await initInputCitationValue(citationCopyApa, citationCopyBibtex);
53+
} catch (e) {
54+
console.error(`initCitationFileCopyContent error: ${e}`, e);
55+
return;
56+
}
6057
updateUi();
61-
});
6258

63-
citationCopyBibtex.addEventListener('click', () => {
64-
localStorage.setItem('citation-copy-format', 'bibtex');
65-
updateUi();
66-
});
59+
citationCopyApa.addEventListener('click', () => {
60+
localStorage.setItem('citation-copy-format', 'apa');
61+
updateUi();
62+
});
6763

68-
inputContent.addEventListener('click', () => {
69-
inputContent.select();
70-
});
71-
} finally {
72-
elModal.classList.remove('is-loading');
73-
}
74-
});
64+
citationCopyBibtex.addEventListener('click', () => {
65+
localStorage.setItem('citation-copy-format', 'bibtex');
66+
updateUi();
67+
});
68+
69+
inputContent.addEventListener('click', () => {
70+
inputContent.select();
71+
});
72+
} finally {
73+
elModal.classList.remove('is-loading');
74+
}
75+
});
76+
}
7577
}

web_src/js/features/repo-home.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import {fomanticQuery} from '../modules/fomantic/base.ts';
77
const {appSubUrl} = window.config;
88

99
export function initRepoTopicBar() {
10-
const mgrBtns = document.querySelectorAll<HTMLButtonElement>('#manage_topic');
11-
if (mgrBtns.length === 0) return;
10+
for (const viewType of ['desktop', 'mobile']) {
11+
const mgrBtn = document.querySelector<HTMLButtonElement>(`#manage_topic_${viewType}`);
12+
if (!mgrBtn) continue;
1213

13-
for (const mgrBtn of mgrBtns) {
14-
const editDiv = mgrBtn.parentNode.querySelector('#topic_edit');
15-
const viewDiv = mgrBtn.parentNode.querySelector('#repo-topics');
14+
const editDiv = mgrBtn.parentNode.querySelector(`#topic_edit_${viewType}`);
15+
const viewDiv = mgrBtn.parentNode.querySelector(`#repo-topics-${viewType}`);
1616
const topicDropdown = editDiv.querySelector('.ui.dropdown');
1717
let lastErrorToast;
1818

@@ -22,14 +22,14 @@ export function initRepoTopicBar() {
2222
topicDropdown.querySelector<HTMLInputElement>('input.search').focus();
2323
});
2424

25-
mgrBtn.parentNode.querySelector('#cancel_topic_edit').addEventListener('click', () => {
25+
mgrBtn.parentNode.querySelector(`#cancel_topic_edit_${viewType}`).addEventListener('click', () => {
2626
lastErrorToast?.hideToast();
2727
hideElem(editDiv);
2828
showElem(viewDiv);
2929
mgrBtn.focus();
3030
});
3131

32-
mgrBtn.parentNode.querySelector('#save_topic').addEventListener('click', async (e: MouseEvent & {target: HTMLButtonElement}) => {
32+
mgrBtn.parentNode.querySelector(`#save_topic_${viewType}`).addEventListener('click', async (e: MouseEvent & {target: HTMLButtonElement}) => {
3333
lastErrorToast?.hideToast();
3434
const topics = editDiv.querySelector<HTMLInputElement>('input[name=topics]').value;
3535

0 commit comments

Comments
 (0)