From 505c18041bebf533ec63fed3790f54f5c6e1843b Mon Sep 17 00:00:00 2001
From: HampusM <hampus@hampusmat.com>
Date: Sat, 3 Jul 2021 17:45:18 +0200
Subject: Made a bunch of frontend stuff work

---
 packages/client/src/views/Repository.vue | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

(limited to 'packages/client/src/views/Repository.vue')

diff --git a/packages/client/src/views/Repository.vue b/packages/client/src/views/Repository.vue
index 24000d4..7b31545 100644
--- a/packages/client/src/views/Repository.vue
+++ b/packages/client/src/views/Repository.vue
@@ -24,18 +24,29 @@ export default {
 		const description = ref("");
 		const has_readme = ref(null);
 
-		const fetchProjects = async(repository) => {
-			console.log(repository);
-			const repository_data = await (await fetch(`${window.location.protocol}//${window.location.host}/api/v1/repos/${repository}`)).json();
-			name.value = repository_data.data.name;
-			description.value = repository_data.data.description;
-			has_readme.value = repository_data.data.has_readme;
+		const fetchProjects = async(router, path) => {
+			const repository = router.currentRoute._rawValue.params.repo;
+
+			const repository_data = await fetch(`${window.location.protocol}//${window.location.host}/api/v1/repos/${repository}`)
+				.catch(() => {
+					if(path.split("/").length === 2) {
+						router.replace(`/${repository}/log`);
+					};
+					return null;
+				});
+
+			if(repository_data) {
+				const data = (await repository_data.json()).data;
+				name.value = data.name;
+				description.value = data.description;
+				has_readme.value = data.has_readme;
+			}
 		};
 
 		return { name, description, has_readme, fetchProjects };
 	},
 	created() {
-		this.fetchProjects(this.$router.currentRoute._rawValue.params.repo);
+		this.fetchProjects(this.$router, this.$route.path);
 	}
 };
 </script>
-- 
cgit v1.2.3-18-g5258

