Skip to content

Commit

Permalink
Restore function to Show more button
Browse files Browse the repository at this point in the history
There was a serious regression in go-gitea#21012 which broke the Show More
button on the diff page, and the show more button was also broken on the
file tree too.

This PR fixes this by resetting the pageData.diffFiles as the vue
watched value and reattachs a function to the show more button outside
of the file tree view.

Fix go-gitea#22380

Signed-off-by: Andrew Thornton <[email protected]>
  • Loading branch information
zeripath committed Jan 10, 2023
1 parent e7f1d45 commit d4f30bb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions web_src/js/components/DiffFileTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default {
},
computed: {
fileTree() {
pageData.diffFileInfo.files = this.files;
const result = [];
for (const file of this.files) {
// Split file into directories
Expand Down
21 changes: 21 additions & 0 deletions web_src/js/features/repo-diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,46 @@ function onShowMoreFiles() {

export function doLoadMoreFiles(link, diffEnd, callback) {
const url = `${link}?skip-to=${diffEnd}&file-only=true`;
loadMoreFiles(url, callback);
}

function loadMoreFiles(url, callback) {
const $target = $('a#diff-show-more-files');
if ($target.hasClass('disabled')) {
callback();
return;
}
$target.addClass('disabled');
$.ajax({
type: 'GET',
url,
}).done((resp) => {
if (!resp) {
$target.removeClass('disabled');
callback(resp);
return;
}
$('#diff-incomplete').replaceWith($(resp).find('#diff-file-boxes').children());
// By simply rerunning the script we add the new data to our existing
// pagedata object. this triggers vue and the filetree and filelist will
// render the new elements.
$('body').append($(resp).find('script#diff-data-script'));
onShowMoreFiles();
callback(resp);
}).fail(() => {
$target.removeClass('disabled');
callback();
});
}

export function initRepoDiffShowMore() {
$(document).on('click', 'a#diff-show-more-files', (e) => {
e.preventDefault();

const $target = $(e.target);
loadMoreFiles($target.data('href'), () => {});
});

$(document).on('click', 'a.diff-show-more-button', (e) => {
e.preventDefault();
const $target = $(e.target);
Expand Down

0 comments on commit d4f30bb

Please sign in to comment.