From: Michael Tremer Date: Fri, 18 Jul 2025 16:59:28 +0000 (+0000) Subject: frontend: Implement watching/unwatching builds X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b92559eebe5e6767cfae05a4d7da0c6e9151fca;p=pbs.git frontend: Implement watching/unwatching builds Signed-off-by: Michael Tremer --- diff --git a/frontend/src/api/builds.ts b/frontend/src/api/builds.ts index 8b93e50a..e7d5f794 100644 --- a/frontend/src/api/builds.ts +++ b/frontend/src/api/builds.ts @@ -44,3 +44,11 @@ export async function fetchBuildWatchers(uuid: string): Promise { // Fetch all users concurrently return await Promise.all(users); } + +export async function startWatchingBuild(uuid: string): Promise { + await api.post(`/v1/builds/${uuid}/watchers`); +} + +export async function stopWatchingBuild(uuid: string): Promise { + await api.delete(`/v1/builds/${uuid}/watchers`); +} diff --git a/frontend/src/components/BuildWatchers.vue b/frontend/src/components/BuildWatchers.vue index 330023b6..51e2fd04 100644 --- a/frontend/src/components/BuildWatchers.vue +++ b/frontend/src/components/BuildWatchers.vue @@ -2,6 +2,7 @@ import { ref, onMounted } from "vue"; // Composables + import { useAuth } from "@/composables/auth"; import { useBuild } from "@/composables/builds"; // Fetch the build UUID @@ -11,9 +12,19 @@ const loading = ref(true); const error = ref(null); + const watching = ref(false); // Fetch the build - const { watchers, getWatchers } = useBuild(props.uuid); + const { + watchers, + getWatchers, + isWatching, + startWatching, + stopWatching + } = useBuild(props.uuid); + + // Fetch authentication + const { user, isLoggedIn } = useAuth(); onMounted(async () => { try { @@ -23,7 +34,39 @@ } finally { loading.value = false; } + + // Is the current user watching? + if (user.value) + watching.value = await isWatching(user.value); }); + + const loadingAction = ref(false); + + async function watchBuild() { + loadingAction.value = true; + + try { + await startWatching(); + } finally { + loadingAction.value = false; + } + + // We are now watching + watching.value = true; + } + + async function unwatchBuild() { + loadingAction.value = true; + + try { + await stopWatching(); + } finally { + loadingAction.value = false; + } + + // We are no longer watching + watching.value = false; + }