From 5f04c1411219e168541f9c001f4e8b4a47191e0f Mon Sep 17 00:00:00 2001 From: Ian Torres Date: Thu, 19 Jun 2025 18:13:11 -0400 Subject: [PATCH] Subscribe and Publish implemented. --- components/Cards/ChannelChatCard.vue | 42 ++++++++++++- components/Forms/SubscribeForm.vue | 71 ++++++++++++++++++++++ components/Resources/Services/Channels.vue | 22 ++++++- 3 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 components/Forms/SubscribeForm.vue diff --git a/components/Cards/ChannelChatCard.vue b/components/Cards/ChannelChatCard.vue index a3eb487..06e9923 100644 --- a/components/Cards/ChannelChatCard.vue +++ b/components/Cards/ChannelChatCard.vue @@ -15,6 +15,8 @@ // along with this program. If not, see . import UCard from '@nuxt/ui/components/Card.vue'; +import * as z from "zod"; +import type {FormSubmitEvent} from "@nuxt/ui"; const props = defineProps<{ channel: string }>() const messages = ref([]) @@ -22,6 +24,36 @@ const messages = ref([]) const { connect, close } = useSocket() const route = useRoute(); +const schema = z.object({ + value: z.string(), +}) + +type Schema = z.output + +const state = reactive>({ + value: '', +}) + +const submit = async (event: FormSubmitEvent) => { + try { + const response = await $fetch(`/api/services/${route.params.id}/publish`, { + method: 'POST', + body: { + channel: props.channel, + value: event.data.value + } + }) + + toast.add({title: t('forms.event', { name: "Published"}), color: 'success'}) + console.log("Published ⤑ Response", response) + emit('success'); + } catch (error) { + toast.add({title: t('forms.event', { name: "Published ⤑ Exception"}), color: 'error'}) + console.error("Published ⤑ Exception", error) + throw error; + } +} + onMounted(() => { connect(props.channel, route.params.id!, (msg) => { if (msg.event === "MESSAGE") { @@ -40,10 +72,18 @@ onUnmounted(() => {

Channel: {{ props.channel }}


+
+    
+      
+        
+      
+
+      
+    
   
diff --git a/components/Forms/SubscribeForm.vue b/components/Forms/SubscribeForm.vue new file mode 100644 index 0000000..2ebebcb --- /dev/null +++ b/components/Forms/SubscribeForm.vue @@ -0,0 +1,71 @@ + + + \ No newline at end of file diff --git a/components/Resources/Services/Channels.vue b/components/Resources/Services/Channels.vue index 78a8ad7..81b6b18 100644 --- a/components/Resources/Services/Channels.vue +++ b/components/Resources/Services/Channels.vue @@ -31,12 +31,13 @@ const data = ref({ }); const loading = ref(true); +const open_subscribe = ref(false); const fetch = async () => { loading.value = true; data.value = await services.channels(route.params.id) as ChannelsResponse; - toast.add({title: t('forms.event', { name: "Channels Retrieved ⤑ Success"}), color: 'success'}) + toast.add({title: t('forms.event', {name: "Channels Retrieved ⤑ Success"}), color: 'success'}) console.log("Stats Retrieved ⤑ Success", data.value) loading.value = false; } @@ -49,9 +50,24 @@ onMounted(async () => {