favorites and other should be done?
This commit is contained in:
33
nginx/vue/src/stores/activity.js
Normal file
33
nginx/vue/src/stores/activity.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, ref } from "vue";
|
||||
import axios from "axios";
|
||||
|
||||
const activity_template = {
|
||||
type: "activity",
|
||||
name: "nameof",
|
||||
createdAt: Date.now(),
|
||||
};
|
||||
|
||||
export const useActivityStore = defineStore("activity", () => {
|
||||
const activity = ref([activity_template]);
|
||||
|
||||
const activityCount = computed(() => activity.value.length);
|
||||
|
||||
async function fetchActivity() {
|
||||
try {
|
||||
const res = await axios.get("/api/activity");
|
||||
if (!Array.isArray(res.data)) {
|
||||
throw new Error("Invalid response from posts API");
|
||||
}
|
||||
activity.value = res.data;
|
||||
} catch (err) {
|
||||
console.error("Cannot connect to activity API", err);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
activity,
|
||||
activityCount,
|
||||
fetchActivity,
|
||||
};
|
||||
});
|
||||
33
nginx/vue/src/stores/favorites.js
Normal file
33
nginx/vue/src/stores/favorites.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, ref } from "vue";
|
||||
import axios from "axios";
|
||||
|
||||
const favorite_template = {
|
||||
type: "favorite",
|
||||
name: "nameof",
|
||||
createdAt: Date.now(),
|
||||
};
|
||||
|
||||
export const useFavoritesStore = defineStore("favorites", () => {
|
||||
const favorites = ref([favorite_template]);
|
||||
|
||||
const favoritesCount = computed(() => favorites.value.length);
|
||||
|
||||
async function fetchFavorites() {
|
||||
try {
|
||||
const res = await axios.get("/api/favorites");
|
||||
if (!Array.isArray(res.data)) {
|
||||
throw new Error("Invalid response from favorites API");
|
||||
}
|
||||
favorites.value = res.data;
|
||||
} catch (err) {
|
||||
console.error("Cannot connect to favorites API", err);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
favorites,
|
||||
favoritesCount,
|
||||
fetchFavorites,
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user