feat: realtime updates for study spaces and reports
This commit is contained in:
@@ -17,7 +17,16 @@
|
||||
invalidate("supabase:auth");
|
||||
}
|
||||
});
|
||||
return () => data.subscription.unsubscribe();
|
||||
const spacesChannel = supabase
|
||||
.channel("study_space_updates")
|
||||
.on("broadcast", { event: "study_space_updated" }, (payload) => {
|
||||
invalidate("db:study_spaces");
|
||||
})
|
||||
.subscribe();
|
||||
return () => {
|
||||
data.subscription.unsubscribe();
|
||||
spacesChannel.unsubscribe();
|
||||
};
|
||||
});
|
||||
$effect(() => {
|
||||
if (route.id === "/filter") {
|
||||
|
||||
@@ -207,6 +207,13 @@
|
||||
.insert(genTimings(studySpaceInsert.id));
|
||||
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!");
|
||||
// Redirect to the new study space page
|
||||
await goto(`/space/${studySpaceInsert.id}`, {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
const { data } = $props();
|
||||
const { reports, supabase } = $derived(data);
|
||||
import { invalidate } from "$app/navigation";
|
||||
import { onMount } from "svelte";
|
||||
|
||||
let deleting = $state(false);
|
||||
|
||||
@@ -18,6 +19,16 @@
|
||||
return alert(`Error submitting report: ${reportDeleteError.message}`);
|
||||
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>
|
||||
|
||||
<Navbar>
|
||||
|
||||
Reference in New Issue
Block a user