attachments support
This commit is contained in:
@@ -49,7 +49,7 @@
|
|||||||
</SMRow>
|
</SMRow>
|
||||||
<SMRow>
|
<SMRow>
|
||||||
<SMColumn>
|
<SMColumn>
|
||||||
<SMInputAttachments :model-value="attachments" />
|
<SMInputAttachments v-model:model-value="attachments" />
|
||||||
</SMColumn>
|
</SMColumn>
|
||||||
</SMRow>
|
</SMRow>
|
||||||
<SMRow>
|
<SMRow>
|
||||||
@@ -170,6 +170,13 @@ const loadData = async () => {
|
|||||||
: "";
|
: "";
|
||||||
form.controls.content.value = data.post.content;
|
form.controls.content.value = data.post.content;
|
||||||
form.controls.hero.value = data.post.hero;
|
form.controls.hero.value = data.post.hero;
|
||||||
|
|
||||||
|
attachments.value = (data.post.attachments || []).map(function (
|
||||||
|
attachment
|
||||||
|
) {
|
||||||
|
return attachment.id.toString();
|
||||||
|
});
|
||||||
|
console.log(attachments.value);
|
||||||
} else {
|
} else {
|
||||||
pageError.value = 404;
|
pageError.value = 404;
|
||||||
}
|
}
|
||||||
@@ -195,18 +202,33 @@ const handleSubmit = async () => {
|
|||||||
hero: form.controls.hero.value,
|
hero: form.controls.hero.value,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let post_id = "";
|
||||||
|
|
||||||
if (route.params.id) {
|
if (route.params.id) {
|
||||||
|
post_id = route.params.id as string;
|
||||||
await api.put({
|
await api.put({
|
||||||
url: `/posts/${route.params.id}`,
|
url: `/posts/${route.params.id}`,
|
||||||
body: data,
|
body: data,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await api.post({
|
let result = await api.post({
|
||||||
url: "/posts",
|
url: "/posts",
|
||||||
body: data,
|
body: data,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (result.data) {
|
||||||
|
const data = result.data as PostResponse;
|
||||||
|
post_id = data.post.id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await api.put({
|
||||||
|
url: `/posts/${post_id}/attachments`,
|
||||||
|
body: {
|
||||||
|
attachments: attachments.value,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
useToastStore().addToast({
|
useToastStore().addToast({
|
||||||
title: route.params.id ? "Post Updated" : "Post Created",
|
title: route.params.id ? "Post Updated" : "Post Created",
|
||||||
content: route.params.id
|
content: route.params.id
|
||||||
|
|||||||
Reference in New Issue
Block a user