opnform/client/stores/templates.js

58 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-12-16 18:21:03 +00:00
import {defineStore} from 'pinia'
import {useContentStore} from "~/composables/stores/useContentStore.js";
2023-12-19 14:24:54 +00:00
import templateTypes from "~/data/forms/templates/types.json"
import industryTypes from "~/data/forms/templates/industries.json"
2023-12-09 14:47:03 +00:00
const templatesEndpoint = 'templates'
export const useTemplatesStore = defineStore('templates', () => {
const contentStore = useContentStore('slug')
2023-12-09 14:47:03 +00:00
const allLoaded = ref(false)
2023-12-19 14:24:54 +00:00
const industries = ref(new Map)
const types = ref(new Map)
const getTemplateTypes = (slugs) => {
return slugs.map((slug) => {
return types.value.get(slug)
}).filter((item) => item !== undefined)
}
const getTemplateIndustries =(slugs) => {
return slugs.map((slug) => {
return industries.value.get(slug)
}).filter((item) => item !== undefined)
}
const initTypesAndIndustries = () => {
if (types.value.size === 0) {
types.value = new Map(Object.entries(templateTypes))
}
if (industries.value.size === 0) {
industries.value = new Map(Object.entries(industryTypes))
2023-12-09 14:47:03 +00:00
}
}
return {
...contentStore,
industries,
types,
getTemplateTypes,
getTemplateIndustries,
2023-12-19 14:24:54 +00:00
initTypesAndIndustries
}
2023-12-09 14:47:03 +00:00
})
export const fetchTemplate = (slug) => {
return useOpnApi(templatesEndpoint + '/' + slug)
}
export const fetchAllTemplates = () => {
return useOpnApi(templatesEndpoint)
}
2023-12-19 14:24:54 +00:00
export const loadTypesAndIndustries = () => {
// Load the json files
}