Merge branch 'realtime' into 'master'

feat: realtime updates for study spaces and reports

See merge request gk1623/drp-48!29

Co-authored-by: Gleb Koval <gleb@koval.net>
This commit is contained in:
Ling, Alex
2025-06-16 20:29:27 +00:00
5 changed files with 39 additions and 1 deletions

View File

@@ -33,6 +33,11 @@
tags: newStudySpaceData.tags tags: newStudySpaceData.tags
}) })
.eq("id", newStudySpaceData.id ?? ""); .eq("id", newStudySpaceData.id ?? "");
await supabase.channel("study_space_updates").send({
type: "broadcast",
event: "study_space_updated",
payload: { id: newStudySpaceData.id }
});
invalidate("db:study_spaces"); invalidate("db:study_spaces");
if (feedbackUpload) return alert(`Error submitting feedback: ${feedbackUpload.message}`); if (feedbackUpload) return alert(`Error submitting feedback: ${feedbackUpload.message}`);
else alert("Feedback submitted successfully!"); else alert("Feedback submitted successfully!");

View File

@@ -29,6 +29,12 @@
.select() .select()
.single(); .single();
await supabase.channel("report_updates").send({
type: "broadcast",
event: "reports_updated",
payload: { study_space_id: studySpaceId }
});
if (reportUploadError) if (reportUploadError)
return alert(`Error submitting report: ${reportUploadError.message}`); return alert(`Error submitting report: ${reportUploadError.message}`);
else alert("Report submitted successfully!"); else alert("Report submitted successfully!");

View File

@@ -17,7 +17,16 @@
invalidate("supabase:auth"); invalidate("supabase:auth");
} }
}); });
return () => data.subscription.unsubscribe(); const spacesChannel = supabase
.channel("study_space_updates")
.on("broadcast", { event: "study_space_updated" }, () => {
invalidate("db:study_spaces");
})
.subscribe();
return () => {
data.subscription.unsubscribe();
spacesChannel.unsubscribe();
};
}); });
$effect(() => { $effect(() => {
if (route.id === "/filter") { if (route.id === "/filter") {

View File

@@ -207,6 +207,13 @@
.insert(genTimings(studySpaceInsert.id)); .insert(genTimings(studySpaceInsert.id));
if (hoursErr) return alert(`Error saving opening times: ${hoursErr.message}`); if (hoursErr) return alert(`Error saving opening times: ${hoursErr.message}`);
} }
await supabase.channel("study_space_updates").send({
type: "broadcast",
event: "study_space_updated",
payload: {
study_space_id: studySpaceInsert.id
}
});
alert("Thank you for your contribution!"); alert("Thank you for your contribution!");
// Redirect to the new study space page // Redirect to the new study space page
await goto(`/space/${studySpaceInsert.id}`, { await goto(`/space/${studySpaceInsert.id}`, {

View File

@@ -5,6 +5,7 @@
const { data } = $props(); const { data } = $props();
const { reports, supabase } = $derived(data); const { reports, supabase } = $derived(data);
import { invalidate } from "$app/navigation"; import { invalidate } from "$app/navigation";
import { onMount } from "svelte";
let deleting = $state(false); let deleting = $state(false);
@@ -18,6 +19,16 @@
return alert(`Error submitting report: ${reportDeleteError.message}`); return alert(`Error submitting report: ${reportDeleteError.message}`);
else alert("Report deleted successfully!"); else alert("Report deleted successfully!");
} }
onMount(() => {
const reportsChannel = supabase
.channel("report_updates")
.on("broadcast", { event: "reports_updated" }, () => {
invalidate("db:reports");
})
.subscribe();
return () => reportsChannel.unsubscribe();
});
</script> </script>
<Navbar> <Navbar>