36 lines
978 B
JavaScript
36 lines
978 B
JavaScript
import { defineStore } from "pinia";
|
|
import { useApiStore } from "./api.js";
|
|
import { ref, computed } from "vue";
|
|
|
|
export const useProjectsStore = defineStore("projects", () => {
|
|
const projects = ref([]);
|
|
|
|
const currentProjects = computed(() => {
|
|
return projects.value.filter((project) => project.status === "listed");
|
|
});
|
|
const draftProjects = computed(() => {
|
|
return projects.value.filter((project) => project.status === "draft");
|
|
});
|
|
const archivedProjects = computed(() => {
|
|
return projects.value.filter((project) => project.status === "unlisted");
|
|
});
|
|
|
|
const api = useApiStore();
|
|
api
|
|
.fetchData("projects")
|
|
.then((json) => (projects.value = json.page.children));
|
|
|
|
// Functions
|
|
function getProjectByUuid(uuid) {
|
|
const project = projects.value.find((project) => project.uuid === uuid);
|
|
return project;
|
|
}
|
|
|
|
return {
|
|
projects,
|
|
currentProjects,
|
|
archivedProjects,
|
|
draftProjects,
|
|
getProjectByUuid,
|
|
};
|
|
});
|