designtopack/src/stores/projects.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

2025-02-05 11:52:54 +01:00
import { defineStore } from 'pinia';
import { useApiStore } from './api.js';
import { ref, computed } from 'vue';
2024-09-10 08:49:09 +02:00
2025-02-05 11:52:54 +01:00
export const useProjectsStore = defineStore('projects', () => {
const isProjectsLoading = ref(true);
2024-09-10 08:49:09 +02:00
const projects = ref([]);
2024-09-10 09:12:52 +02:00
const currentProjects = computed(() => {
2025-02-05 11:52:54 +01:00
return projects.value.filter((project) => project.status === 'listed');
2024-09-10 09:12:52 +02:00
});
const draftProjects = computed(() => {
2025-02-05 11:52:54 +01:00
return projects.value.filter((project) => project.status === 'draft');
});
2024-09-10 09:12:52 +02:00
const archivedProjects = computed(() => {
2025-02-05 11:52:54 +01:00
return projects.value.filter((project) => project.status === 'unlisted');
2024-09-10 09:12:52 +02:00
});
2024-09-10 08:49:09 +02:00
const api = useApiStore();
2025-02-05 11:52:54 +01:00
api.fetchData('projects').then((json) => {
isProjectsLoading.value = false;
projects.value = json.page.children;
});
2024-09-10 08:49:09 +02:00
// Functions
function getProjectByUuid(uuid) {
const project = projects.value.find((project) => project.uuid === uuid);
return project;
}
return {
projects,
currentProjects,
archivedProjects,
draftProjects,
getProjectByUuid,
2025-02-05 11:52:54 +01:00
isProjectsLoading,
};
2024-09-10 08:49:09 +02:00
});