opnform/client/components/pages/templates/TemplatesList.vue

175 lines
5.6 KiB
Vue
Raw Normal View History

2023-12-09 14:47:03 +00:00
<template>
<div>
<section class="bg-white py-12">
<div class="px-4 sm:px-6 lg:px-8 max-w-7xl mx-auto">
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 sm:gap-6 relative z-20">
<div class="flex items-center gap-4">
<div class="flex-1 sm:flex-none">
<select-input v-model="selectedType" name="type"
:options="typesOptions" class="w-full sm:w-auto md:w-56"
/>
</div>
<div class="flex-1 sm:flex-none">
<select-input v-model="selectedIndustry" name="industry"
:options="industriesOptions" class="w-full sm:w-auto md:w-56"
/>
</div>
</div>
<div class="flex-1 w-full md:max-w-xs">
2023-12-19 14:24:54 +00:00
<text-input autocomplete="off" name="search" v-model="search" placeholder="Search..."/>
2023-12-09 14:47:03 +00:00
</div>
</div>
<div v-if="loading" class="text-center mt-4">
2023-12-18 09:35:00 +00:00
<Loader class="h-6 w-6 text-nt-blue mx-auto"/>
2023-12-09 14:47:03 +00:00
</div>
<p v-else-if="enrichedTemplates.length === 0" class="text-center mt-4">
No templates found.
</p>
<div v-else class="relative z-10">
<div class="grid grid-cols-1 mt-8 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-8 sm:gap-y-12">
2023-12-18 09:35:00 +00:00
<single-template v-for="template in enrichedTemplates" :key="template.id" :template="template"/>
2023-12-09 14:47:03 +00:00
</div>
</div>
</div>
</section>
2023-12-18 09:35:00 +00:00
<section class="py-12 bg-white border-t border-gray-200 sm:py-16">
<div class="px-4 mx-auto sm:px-6 lg:px-8 max-w-7xl">
<div class="flex items-center justify-between">
<h4 class="text-xl font-bold tracking-tight text-gray-900 sm:text-2xl">
All Types
</h4>
2023-12-09 14:47:03 +00:00
</div>
2023-12-18 09:35:00 +00:00
<div class="grid grid-cols-1 gap-8 mt-8 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
<router-link v-for="row in types" :key="row.slug"
2023-12-19 14:24:54 +00:00
:to="{params: {slug:row.slug}, name:'templates-types-slug'}"
2023-12-18 09:35:00 +00:00
:title="row.name"
class="text-gray-600 dark:text-gray-400 transition-colors duration-300 hover:text-nt-blue"
>
{{ row.name }}
</router-link>
2023-12-09 14:47:03 +00:00
</div>
2023-12-18 09:35:00 +00:00
</div>
</section>
<section class="py-12 bg-white border-t border-gray-200 sm:py-16">
<div class="px-4 mx-auto sm:px-6 lg:px-8 max-w-7xl">
<div class="flex items-center justify-between">
<h4 class="text-xl font-bold tracking-tight text-gray-900 sm:text-2xl">
All Industries
</h4>
</div>
<div class="grid grid-cols-1 gap-8 mt-8 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
<router-link v-for="row in industries" :key="row.slug"
2023-12-19 14:24:54 +00:00
:to="{params:{slug:row.slug}, name:'templates-industries-slug'}"
2023-12-18 09:35:00 +00:00
:title="row.name"
class="text-gray-600 dark:text-gray-400 transition-colors duration-300 hover:text-nt-blue"
>
{{ row.name }}
</router-link>
</div>
</div>
</section>
2023-12-09 14:47:03 +00:00
</div>
</template>
<script>
2023-12-18 09:35:00 +00:00
import {computed} from 'vue'
2023-12-09 14:47:03 +00:00
import Fuse from 'fuse.js'
import SingleTemplate from './SingleTemplate.vue'
2023-12-19 14:24:54 +00:00
import {refThrottled} from "@vueuse/core";
2023-12-09 14:47:03 +00:00
export default {
name: 'TemplatesList',
2023-12-18 09:35:00 +00:00
components: {SingleTemplate},
2023-12-09 14:47:03 +00:00
props: {
2023-12-18 09:35:00 +00:00
templates: {
type: Array,
required: true
},
loading: {
2023-12-09 14:47:03 +00:00
type: Boolean,
2023-12-18 09:35:00 +00:00
default: false
2023-12-09 14:47:03 +00:00
}
},
2023-12-18 09:35:00 +00:00
setup() {
2023-12-09 14:47:03 +00:00
const authStore = useAuthStore()
const templatesStore = useTemplatesStore()
2023-12-19 14:24:54 +00:00
const search = ref('')
const throttledSearch = refThrottled(search, 1000)
2023-12-09 14:47:03 +00:00
return {
2023-12-19 14:24:54 +00:00
search,
throttledSearch,
2023-12-18 09:35:00 +00:00
user: computed(() => authStore.user),
2023-12-19 14:24:54 +00:00
industries: computed(() => [...templatesStore.industries.values()]),
types: computed(() => [...templatesStore.types.values()])
2023-12-09 14:47:03 +00:00
}
},
data: () => ({
selectedType: 'all',
selectedIndustry: 'all',
}),
computed: {
2023-12-18 09:35:00 +00:00
industriesOptions() {
return [{name: 'All Industries', value: 'all'}].concat(Object.values(this.industries).map((industry) => {
2023-12-09 14:47:03 +00:00
return {
name: industry.name,
value: industry.slug
}
}))
},
2023-12-18 09:35:00 +00:00
typesOptions() {
return [{name: 'All Types', value: 'all'}].concat(Object.values(this.types).map((type) => {
2023-12-09 14:47:03 +00:00
return {
name: type.name,
value: type.slug
}
}))
},
2023-12-18 09:35:00 +00:00
enrichedTemplates() {
let enrichedTemplates = this.templates
2023-12-09 14:47:03 +00:00
// Filter by Selected Type
if (this.selectedType && this.selectedType !== 'all') {
enrichedTemplates = enrichedTemplates.filter((item) => {
return (item.types && item.types.length > 0) ? item.types.includes(this.selectedType) : false
})
}
// Filter by Selected Industry
if (this.selectedIndustry && this.selectedIndustry !== 'all') {
enrichedTemplates = enrichedTemplates.filter((item) => {
return (item.industries && item.industries.length > 0) ? item.industries.includes(this.selectedIndustry) : false
})
}
2023-12-19 14:24:54 +00:00
console.log(this.throttledSearch, '---inode')
if (!this.throttledSearch || this.throttledSearch === '' || this.throttledSearch === null) {
2023-12-09 14:47:03 +00:00
return enrichedTemplates
}
// Fuze search
const fuzeOptions = {
keys: [
'name',
'slug',
'description',
'short_description'
]
}
const fuse = new Fuse(enrichedTemplates, fuzeOptions)
2023-12-19 14:24:54 +00:00
return fuse.search(this.throttledSearch).map((res) => {
2023-12-09 14:47:03 +00:00
return res.item
})
}
},
}
</script>