bug fixes

This commit is contained in:
2023-09-02 19:30:45 +10:00
parent c36d4783e7
commit 7cf6b0bba6
5 changed files with 29 additions and 26 deletions

View File

@@ -28,7 +28,7 @@ trait HasAttachments
*/
public function getAttachments(): Collection
{
return Cache::remember($this->cacheKey(), now()->addDays(28), function () {
return Cache::remember($this->attachmentsCacheKey(), now()->addDays(28), function () {
return $this->attachments()->get();
});
}
@@ -61,7 +61,7 @@ trait HasAttachments
}
}
Cache::forget($this->cacheKey());
Cache::forget($this->attachmentsCacheKey());
$this->attachments()->createMany($attachmentItems);
}
@@ -72,7 +72,7 @@ trait HasAttachments
*/
public function deleteAttachments(): void
{
Cache::forget($this->cacheKey());
Cache::forget($this->attachmentsCacheKey());
$this->morphMany(\App\Models\Attachment::class, 'addendum')->delete();
}
@@ -91,7 +91,7 @@ trait HasAttachments
*
* @return string
*/
private function cacheKey(): string
private function attachmentsCacheKey(): string
{
return "attachments:{$this->getTable()}:{$this->id}";
}

View File

@@ -50,6 +50,7 @@ trait HasGallery
}
}
Cache::forget($this->galleryCacheKey());
$this->gallery()->createMany($galleryItems);
}
@@ -65,13 +66,18 @@ trait HasGallery
public function getGallery(): Collection
{
$cacheKey = 'gallery:' . $this->getTable() . ':' . $this->id;
if (Cache::has($cacheKey) === true) {
return Cache::get($cacheKey);
return Cache::remember($this->galleryCacheKey(), now()->addDays(28), function () {
return $this->gallery()->get();
});
}
$gallery = $this->morphMany(\App\Models\Gallery::class, 'addendum')->get();
Cache::put($cacheKey, $gallery, now()->addDays(14));
return $gallery;
/**
* Return the attachment cache key.
*
* @return string
*/
private function galleryCacheKey(): string
{
return "gallery:{$this->getTable()}:{$this->id}";
}
}

View File

@@ -175,7 +175,7 @@ const handleAddToGallery = async () => {
if (result) {
const mediaResult = result as Media[];
let newValue = props.modelValue;
let galleryIds = new Set(newValue.map((item) => item.id));
let galleryIds = new Set(mediaResult.map((item) => (item as Media).id));
mediaResult.forEach((item) => {
if (!galleryIds.has(item.id)) {
@@ -184,7 +184,7 @@ const handleAddToGallery = async () => {
}
});
emits("update:modelValue", newValue);
emits("update:modelValue", mediaResult);
}
};

View File

@@ -377,7 +377,7 @@
)}')`,
}">
<SMLoading
v-if="true"
v-if="getMediaStatus(item).busy"
small
class="bg-white bg-op-90 w-full h-full" />
<div

View File

@@ -78,7 +78,11 @@ import SMInput from "../../components/SMInput.vue";
import SMDropdown from "../../components/SMDropdown.vue";
import SMAttachments from "../../components/SMAttachments.vue";
import { api } from "../../helpers/api";
import { ArticleResponse, UserCollection } from "../../helpers/api.types";
import {
ArticleResponse,
Media,
UserCollection,
} from "../../helpers/api.types";
import { SMDate } from "../../helpers/datetime";
import { Form, FormControl } from "../../helpers/form";
import { And, DateTime, Min, Required } from "../../helpers/validate";
@@ -108,7 +112,7 @@ const form = reactive(
route.params.id ? "" : new SMDate("now").format("d/M/yy h:mm aa"),
DateTime(),
),
hero: FormControl(),
hero: FormControl("", Required()),
user_id: FormControl(userStore.id),
content: FormControl(),
}),
@@ -206,15 +210,12 @@ const handleSubmit = async (enableFormCallBack) => {
).format("yyyy/MM/dd HH:mm:ss", { utc: true }),
user_id: form.controls.user_id.value,
content: form.controls.content.value,
hero: form.controls.hero.value.id,
hero: (form.controls.hero.value as Media).id,
gallery: gallery.value.map((item) => item.id),
attachments: attachments.value.map((item) => item.id),
};
let article_id = "";
if (route.params.id) {
article_id = route.params.id as string;
await api.put({
url: `/articles/{id}`,
params: {
@@ -223,15 +224,10 @@ const handleSubmit = async (enableFormCallBack) => {
body: data,
});
} else {
let result = await api.post({
await api.post({
url: "/articles",
body: data,
});
if (result.data) {
const data = result.data as ArticleResponse;
article_id = data.article.id;
}
}
useToastStore().addToast({
@@ -250,6 +246,7 @@ const handleSubmit = async (enableFormCallBack) => {
router.push({ name: "dashboard-article-list" });
}
} catch (error) {
console.log(error);
form.apiErrors(error, (message) => {
useToastStore().addToast({
title: "An error occurred",