Got comments working

This commit is contained in:
2026-03-01 13:18:12 -05:00
parent 5483e42bb4
commit 7c090c647e
4 changed files with 48 additions and 13 deletions

View File

@@ -20,3 +20,17 @@ export async function postComment(comment: DiscussionComment) {
}
}
export async function getPostComments(postId: number): Promise<DiscussionComment[]> {
const res = await fetch(`${addr}/discussions/${postId}/comments`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
credentials: 'include',
});
if (!res.ok) {
throw new Error("Failed to fetch comments");
}
return res.json();
}

View File

@@ -1,17 +1,26 @@
<script setup lang="ts">
import { DiscussionComment } from '@shared/types/discussion';
import DiscussionCommentView from './DiscussionCommentView.vue';
import CommentForm from './CommentForm.vue';
import { DiscussionComment } from '@shared/types/discussion';
import DiscussionCommentView from './DiscussionCommentView.vue';
import CommentForm from './CommentForm.vue';
import { ref } from 'process';
import { getPostComments } from '@/api/discussion';
const props = defineProps<{
parentId: number;
comments: DiscussionComment[];
}>();
const props = defineProps<{
parentId: number,
comments: DiscussionComment[]
}>()
function onCommentPosted() {
// TODO: Refresh comments if needed
}
const emit = defineEmits<{
(e: 'commentsUpdated', comments: DiscussionComment[]): void
}>()
async function onCommentPosted() {
const res = await getPostComments(props.parentId);
console.log(res);
// tell parent to update state
emit('commentsUpdated', res);
}
</script>
<template>

View File

@@ -96,7 +96,7 @@
</div>
<!-- discussion placeholder -->
<CommentThread :parent-id="post.id" :comments="post.comments" />
<CommentThread :parent-id="post.id" :comments="post.comments" @comments-updated="post.comments = $event" />
</div>
<div v-else>