From 75e8ae6ebd9df23275fb14eea88da0b56d006313 Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 9 Jun 2021 17:37:43 +0200 Subject: Frontend has proper error handling & api fetching is in it's own file --- packages/client/src/views/RepositoryTree.vue | 49 +++++++++++++++------------- 1 file changed, 26 insertions(+), 23 deletions(-) (limited to 'packages/client/src/views/RepositoryTree.vue') diff --git a/packages/client/src/views/RepositoryTree.vue b/packages/client/src/views/RepositoryTree.vue index 1b61c42..898b12c 100644 --- a/packages/client/src/views/RepositoryTree.vue +++ b/packages/client/src/views/RepositoryTree.vue @@ -11,11 +11,11 @@ }))" :active-item="(pathArr.length === 0) ? $router.currentRoute._rawValue.params.repo : pathArr[pathArr.length - 1]" /> + :tree="tree" v-if="tree" /> + :content="blob_content" v-if="blob_content" /> + { + blob_content.value = null; + tree.value = null; + path.value = props.pathArr ? props.pathArr.join("/") : undefined; - const data = await (await fetch(`${window.location.protocol}//${window.location.host}/api/v1/repos/${repository}/tree${path.value ? "?path=" + path.value : ""}`)).json(); - console.log(path.value); - type.value = data.data.type; - if(data.data.type === "tree") { - const tree_data = data.data.tree; + const tree_data = await fetchData(`repos/${repository}/tree${path.value ? "?path=" + path.value : ""}`, fetch_failed, is_loading, "tree"); - let tree_trees = Object.entries(tree_data).filter((entry) => entry[1].type === "tree"); - tree_trees = tree_trees.sort((a, b) => a[0].localeCompare(b[0])); + if(tree_data) { + if(tree_data.type === "tree") { + let tree_trees = Object.entries(tree_data.tree).filter((entry) => entry[1].type === "tree"); + tree_trees = tree_trees.sort((a, b) => a[0].localeCompare(b[0])); - let tree_blobs = Object.entries(tree_data).filter((entry) => entry[1].type === "blob"); - tree_blobs = tree_blobs.sort((a, b) => a[0].localeCompare(b[0])); + let tree_blobs = Object.entries(tree_data.tree).filter((entry) => entry[1].type === "blob"); + tree_blobs = tree_blobs.sort((a, b) => a[0].localeCompare(b[0])); - tree.value = Object.fromEntries(tree_trees.concat(tree_blobs)); - } else { - blob_content.value = data.data.content; + tree.value = Object.fromEntries(tree_trees.concat(tree_blobs)); + console.log(tree.value); + } else { + blob_content.value = tree_data.content; + } } - - is_loading.value = false; }; return { - type, tree, blob_content, is_loading, + fetch_failed, path, fetchTree }; -- cgit v1.2.3-18-g5258