@@ -88,13 +84,13 @@ onMounted(() => {
- {{ resource?.data?.total_all_time || "-" }}
+ {{ state?.data?.total_all_time || "-" }}
- {{ resource?.data?.total_last_month }} from last month
+ {{ state?.data?.total_last_month }} from last month
diff --git a/resources/js/composables/loadData.js b/resources/js/composables/loadData.js
deleted file mode 100644
index 70008bf..0000000
--- a/resources/js/composables/loadData.js
+++ /dev/null
@@ -1,32 +0,0 @@
-import axios from "axios";
-import { reactive } from "vue";
-
-export function useLoadData(defaultUrl = null) {
- return reactive({
- loading: false,
- data: null,
- fetchData(overrideUrl = null, cb = null) {
- const self = this;
- self.loading = true;
- const url = overrideUrl ? overrideUrl : defaultUrl;
-
- axios
- .get(url)
- .then((response) => {
- self.data = response.data;
-
- if (typeof cb === "function") {
- cb(self.data);
- }
- })
- .finally(() => {
- self.loading = false;
- });
- },
-
- promise(overrideUrl = null) {
- const url = overrideUrl ? overrideUrl : defaultUrl;
- return axios.get(url);
- },
- });
-}
diff --git a/resources/js/composables/confirmable.js b/resources/js/composables/useConfirmable.js
similarity index 100%
rename from resources/js/composables/confirmable.js
rename to resources/js/composables/useConfirmable.js
diff --git a/resources/js/composables/useToastable.js b/resources/js/composables/useToastable.js
new file mode 100644
index 0000000..85b276d
--- /dev/null
+++ b/resources/js/composables/useToastable.js
@@ -0,0 +1,29 @@
+import { reactive } from "vue";
+
+export const toasts = reactive({
+ list: [],
+});
+
+export function useToastable() {
+ const addToast = (
+ message,
+ { type = "success", duration = 3000, isHtml = false } = {},
+ ) => {
+ const id = Date.now();
+ toasts.list.push({ id, message, type, isHtml });
+
+ // Automatically remove the toast after the specified duration
+ setTimeout(() => {
+ removeToast(id);
+ }, duration);
+ };
+
+ const removeToast = (id) => {
+ toasts.list = toasts.list.filter((toast) => toast.id !== id);
+ };
+
+ return {
+ addToast,
+ removeToast,
+ };
+}
diff --git a/resources/js/pages/posts/Form.vue b/resources/js/pages/posts/Form.vue
index 40c3af7..e4164d7 100644
--- a/resources/js/pages/posts/Form.vue
+++ b/resources/js/pages/posts/Form.vue
@@ -21,7 +21,6 @@ const { state: postState, fetchData: fetchPostData } = useAxiosFetch();
const { state: tagsState, fetchData: fetchTagData } = useAxiosFetch();
const searchableTags = async (q) => {
- console.log("jancok", { q });
const data = await fetchTagData(
apiBasePath(`tags/dropdown`) + `?search=${q}`,
);
@@ -38,28 +37,6 @@ const postForm = useForm("post", apiBasePath("posts"), {
tags: [],
});
-const submit = () => {
- const handleSuccess = () => {
- return router.push({ name: "posts-index" });
- };
-
- if (route.params.id) {
- postForm.submit({
- method: "put",
- url: apiBasePath(`posts/${postState.data.id}/update`),
- onSuccess() {
- return handleSuccess();
- },
- });
- } else {
- postForm.submit({
- onSuccess() {
- return handleSuccess();
- },
- });
- }
-};
-
const loadPageData = async () => {
if (route.params.id) {
await fetchPostData(apiBasePath(`posts/${route.params.id}`));
@@ -97,12 +74,33 @@ watch(
postForm.slug = slugify(val);
},
);
+
+const submit = () => {
+ const handleSuccess = () => {
+ return router.push({ name: "posts-index" });
+ };
+
+ if (route.params.id) {
+ postForm.submit({
+ method: "put",
+ url: apiBasePath(`posts/${postState.data.id}/update`),
+ onSuccess() {
+ return handleSuccess();
+ },
+ });
+ } else {
+ postForm.submit({
+ onSuccess() {
+ return handleSuccess();
+ },
+ });
+ }
+};