designtopack/src/stores/projects.js

52 lines
1.3 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);
const projects = ref(null);
2024-09-10 08:49:09 +02:00
2024-09-10 09:12:52 +02:00
const currentProjects = computed(() => {
2025-10-08 14:53:09 +02:00
return (
projects.value
2025-10-08 15:01:08 +02:00
?.filter((project) => project.status === 'listed')
.sort((a, b) => new Date(b.modified) - new Date(a.modified)) ?? []
2025-10-08 14:53:09 +02:00
);
2024-09-10 09:12:52 +02:00
});
2025-02-11 17:30:26 +01:00
const draftProjects = computed(() => {
2025-02-11 17:30:26 +01:00
return projects.value
.filter((project) => project.status === 'draft')
.sort((a, b) => new Date(b.modified) - new Date(a.modified));
});
2025-02-11 17:30:26 +01:00
2024-09-10 09:12:52 +02:00
const archivedProjects = computed(() => {
2025-02-11 17:30:26 +01:00
return projects.value
.filter((project) => project.status === 'unlisted')
.sort((a, b) => new Date(b.modified) - new Date(a.modified));
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) => {
2025-05-14 17:12:20 +02:00
// setTimeout(() => {
2025-05-14 17:27:26 +02:00
isProjectsLoading.value = false;
2025-02-05 11:52:54 +01:00
projects.value = json.page.children;
2025-05-14 17:12:20 +02:00
// }, 3000);
2025-02-05 11:52:54 +01:00
});
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
});