summaryrefslogtreecommitdiff
path: root/store
diff options
context:
space:
mode:
Diffstat (limited to 'store')
-rw-r--r--store/index.js4
-rw-r--r--store/models.js53
2 files changed, 55 insertions, 2 deletions
diff --git a/store/index.js b/store/index.js
index eabe2e5..a91e3a7 100644
--- a/store/index.js
+++ b/store/index.js
@@ -3,8 +3,8 @@ export const state = () => ({
});
export const getters = {
- animation: (state) => {
- return state.loading ? "animate-none" : "animate-spin";
+ isLoading: (state) => {
+ return state.loading;
},
};
export const mutations = {
diff --git a/store/models.js b/store/models.js
new file mode 100644
index 0000000..b1b0b95
--- /dev/null
+++ b/store/models.js
@@ -0,0 +1,53 @@
+export const state = () => ({
+ models: [],
+ count: 0,
+});
+
+export const getters = {
+ models: (state) => {
+ return state.models;
+ },
+ count: (state) => {
+ return state.count;
+ },
+};
+
+export const mutations = {
+ // Save results and count
+ saveModels: (state, value) => {
+ state.models = value.results;
+ state.count = value.count;
+ },
+};
+
+export const actions = {
+ // Get models usign `page`
+ async getModels({ commit, getters }, page) {
+ commit("loadingStatus", true, { root: true });
+ let res = { status: 0, data: null };
+ let api = this.$config.api;
+
+ page = page ? page : 1;
+
+ await fetch(`${api}/v1/models?page=${page}`, {
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${getters.accessToken}`,
+ },
+ })
+ .then(async (response) => {
+ res.data = await response.json();
+ res.status = response.status;
+ if (res.status == 200) {
+ commit("saveModels", res.data);
+ }
+ })
+ .catch((e) => {
+ res.status = e.status;
+ });
+
+ commit("loadingStatus", false, { root: true });
+
+ return res;
+ },
+};