aboutsummaryrefslogtreecommitdiff
path: root/packages/client/src/views/RepositoryAbout.vue
blob: d50a08101abb562dad116f9dc2440b9a556124da (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
53
54
55
56
57
58
59
60
61
<template>
	<div class="row">
		<div class="col fs-5 vld-parent">
			<RepositoryTreeBlob
				:repository="$router.currentRoute._rawValue.params.repo" path="README.md"
				:content="readme" v-if="readme" />
			<BaseErrorMessage :fetch-failed="fetch_failed" />
			<Loading
				:active="is_loading" :height="24"
				:width="24" color="#ffffff"
				:opacity="0" :is-full-page="false" />
		</div>
	</div>
</template>

<script lang="ts">
import { defineComponent, Ref, ref } from "vue";
import fetchData from "../util/fetch";
import { Tree } from "api";
import { getParam } from "../util/util";

import RepositoryTreeBlob from "../components/RepositoryTreeBlob.vue";
import Loading from "vue-loading-overlay";
import BaseErrorMessage from "../components/BaseErrorMessage.vue";

export default defineComponent({
	name: "RepositoryAbout",
	components: {
		RepositoryTreeBlob,
		Loading,
		BaseErrorMessage
	},
	setup(props) {
		const readme: Ref<string | null> = ref(null);
		const is_loading: Ref<boolean> = ref(true);
		const fetch_failed: Ref<string> = ref("");

		async function fetchReadme(repository: string) {
			const readme_data = await fetchData(`repos/${repository}/tree?path=README.md`, fetch_failed, is_loading, "tree") as Tree;

			if(readme_data && typeof readme_data.content === "string") {
				readme.value = readme_data.content;
			}
		};

		return {
			readme,
			is_loading,
			fetch_failed,
			fetchReadme
		};
	},
	created() {
		this.fetchReadme(getParam(this.$route.params, "repo"));
	}
});
</script>

<style lang="scss" scoped>
@import "~vue-loading-overlay/dist/vue-loading.css";
</style>