Skip to content

Commit 17fb682

Browse files
committed
Reimplement quote reply and translation text
1 parent bb94379 commit 17fb682

File tree

7 files changed

+150
-10
lines changed

7 files changed

+150
-10
lines changed

options/locale/locale_en-US.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,6 +1936,12 @@ pull.agit_documentation = Review documentation about AGit
19361936
comments.edit.already_changed = Unable to save changes to the comment. It appears the content has already been changed by another user. Please refresh the page and try editing again to avoid overwriting their changes
19371937

19381938
conversations.delete_comment_confirm = Are you sure you want to delete this comment?
1939+
conversations.context.copy_link = Copy Link
1940+
conversations.context.quote_reply = Quote Reply
1941+
conversations.context.reference_issue = Reference in New Issue
1942+
conversations.context.edit = Edit
1943+
conversations.context.delete = Delete
1944+
conversations.no_content = No description provided.
19391945

19401946
milestones.new = New Milestone
19411947
milestones.closed = Closed %s

routers/web/repo/conversation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ func NewConversationComment(ctx *context.Context) {
935935
defer func() {
936936

937937
// Redirect to comment hashtag if there is any actual content.
938-
typeName := "commits"
938+
typeName := "commit"
939939
if comment != nil {
940940
ctx.JSONRedirect(fmt.Sprintf("%s/%s/%s#%s", ctx.Repo.RepoLink, typeName, conversation.CommitSha, comment.HashTag()))
941941
} else {

templates/repo/conversation/comments.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
<span class="no-content">{{ctx.Locale.Tr "repo.issues.no_content"}}</span>
7575
{{end}}
7676
</div>
77-
<div id="issuecomment-{{.ID}}-raw" class="raw-content tw-hidden">{{.Content}}</div>
77+
<div id="{{if $IsIssue}}issue{{end}}comment-{{.ID}}-raw" class="raw-content tw-hidden">{{.Content}}</div>
7878
<div class="edit-content-zone tw-hidden" data-update-url="{{$.RepoLink}}/comments/{{.ID}}" data-content-version="{{.ContentVersion}}" data-context="{{$.RepoLink}}" data-attachment-url="{{$.RepoLink}}/comments/{{.ID}}/attachments"></div>
7979
{{if .Attachments}}
8080
{{template "repo/issue/view_content/attachments" dict "Attachments" .Attachments "RenderedContent" .RenderedContent}}

templates/repo/conversation/context_menu.tmpl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@
1515
{{if .commit}}
1616
{{$referenceUrl = printf "%s#%s" .ctxData.Conversation.Link .item.HashTag}}
1717
{{end}}
18-
<div class="item context js-aria-clickable" data-clipboard-text-type="url" data-clipboard-text="{{$referenceUrl}}">{{ctx.Locale.Tr "repo.issues.context.copy_link"}}</div>
18+
<div class="item context js-aria-clickable" data-clipboard-text-type="url" data-clipboard-text="{{$referenceUrl}}">{{ctx.Locale.Tr "repo.conversations.context.copy_link"}}</div>
1919
{{if .ctxData.IsSigned}}
2020
{{$needDivider := false}}
2121
{{if not .ctxData.Repository.IsArchived}}
2222
{{$needDivider = true}}
23-
<div class="item context js-aria-clickable quote-reply {{if .diff}}quote-reply-diff{{end}}" data-target="{{.item.HashTag}}-raw">{{ctx.Locale.Tr "repo.issues.context.quote_reply"}}</div>
24-
{{if not ctx.Consts.RepoUnitTypeIssues.UnitGlobalDisabled}}
25-
<div class="item context js-aria-clickable reference-issue" data-target="{{.item.HashTag}}-raw" data-modal="#reference-issue-modal" data-poster="{{.item.Poster.GetDisplayName}}" data-poster-username="{{.item.Poster.Name}}" data-reference="{{$referenceUrl}}">{{ctx.Locale.Tr "repo.issues.context.reference_issue"}}</div>
23+
<div class="item context js-aria-clickable quote-reply {{if .diff}}quote-reply-diff{{end}}" data-target="{{.item.HashTag}}-raw">{{ctx.Locale.Tr "repo.conversations.context.quote_reply"}}</div>
24+
{{if and .issue (not ctx.Consts.RepoUnitTypeIssues.UnitGlobalDisabled)}}
25+
<div class="item context js-aria-clickable reference-issue" data-target="{{.item.HashTag}}-raw" data-modal="#reference-issue-modal" data-poster="{{.item.Poster.GetDisplayName}}" data-poster-username="{{.item.Poster.Name}}" data-reference="{{$referenceUrl}}">{{ctx.Locale.Tr "repo.conversations.context.reference_issue"}}</div>
2626
{{end}}
2727
{{if or .ctxData.Permission.IsAdmin .IsCommentPoster .ctxData.HasIssuesOrPullsWritePermission .ctxData.HasConversationsWritePermission}}
2828
<div class="divider"></div>
29-
<div class="item context js-aria-clickable edit-content">{{ctx.Locale.Tr "repo.issues.context.edit"}}</div>
29+
<div class="item context js-aria-clickable edit-content">{{ctx.Locale.Tr "repo.conversations.context.edit"}}</div>
3030
{{if .delete}}
3131
{{if .ctxData.IsIssue}}
32-
<div class="item context js-aria-clickable delete-comment" data-comment-id={{.item.HashTag}} data-url="{{.ctxData.RepoLink}}/comments/{{.item.ID}}/delete" data-locale="{{ctx.Locale.Tr "repo.issues.delete_comment_confirm"}}">{{ctx.Locale.Tr "repo.issues.context.delete"}}</div>
32+
<div class="item context js-aria-clickable delete-comment" data-comment-id={{.item.HashTag}} data-url="{{.ctxData.RepoLink}}/comments/{{.item.ID}}/delete" data-locale="{{ctx.Locale.Tr "repo.issues.delete_comment_confirm"}}">{{ctx.Locale.Tr "repo.conversations.context.delete"}}</div>
3333
{{else}}
3434
<div class="item context js-aria-clickable delete-comment conversation-comment" data-comment-id={{.item.HashTag}} data-url="{{.ctxData.RepoLink}}/conversations/comments/{{.item.ID}}/delete" data-locale="{{ctx.Locale.Tr "repo.conversations.delete_comment_confirm"}}">{{ctx.Locale.Tr "repo.conversations.context.delete"}}</div>
3535
{{end}}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import $ from 'jquery';
2+
import {handleReply} from './repo-issue.ts';
3+
import {getComboMarkdownEditor, initComboMarkdownEditor} from './comp/ComboMarkdownEditor.ts';
4+
import {POST} from '../modules/fetch.ts';
5+
import {showErrorToast} from '../modules/toast.ts';
6+
import {hideElem, showElem} from '../utils/dom.ts';
7+
import {attachRefIssueContextPopup} from './contextpopup.ts';
8+
import {initCommentContent, initMarkupContent} from '../markup/content.ts';
9+
10+
export function initRepoConversationCommentEdit() {
11+
// Edit issue or comment content
12+
$(document).on('click', '.edit-content', onEditContent);
13+
14+
// Quote reply
15+
$(document).on('click', '.quote-reply', async function (event) {
16+
event.preventDefault();
17+
const target = this.getAttribute('data-target');
18+
const quote = document.querySelector(`#${target}`).textContent.replace(/\n/g, '\n> ');
19+
const content = `> ${quote}\n\n`;
20+
21+
let editor;
22+
if (this.classList.contains('quote-reply-diff')) {
23+
const replyBtn = this.closest('.comment-code-cloud').querySelector('button.comment-form-reply');
24+
editor = await handleReply(replyBtn);
25+
} else {
26+
// for normal issue/comment page
27+
editor = getComboMarkdownEditor($('#comment-form .combo-markdown-editor'));
28+
}
29+
if (editor) {
30+
if (editor.value()) {
31+
editor.value(`${editor.value()}\n\n${content}`);
32+
} else {
33+
editor.value(content);
34+
}
35+
editor.focus();
36+
editor.moveCursorToEnd();
37+
}
38+
});
39+
}
40+
41+
async function onEditContent(event) {
42+
event.preventDefault();
43+
44+
const segment = this.closest('.header').nextElementSibling;
45+
const editContentZone = segment.querySelector('.edit-content-zone');
46+
const renderContent = segment.querySelector('.render-content');
47+
const rawContent = segment.querySelector('.raw-content');
48+
49+
let comboMarkdownEditor;
50+
51+
const cancelAndReset = (e) => {
52+
e.preventDefault();
53+
showElem(renderContent);
54+
hideElem(editContentZone);
55+
comboMarkdownEditor.dropzoneReloadFiles();
56+
};
57+
58+
const saveAndRefresh = async (e) => {
59+
e.preventDefault();
60+
renderContent.classList.add('is-loading');
61+
showElem(renderContent);
62+
hideElem(editContentZone);
63+
try {
64+
const params = new URLSearchParams({
65+
content: comboMarkdownEditor.value(),
66+
context: editContentZone.getAttribute('data-context'),
67+
content_version: editContentZone.getAttribute('data-content-version'),
68+
});
69+
for (const file of comboMarkdownEditor.dropzoneGetFiles() ?? []) {
70+
params.append('files[]', file);
71+
}
72+
73+
const response = await POST(editContentZone.getAttribute('data-update-url'), {data: params});
74+
const data = await response.json();
75+
if (response.status === 400) {
76+
showErrorToast(data.errorMessage);
77+
return;
78+
}
79+
editContentZone.setAttribute('data-content-version', data.contentVersion);
80+
if (!data.content) {
81+
renderContent.innerHTML = document.querySelector('#no-content').innerHTML;
82+
rawContent.textContent = '';
83+
} else {
84+
renderContent.innerHTML = data.content;
85+
rawContent.textContent = comboMarkdownEditor.value();
86+
const refIssues = renderContent.querySelectorAll('p .ref-issue');
87+
attachRefIssueContextPopup(refIssues);
88+
}
89+
const content = segment;
90+
if (!content.querySelector('.dropzone-attachments')) {
91+
if (data.attachments !== '') {
92+
content.insertAdjacentHTML('beforeend', data.attachments);
93+
}
94+
} else if (data.attachments === '') {
95+
content.querySelector('.dropzone-attachments').remove();
96+
} else {
97+
content.querySelector('.dropzone-attachments').outerHTML = data.attachments;
98+
}
99+
comboMarkdownEditor.dropzoneSubmitReload();
100+
initMarkupContent();
101+
initCommentContent();
102+
} catch (error) {
103+
showErrorToast(`Failed to save the content: ${error}`);
104+
console.error(error);
105+
} finally {
106+
renderContent.classList.remove('is-loading');
107+
}
108+
};
109+
110+
comboMarkdownEditor = getComboMarkdownEditor(editContentZone.querySelector('.combo-markdown-editor'));
111+
if (!comboMarkdownEditor) {
112+
editContentZone.innerHTML = document.querySelector('#issue-comment-editor-template').innerHTML;
113+
comboMarkdownEditor = await initComboMarkdownEditor(editContentZone.querySelector('.combo-markdown-editor'));
114+
editContentZone.querySelector('.ui.cancel.button').addEventListener('click', cancelAndReset);
115+
editContentZone.querySelector('.ui.primary.button').addEventListener('click', saveAndRefresh);
116+
}
117+
118+
// Show write/preview tab and copy raw content as needed
119+
showElem(editContentZone);
120+
hideElem(renderContent);
121+
// FIXME: ideally here should reload content and attachment list from backend for existing editor, to avoid losing data
122+
if (!comboMarkdownEditor.value()) {
123+
comboMarkdownEditor.value(rawContent.textContent);
124+
}
125+
comboMarkdownEditor.switchTabToEditor();
126+
comboMarkdownEditor.focus();
127+
}

web_src/js/features/repo-conversation.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {GET, POST} from '../modules/fetch.ts';
1+
import {POST} from '../modules/fetch.ts';
22

33
export function initRepoConversationCommentDelete() {
44
// Delete comment
@@ -56,4 +56,5 @@ export function initRepoConversationCommentDelete() {
5656
}
5757
}
5858
});
59-
}
59+
}
60+

web_src/js/features/repo-legacy.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import {
88
import {
99
initRepoConversationCommentDelete
1010
} from './repo-conversation.ts'
11+
import {
12+
initRepoConversationCommentEdit
13+
} from './repo-conversation-edit.ts'
1114
import {initUnicodeEscapeButton} from './repo-unicode-escape.ts';
1215
import {svg} from '../svg.ts';
1316
import {htmlEscape} from 'escape-goat';
@@ -423,6 +426,9 @@ export function initRepository() {
423426
if ($('.conversation-container').length > 0) {
424427
initCompReactionSelector();
425428
initRepoConversationCommentDelete();
429+
if ($('.repository.view.issue').length == 0) {
430+
initRepoConversationCommentEdit();
431+
}
426432
}
427433

428434
initUnicodeEscapeButton();

0 commit comments

Comments
 (0)