diff --git a/app/components/ui/modal/CreatePostModal.vue b/app/components/ui/modal/CreatePostModal.vue index 572e4d0..aa73f73 100644 --- a/app/components/ui/modal/CreatePostModal.vue +++ b/app/components/ui/modal/CreatePostModal.vue @@ -5,12 +5,14 @@ const props = defineProps<{ isOpen: boolean; api: string; token: string | null; + postToEdit?: any; }>(); const emit = defineEmits(['close', 'refresh']); interface Tag { id: number; name: string; } +const notifications = useNotificationStore(); const isSubmitting = ref(false); const availableTags = ref([]); const errors = reactive({ @@ -73,26 +75,41 @@ async function submitPublication() { authors: uploadForm.authors, type: uploadForm.type, abstract: uploadForm.abstract, - tags: uploadForm.selectedTagIds, - // Sending fixed defaults for removed fields to maintain API compatibility if needed - publication_date: new Date().toISOString().split('T')[0], - is_confidential: false + tags: uploadForm.selectedTagIds }; - const formData = new FormData(); - if (uploadForm.file) formData.append('file', uploadForm.file); - formData.append('data', JSON.stringify(metadata)); + const isEditing = !!props.postToEdit; + const url = isEditing + ? `${props.api}/publications/${props.postToEdit.id}` + : `${props.api}/publications`; - await $fetch(`${props.api}/publications`, { - method: 'POST', - headers: { Authorization: `Bearer ${props.token}` }, - body: formData + let requestBody: any; + let headers: Record = { + Authorization: `Bearer ${props.token}` + }; + + if (!isEditing || uploadForm.file) { + const formData = new FormData(); + if (uploadForm.file) formData.append('file', uploadForm.file); + formData.append('data', JSON.stringify(metadata)); + requestBody = formData; + } + else { + requestBody = metadata; + } + + await $fetch(url, { + method: isEditing ? 'PATCH' : 'POST', + headers, + body: requestBody }); + notifications.success(`Publication ${isEditing ? "updated" : "created"}`); emit('refresh'); closeModal(); } catch (error) { - alert("Upload failed."); + console.error("Submission error:", error); + notifications.error("Operation failed"); } finally { isSubmitting.value = false; } @@ -113,19 +130,34 @@ function handleFileChange(event: Event) { } function closeModal() { + uploadForm.title = ''; + uploadForm.abstract = ''; + uploadForm.type = 'CONFERENCE_PAPER'; + uploadForm.newAuthorName = ''; + uploadForm.authors = []; + uploadForm.selectedTagIds = []; + uploadForm.file = null; emit('close'); } watch(() => props.isOpen, (newVal) => { if (newVal && availableTags.value.length === 0) fetchTags(); if (!newVal) { - // Reset errors on close errors.title = ''; errors.abstract = ''; } }); -// Helper for colorful tags +watch(() => props.postToEdit, (newPost) => { + if (newPost) { + uploadForm.title = newPost.title; + uploadForm.abstract = newPost.abstractText || newPost.abstract; + uploadForm.type = newPost.type; + uploadForm.authors = [...newPost?.authors]; + uploadForm.selectedTagIds = newPost?.tags.map((t: any) => t.id); + } +}, { immediate: true }); + const getTagClass = (id: number) => { const colors = [ 'bg-pink-100 text-pink-700 border-pink-200 dark:bg-pink-900/30 dark:text-pink-300', @@ -204,9 +236,6 @@ const getTagClass = (id: number) => { @@ -224,7 +253,7 @@ const getTagClass = (id: number) => {
-
+
@@ -241,7 +270,7 @@ const getTagClass = (id: number) => {
-
+
{{ author }} @@ -255,7 +284,7 @@ const getTagClass = (id: number) => {
-
+
{ if (idx > -1) uploadForm.selectedTagIds.splice(idx, 1); else uploadForm.selectedTagIds.push(tag.id); }" :class="[ - uploadForm.selectedTagIds.includes(tag.id) - ? getTagClass(tag.id) + ' border-transparent' - : 'bg-white dark:bg-slate-800 border-slate-200 dark:border-slate-700 text-slate-600 dark:text-slate-400' - ]" + uploadForm.selectedTagIds.includes(tag.id) + ? getTagClass(tag.id) + ' border-transparent' + : 'bg-white dark:bg-slate-800 border-slate-200 dark:border-slate-700 text-slate-600 dark:text-slate-400' + ]" class="px-3 py-1.5 rounded-full border text-xs font-bold uppercase tracking-tight transition-all shadow-sm whitespace-nowrap"> {{ tag.name }} @@ -286,7 +315,7 @@ const getTagClass = (id: number) => {
-
@@ -136,10 +138,9 @@
-
-
-
-
- - - - Joined {{ formattedDate }} -
@@ -345,7 +338,7 @@ }}
- Papers + Publications
@@ -387,46 +380,12 @@ Recent Publications - {{ userProfile.publications.length }} Papers + {{ userProfile.publications.length }} Publications
-
-
-
- -
-
- - -
- - -
-
-
@@ -449,21 +408,25 @@
- +
+ attachment +
{{ post.type.replace('_', ' ') }} - {{ post.publishedDate }} + {{ new + Date(post.publicationDate).toLocaleDateString('en-US', { + year: + 'numeric', month: 'long', day: 'numeric' + }) }} + +

{{ post.title }}

@@ -490,65 +484,16 @@ post.authors.join(', ') }}

- 💬 {{ post.comment_count }} Comments + 💬 {{ post.commentCount }} Comments
#{{ tag.name }}
-
- - -
- - -
- - -
- - -
@@ -561,7 +506,7 @@
-
@@ -604,7 +549,6 @@
-

Edit Profile @@ -620,13 +564,13 @@ class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1"> Name - + outline-none transition-all">

@@ -634,33 +578,34 @@ class="block text-sm font-medium text-slate-700 dark:text-slate-300 mb-1"> Email address - + outline-none transition-all">

Dont worry, Your email is going to be sold to russian hackers.

- - Reset Password + + Reset Password
-
-
@@ -672,69 +617,32 @@
-