import { ref, onMounted } from "vue";
// Composables
- import type { User } from "@/api/users";
import { useBuild } from "@/composables/builds";
// Fetch the build UUID
const loading = ref(true);
const error = ref<Error | null>(null);
- const watchers = ref<User[] | null>(null);
// Fetch the build
- const { getWatchers } = useBuild(props.uuid);
+ const { watchers, getWatchers } = useBuild(props.uuid);
onMounted(async () => {
try {
- watchers.value = await getWatchers();
+ await getWatchers();
} catch (err) {
error.value = err as Error;
} finally {
export function useBuild(uuid: string) {
const build = ref<Build>();
+ // Cache all watchers
+ const watchers = ref<User[]>();
+
// Fetch the build
async function loadBuild() {
build.value = await fetchBuild(uuid);
// Fetch all watchers
async function getWatchers(): Promise<User[]> {
- return await fetchBuildWatchers(uuid);
+ if (!watchers.value)
+ watchers.value = await fetchBuildWatchers(uuid);
+
+ return watchers.value;
}
return {
build,
+ watchers,
loadBuild,
getBugs,
getWatchers,