aboutsummaryrefslogtreecommitdiff
path: root/packages/client/src/views/Repository.vue
blob: 7b315455c3744d8b16aac43d717ecf8a0bf549b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<template>
	<div class="container">
		<RepositoryHeader :name="name" :description="description" />
		<RepositoryNavbar
			:repository="$router.currentRoute._rawValue.params.repo" :active-page="$router.currentRoute._rawValue.path.split('/')[2]"
			:has-readme="has_readme" />
		<router-view />
	</div>
</template>

<script>
import RepositoryHeader from "@/components/RepositoryHeader";
import RepositoryNavbar from "@/components/RepositoryNavbar";
import { ref } from "vue";

export default {
	name: "Repository",
	components: {
		RepositoryHeader,
		RepositoryNavbar
	},
	setup(props) {
		const name = ref("");
		const description = ref("");
		const has_readme = ref(null);

		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, this.$route.path);
	}
};
</script>