Add (new post)
This commit is contained in:
53
resources/js/stores/postStore.js
Normal file
53
resources/js/stores/postStore.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import { defineStore } from "pinia";
|
||||
|
||||
import route from "ziggy-js/src/js/index";
|
||||
|
||||
import axios from "axios";
|
||||
|
||||
export const usePostStore = defineStore("postStore", {
|
||||
state: () => ({
|
||||
data: {
|
||||
defaultLocaleSlug: "my",
|
||||
countryLocales: [],
|
||||
localeCategories: [],
|
||||
},
|
||||
}),
|
||||
getters: {
|
||||
defaultLocaleSlug(state) {
|
||||
return state.data.defaultLocaleSlug;
|
||||
},
|
||||
countryLocales(state) {
|
||||
return state.data.countryLocales;
|
||||
},
|
||||
localeCategories(state) {
|
||||
return state.data.localeCategories;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
async fetchCountryLocales() {
|
||||
try {
|
||||
const response = await axios.get(route("api.admin.country-locales"));
|
||||
console.log(response);
|
||||
this.data.countryLocales = response.data.country_locales;
|
||||
this.data.defaultLocaleSlug = response.data.default_locale_slug;
|
||||
} catch (error) {
|
||||
// alert(error);
|
||||
console.log(error);
|
||||
}
|
||||
},
|
||||
async fetchLocaleCategories(countryLocaleSlug) {
|
||||
try {
|
||||
const response = await axios.get(
|
||||
route("api.admin.categories", {
|
||||
country_locale_slug: countryLocaleSlug,
|
||||
})
|
||||
);
|
||||
console.log(response);
|
||||
this.data.localeCategories = response.data.categories;
|
||||
} catch (error) {
|
||||
// alert(error);
|
||||
console.log(error);
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user