PluginProbe
Extendify / 0.4.0
Extendify v0.4.0
3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 0.7.0 All 126 releases
extendify / src / api / Templates.js

Templates.js in Extendify 0.4.0, at src/api/Templates.js

70 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Axios as api } from './axios'
2 import { useUserStore } from '../state/User'
3
4 let count = 0
5
6 export const Templates = {
7 async get(searchParams, options = {}) {
8 count++
9 const defaultpageSize = searchParams.type === 'pattern' ? '8' : '4'
10 const taxonomyType =
11 searchParams.type === 'pattern' ? 'patternType' : 'layoutType'
12 const args = Object.assign(
13 {
14 filterByFormula: prepareFilterFormula(
15 searchParams,
16 taxonomyType,
17 ),
18 pageSize: defaultpageSize,
19 categories: searchParams.taxonomies,
20 search: searchParams.search,
21 type: searchParams.type,
22 offset: '',
23 initial: count === 1,
24 request_count: count,
25 sdk_partner: useUserStore.getState()?.sdkPartner ?? '',
26 },
27 options,
28 )
29 return await api.post('templates', args)
30 },
31
32 // TODO: Refactor this later to combine the following three
33 maybeImport(template) {
34 return api.post(`templates/${template.id}`, {
35 template_id: template?.id,
36 maybe_import: true,
37 type: template.fields?.type,
38 pageSize: '1',
39 template_name: template.fields?.title,
40 })
41 },
42 import(template) {
43 return api.post(`templates/${template.id}`, {
44 template_id: template.id,
45 imported: true,
46 basePattern:
47 template.fields?.basePattern ??
48 template.fields?.baseLayout ??
49 '',
50 type: template.fields.type,
51 pageSize: '1',
52 template_name: template.fields?.title,
53 })
54 },
55 }
56
57 const prepareFilterFormula = ({ taxonomies }, type) => {
58 const siteType = taxonomies?.siteType?.slug?.length
59 ? taxonomies.siteType.slug
60 : 'default'
61 const formula = [
62 `{type}="${type.replace('Type', '')}"`,
63 `{siteType}="${siteType}"`,
64 ]
65 if (taxonomies[type]?.slug) {
66 formula.push(`{${type}}="${taxonomies[type].slug}"`)
67 }
68 return `AND(${formula.join(', ')})`.replace(/\r?\n|\r/g, '')
69 }
70