Skip to content

Commit

Permalink
fix file list bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yoiteyou committed Jan 29, 2025
1 parent 09c3d0f commit 545203f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
42 changes: 40 additions & 2 deletions frontend/src/components/shared/FileList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
</el-popover>
</div>
</div>
<p v-if="!loading && filePageCursor" class="text-brand-300 cursor-pointer my-2" @click="fetchFileListData">{{ $t('all.loadMore') }}</p>
<el-skeleton v-if="loading" class="mt-4" :rows="5" animated />
</div>
</template>
Expand Down Expand Up @@ -157,6 +158,9 @@
const lastCommit = ref()
const lastCommitAvatar = ref('https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png')
const prefixPath = document.location.pathname.split('/')[1]
const filePageCursor = ref('')
const commitList = ref([])
const tempCommit = ref([])
const emit = defineEmits(['changeBranch'])
Expand Down Expand Up @@ -255,14 +259,48 @@
}
}
const fetchCommits = async () => {
const url = `/${prefixPath}/${props.namespacePath}/refs/${props.currentBranch}/logs_tree/${props.currentPath}?offset=${commitList.value.length}&limit=50`
try {
const { response, data, error } = await useFetchApi(url).json()
if (data.value) {
tempCommit.value = data.value.data?.Commits
commitList.value = [...commitList.value, ...tempCommit.value]
tempCommit.value.forEach(commit => {
const file = files.value.find(f => f.name === commit.name);
if (file) {
file.commit = commit;
}
});
if (commitList.value.length < files.value.length) {
fetchCommits();
}
} else if (response.value.status === 403) {
ToUnauthorizedPage()
} else if (response.value.status === 404) {
ToNotFoundPage()
} else {
ElMessage.warning(error.value ? error.value.msg : 'Failed to fetch commit list')
}
} catch (error) {
console.log(error)
} finally {
loading.value = false
}
}
const fetchFileListData = async () => {
const url = `/${prefixPath}/${props.namespacePath}/tree?path=${props.currentPath}&ref=${props.currentBranch}`
const url = `/${prefixPath}/${props.namespacePath}/refs/${props.currentBranch}/tree/${props.currentPath}?cursor=${filePageCursor.value}&limit=500`
try {
const { response, data, error } = await useFetchApi(url).json()
if (data.value) {
files.value = data.value.data
files.value = [...files.value, ...data.value.data?.Files]
filePageCursor.value = data.value.data?.Cursor
fetchCommits()
} else if (response.value.status === 403) {
ToUnauthorizedPage()
} else if (response.value.status === 404) {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/locales/en_js/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,6 @@ export const all = {
more:"More",
sdkTips: "Please register first and then obtain the Token from OpenCSG's account page",
public: "Public",
private: "Private"
private: "Private",
loadMore: "Load more",
}
3 changes: 2 additions & 1 deletion frontend/src/locales/zh_js/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,6 @@ export const all = {
more:"更多",
sdkTips: "请先注册,然后从 OpenCSG 的账号页面获取 Token",
public: "公开",
private: "私有"
private: "私有",
loadMore:"加载更多"
}

0 comments on commit 545203f

Please sign in to comment.