From ee99cf6313ba565523b3c43f61ffda4b71e2c39b Mon Sep 17 00:00:00 2001
From: wxiaoguang <wxiaoguang@gmail.com>
Date: Tue, 30 May 2023 18:53:15 +0800
Subject: Refactor diffFileInfo / DiffTreeStore  (#24998)

Follow  #21012, #22399

Replace #24983, fix #24938

Help #24956

Now, the `window.config.pageData.diffFileInfo` itself is a reactive
store, so it's quite easy to sync values/states by it, no need to do
"doLoadMoreFiles" or "callback".

Screenshot: these two buttons both work. After complete loading, the UI
is also right.

<details>


![image](https://github.com/go-gitea/gitea/assets/2114189/cc6310fd-7f27-45ea-ab4f-24952a87b421)


![image](https://github.com/go-gitea/gitea/assets/2114189/4c11dd67-ac03-4568-8541-91204d27a4e3)


![image](https://github.com/go-gitea/gitea/assets/2114189/38a22cec-41be-41e6-a209-f347b7a4c1de)

</details>
---
 web_src/js/components/DiffFileList.vue | 28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

(limited to 'web_src/js/components/DiffFileList.vue')

diff --git a/web_src/js/components/DiffFileList.vue b/web_src/js/components/DiffFileList.vue
index 658357a887..131be01811 100644
--- a/web_src/js/components/DiffFileList.vue
+++ b/web_src/js/components/DiffFileList.vue
@@ -1,10 +1,10 @@
 <template>
-  <ol class="diff-detail-box diff-stats gt-m-0" ref="root" v-if="fileListIsVisible">
-    <li v-for="file in files" :key="file.NameHash">
+  <ol class="diff-detail-box diff-stats gt-m-0" ref="root" v-if="store.fileListIsVisible">
+    <li v-for="file in store.files" :key="file.NameHash">
       <div class="gt-font-semibold gt-df gt-ac pull-right">
-        <span v-if="file.IsBin" class="gt-ml-1 gt-mr-3">{{ binaryFileMessage }}</span>
+        <span v-if="file.IsBin" class="gt-ml-1 gt-mr-3">{{ store.binaryFileMessage }}</span>
         {{ file.IsBin ? '' : file.Addition + file.Deletion }}
-        <span v-if="!file.IsBin" class="diff-stats-bar gt-mx-3" :data-tooltip-content="statisticsMessage.replace('%d', (file.Addition + file.Deletion)).replace('%d', file.Addition).replace('%d', file.Deletion)">
+        <span v-if="!file.IsBin" class="diff-stats-bar gt-mx-3" :data-tooltip-content="store.statisticsMessage.replace('%d', (file.Addition + file.Deletion)).replace('%d', file.Addition).replace('%d', file.Deletion)">
           <div class="diff-stats-add-bar" :style="{ 'width': diffStatsWidth(file.Addition, file.Deletion) }"/>
         </span>
       </div>
@@ -12,22 +12,21 @@
       <span :class="['status', diffTypeToString(file.Type)]" :data-tooltip-content="diffTypeToString(file.Type)">&nbsp;</span>
       <a class="file gt-mono" :href="'#diff-' + file.NameHash">{{ file.Name }}</a>
     </li>
-    <li v-if="isIncomplete" id="diff-too-many-files-stats" class="gt-pt-2">
-      <span class="file gt-df gt-ac gt-sb">{{ tooManyFilesMessage }}
-        <a :class="['ui', 'basic', 'tiny', 'button', isLoadingNewData === true ? 'disabled' : '']" id="diff-show-more-files-stats" @click.stop="loadMoreData">{{ showMoreMessage }}</a>
+    <li v-if="store.isIncomplete" class="gt-pt-2">
+      <span class="file gt-df gt-ac gt-sb">{{ store.tooManyFilesMessage }}
+        <a :class="['ui', 'basic', 'tiny', 'button', store.isLoadingNewData ? 'disabled' : '']" @click.stop="loadMoreData">{{ store.showMoreMessage }}</a>
       </span>
     </li>
   </ol>
 </template>
 
 <script>
-import {doLoadMoreFiles} from '../features/repo-diff.js';
-
-const {pageData} = window.config;
+import {loadMoreFiles} from '../features/repo-diff.js';
+import {diffTreeStore} from '../modules/stores.js';
 
 export default {
   data: () => {
-    return pageData.diffFileInfo;
+    return {store: diffTreeStore()};
   },
   mounted() {
     document.getElementById('show-file-list-btn').addEventListener('click', this.toggleFileList);
@@ -37,7 +36,7 @@ export default {
   },
   methods: {
     toggleFileList() {
-      this.fileListIsVisible = !this.fileListIsVisible;
+      this.store.fileListIsVisible = !this.store.fileListIsVisible;
     },
     diffTypeToString(pType) {
       const diffTypes = {
@@ -53,10 +52,7 @@ export default {
       return `${adds / (adds + dels) * 100}%`;
     },
     loadMoreData() {
-      this.isLoadingNewData = true;
-      doLoadMoreFiles(this.link, this.diffEnd, () => {
-        this.isLoadingNewData = false;
-      });
+      loadMoreFiles(this.store.linkLoadMore);
     }
   },
 };
-- 
cgit v1.2.3

