import api from "@/api";
import type { Bug } from "@/api/bugs";
+import type { User } from "@/api/users";
+import { fetchUser } from "@/api/users";
export interface Build {
// Name
const response = await api.get(`/v1/builds/${uuid}/bugs`);
return response.data as Bug[];
}
+
+// Fetch all watchers by the build UUID
+export async function fetchBuildWatchers(uuid: string): Promise<User[]> {
+ const response = await api.get(`/v1/builds/${uuid}/watchers`);
+
+ // Fetch all users by their name
+ const users = response.data.map(
+ ({ username }: { username: string }) => fetchUser(username)
+ );
+
+ // Fetch all users concurrently
+ return await Promise.all(users);
+}
<script setup lang="ts">
- // Import type
+ // Import types
import type { Build } from "@/api/builds";
+ import type { User } from "@/api/users";
+
+ // Import components
+ import BuildWatchers from "@/components/BuildWatchers.vue";
// Fetch the build
defineProps<{
</h5>
</div>
</div>
+
+ <BuildWatchers :uuid="build.uuid" />
</Container>
</div>
</div>
--- /dev/null
+<script setup lang="ts">
+ import { ref, onMounted } from "vue";
+
+ // Composables
+ import type { User } from "@/api/users";
+ import { useBuild } from "@/composables/builds";
+
+ // Fetch the build UUID
+ const props = defineProps<{
+ uuid: string,
+ }>();
+
+ const loading = ref(true);
+ const error = ref<Error | null>(null);
+ const watchers = ref<User[] | null>(null);
+
+ // Fetch the build
+ const { getWatchers } = useBuild(props.uuid);
+
+ onMounted(async () => {
+ try {
+ watchers.value = await getWatchers();
+ } catch (err) {
+ error.value = err as Error;
+ } finally {
+ loading.value = false;
+ }
+ });
+</script>
+
+<template>
+ <Loader :loading="loading" :error="error">
+ <div v-if="watchers" class="level">
+ <div class="level-left">
+ <RouterLink :to="{ name: 'UserView', params: { name: watcher.name }}"
+ class="level-item" v-for="watcher in watchers" :key="watcher.name">
+ <Avatar :user="watcher" size="32" is-rounded />
+ </RouterLink>
+ </div>
+ </div>
+ </Loader>
+</template>
import {
fetchBuild,
fetchBuildBugs,
+ fetchBuildWatchers,
} from "@/api/builds";
+import type { User } from "@/api/users";
export function useBuild(uuid: string) {
const build = ref<Build>();
return await fetchBuildBugs(uuid);
}
+ // Fetch all watchers
+ async function getWatchers(): Promise<User[]> {
+ return await fetchBuildWatchers(uuid);
+ }
+
return {
build,
loadBuild,
getBugs,
+ getWatchers,
};
}