@paris-ias/list 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/example/.env.example +3 -0
  2. package/example/nuxt.config.ts +19 -0
  3. package/example/pages/index.vue +27 -0
  4. package/package.json +3 -3
  5. package/src/module.ts +119 -0
  6. package/src/runtime/components/events/Badges.vue +73 -0
  7. package/src/runtime/components/events/DateTimePlace.vue +77 -0
  8. package/src/runtime/components/events/DenseItem.vue +40 -0
  9. package/src/runtime/components/events/ExpandedItem.vue +11 -0
  10. package/src/runtime/components/events/ListContainer.vue +41 -0
  11. package/src/runtime/components/events/RegisterModal.vue +51 -0
  12. package/src/runtime/components/events/RelatedItem.vue +44 -0
  13. package/src/runtime/components/events/RowsItem.vue +114 -0
  14. package/src/runtime/components/events/View.vue +333 -0
  15. package/src/runtime/components/fellowships/Badges.vue +48 -0
  16. package/src/runtime/components/fellowships/DenseItem.vue +39 -0
  17. package/src/runtime/components/fellowships/ExpandedItem.vue +7 -0
  18. package/src/runtime/components/fellowships/RegisterModal.vue +41 -0
  19. package/src/runtime/components/fellowships/RowsItem.vue +61 -0
  20. package/src/runtime/components/fellowships/View.vue +210 -0
  21. package/src/runtime/components/list/atoms/FiltersMenu.vue +46 -0
  22. package/src/runtime/components/list/atoms/SearchInput.vue +129 -0
  23. package/src/runtime/components/list/atoms/SearchItem.vue +59 -0
  24. package/src/runtime/components/list/atoms/SearchString.vue +161 -0
  25. package/src/runtime/components/list/atoms/SortMenu.vue +97 -0
  26. package/src/runtime/components/list/atoms/ViewMenu.vue +71 -0
  27. package/src/runtime/components/list/inputs/AutoComplete.vue +22 -0
  28. package/src/runtime/components/list/inputs/BooleanSwitch.vue +18 -0
  29. package/src/runtime/components/list/inputs/Checkbox.vue +21 -0
  30. package/src/runtime/components/list/inputs/Select.vue +25 -0
  31. package/src/runtime/components/list/molecules/Filters.vue +97 -0
  32. package/src/runtime/components/list/molecules/Header.vue +47 -0
  33. package/src/runtime/components/list/molecules/Pagination.vue +243 -0
  34. package/src/runtime/components/list/organisms/List.vue +92 -0
  35. package/src/runtime/components/list/views/Dense.vue +25 -0
  36. package/src/runtime/components/list/views/Expanded.vue +10 -0
  37. package/src/runtime/components/list/views/Grid.vue +13 -0
  38. package/src/runtime/components/list/views/Rows.vue +13 -0
  39. package/src/runtime/components/list/views/Table.vue +13 -0
  40. package/src/runtime/components/misc/atoms/CountUp.vue +198 -0
  41. package/src/runtime/components/misc/atoms/DateStamp.vue +104 -0
  42. package/src/runtime/components/misc/atoms/ImageContainer.vue +105 -0
  43. package/src/runtime/components/misc/atoms/ShareMenu.vue +60 -0
  44. package/src/runtime/components/misc/atoms/Socials.vue +127 -0
  45. package/src/runtime/components/misc/molecules/ChipContainer.vue +35 -0
  46. package/src/runtime/components/misc/molecules/Related.vue +41 -0
  47. package/src/runtime/components/misc/molecules/RelatedItems.vue +29 -0
  48. package/src/runtime/components/misc/molecules/SearchItem.vue +26 -0
  49. package/src/runtime/components/news/DenseItem.vue +62 -0
  50. package/src/runtime/components/news/ExpandedItem.vue +153 -0
  51. package/src/runtime/components/news/Header.vue +9 -0
  52. package/src/runtime/components/news/RelatedItem.vue +44 -0
  53. package/src/runtime/components/news/RowsItem.vue +160 -0
  54. package/src/runtime/components/news/View.vue +190 -0
  55. package/src/runtime/components/people/DenseItem.vue +37 -0
  56. package/src/runtime/components/people/ExpandedItem.vue +16 -0
  57. package/src/runtime/components/people/GroupBadges.vue +56 -0
  58. package/src/runtime/components/people/RelatedItem.vue +41 -0
  59. package/src/runtime/components/people/RowsItem.vue +95 -0
  60. package/src/runtime/components/people/View.vue +162 -0
  61. package/src/runtime/components/projects/ExpandedItem.vue +14 -0
  62. package/src/runtime/components/projects/RelatedItem.vue +44 -0
  63. package/src/runtime/components/projects/RowsItem.vue +106 -0
  64. package/src/runtime/components/projects/View.vue +131 -0
  65. package/src/runtime/components/publications/RelatedItem.vue +44 -0
  66. package/src/runtime/components/publications/RowsItem.vue +105 -0
  67. package/src/runtime/components/publications/View.vue +139 -0
  68. package/src/runtime/composables/useFetchItem.ts +64 -0
  69. package/src/runtime/composables/useIcons.ts +30 -0
  70. package/src/runtime/composables/useUtils.ts +75 -0
  71. package/src/runtime/graphql/queries/buildFiltersValues.gql +35 -0
  72. package/src/runtime/graphql/queries/item/action.gql +0 -0
  73. package/src/runtime/graphql/queries/item/apps.gql +0 -0
  74. package/src/runtime/graphql/queries/item/events.gql +120 -0
  75. package/src/runtime/graphql/queries/item/fellowships.gql +164 -0
  76. package/src/runtime/graphql/queries/item/news.gql +129 -0
  77. package/src/runtime/graphql/queries/item/people.gql +174 -0
  78. package/src/runtime/graphql/queries/item/projects.gql +171 -0
  79. package/src/runtime/graphql/queries/item/publications.gql +169 -0
  80. package/src/runtime/graphql/queries/item/users.gql +0 -0
  81. package/src/runtime/graphql/queries/list/action.gql +0 -0
  82. package/src/runtime/graphql/queries/list/apps.gql +32 -0
  83. package/src/runtime/graphql/queries/list/events.gql +44 -0
  84. package/src/runtime/graphql/queries/list/fellowships.gql +53 -0
  85. package/src/runtime/graphql/queries/list/news.gql +39 -0
  86. package/src/runtime/graphql/queries/list/people.gql +49 -0
  87. package/src/runtime/graphql/queries/list/projects.gql +37 -0
  88. package/src/runtime/graphql/queries/list/publications.gql +37 -0
  89. package/src/runtime/graphql/queries/list/search.gql +148 -0
  90. package/src/runtime/graphql/queries/list/users.gql +32 -0
  91. package/src/runtime/graphql/queries/login.gql +0 -0
  92. package/src/runtime/plugins/pinia.ts +88 -0
  93. package/src/runtime/plugins/vuetify.js +21 -0
  94. package/src/runtime/stores/factory.ts +18 -0
  95. package/src/runtime/stores/root.ts +353 -0
  96. package/src/runtime/translations/en.json +436 -0
  97. package/src/runtime/translations/fr.json +429 -0
  98. package/src/runtime/types/imports.d.ts +13 -0
  99. package/src/runtime/types/stores.d.ts +11 -0
@@ -0,0 +1,148 @@
1
+ query search($appId: ID = "", $search: String = "", $lang: String = "en") {
2
+ search(appId: $appId, search: $search, lang: $lang) {
3
+ people {
4
+ items {
5
+ firstname
6
+ id
7
+ image {
8
+ alt
9
+ backgroundColor
10
+ caption
11
+ copyright
12
+ license
13
+ licenseUrl
14
+ url
15
+ }
16
+ lastname
17
+ slug
18
+ }
19
+ total
20
+ }
21
+ projects {
22
+ items {
23
+ date
24
+ id
25
+ featured
26
+ name
27
+ image {
28
+ alt
29
+ backgroundColor
30
+ caption
31
+ copyright
32
+ license
33
+ licenseUrl
34
+ url
35
+ }
36
+ subtitle
37
+ tags {
38
+ name
39
+ }
40
+ slug {
41
+ fr
42
+ en
43
+ }
44
+ }
45
+ total
46
+ }
47
+ publications {
48
+ items {
49
+ subtitle
50
+ name
51
+ image {
52
+ alt
53
+ backgroundColor
54
+ caption
55
+ copyright
56
+ licenseUrl
57
+ license
58
+ url
59
+ }
60
+ id
61
+ date
62
+ slug {
63
+ fr
64
+ en
65
+ }
66
+ }
67
+ total
68
+ }
69
+ events {
70
+ items {
71
+ availableSlots
72
+ bookingState
73
+ category
74
+ start
75
+ state
76
+ summary
77
+ eventType
78
+ slug {
79
+ fr
80
+ en
81
+ }
82
+ name
83
+ image {
84
+ alt
85
+ backgroundColor
86
+ caption
87
+ copyright
88
+ licenseUrl
89
+ license
90
+ url
91
+ }
92
+ }
93
+ total
94
+ }
95
+ fellowships {
96
+ total
97
+ items {
98
+ applicationStart
99
+ applicationStop
100
+ disciplines {
101
+ name
102
+ }
103
+ fellowshipStart
104
+ fellowshipType
105
+ fellowshipStop
106
+ id
107
+ image {
108
+ alt
109
+ backgroundColor
110
+ caption
111
+ copyright
112
+ license
113
+ licenseUrl
114
+ url
115
+ }
116
+ name
117
+ summary
118
+ slug {
119
+ fr
120
+ en
121
+ }
122
+ }
123
+ }
124
+ news {
125
+ total
126
+ items {
127
+ category
128
+ date
129
+ featured
130
+ id
131
+ image {
132
+ alt
133
+ backgroundColor
134
+ caption
135
+ copyright
136
+ license
137
+ licenseUrl
138
+ url
139
+ }
140
+ name
141
+ slug {
142
+ fr
143
+ en
144
+ }
145
+ }
146
+ }
147
+ }
148
+ }
@@ -0,0 +1,32 @@
1
+ query listUsers(
2
+ $appId: ID = "iea"
3
+ $lang: String = "en"
4
+ $options: ListInput = {}
5
+ ) {
6
+ listUsers(appId: $appId, lang: $lang, options: $options) {
7
+ items {
8
+ admin
9
+ branch
10
+ createdAt
11
+ email
12
+ profile {
13
+ country
14
+ firstname
15
+ image
16
+ lastname
17
+ linkedin
18
+ position
19
+ presentation
20
+ references
21
+ twitter
22
+ wikipedia
23
+ }
24
+ role
25
+ settings {
26
+ lang
27
+ }
28
+ status
29
+ }
30
+ total
31
+ }
32
+ }
File without changes
@@ -0,0 +1,88 @@
1
+ import { createDynamicStore } from "../stores/factory"
2
+ import type { AppConfig } from "nuxt/schema"
3
+ import { useRootStore } from "../stores/root"
4
+ const rootStore = useRootStore()
5
+ export default defineNuxtPlugin(async (nuxtApp) => {
6
+ const appConfig = useAppConfig() as AppConfig & {
7
+ list: {
8
+ modules: string[]
9
+ }
10
+ }
11
+
12
+ // Define module imports
13
+ const moduleImports = {
14
+ events: () => ({
15
+ model: import("@paris-ias/data/dist/list/events.js"),
16
+ queries: {
17
+ list: import("@paris-ias/data/graphql/queries/list/events.gql"),
18
+ get: import("@paris-ias/data/graphql/queries/item/events.gql"),
19
+ },
20
+ }),
21
+ news: () => ({
22
+ model: import("@paris-ias/data/dist/list/news.js"),
23
+ queries: {
24
+ list: import("@paris-ias/data/graphql/queries/list/news.gql"),
25
+ get: import("@paris-ias/data/graphql/queries/item/news.gql"),
26
+ },
27
+ }),
28
+ people: () => ({
29
+ model: import("@paris-ias/data/dist/list/people.js"),
30
+ queries: {
31
+ list: import("@paris-ias/data/graphql/queries/list/people.gql"),
32
+ get: import("@paris-ias/data/graphql/queries/item/people.gql"),
33
+ },
34
+ }),
35
+ projects: () => ({
36
+ model: import("@paris-ias/data/dist/list/projects.js"),
37
+ queries: {
38
+ list: import("@paris-ias/data/graphql/queries/list/projects.gql"),
39
+ get: import("@paris-ias/data/graphql/queries/item/projects.gql"),
40
+ },
41
+ }),
42
+ fellowships: () => ({
43
+ model: import("@paris-ias/data/dist/list/fellowships.js"),
44
+ queries: {
45
+ list: import("@paris-ias/data/graphql/queries/list/fellowships.gql"),
46
+ get: import("@paris-ias/data/graphql/queries/item/fellowships.gql"),
47
+ },
48
+ }),
49
+ publications: () => ({
50
+ model: import("@paris-ias/data/dist/list/publications.js"),
51
+ queries: {
52
+ list: import("@paris-ias/data/graphql/queries/list/publications.gql"),
53
+ get: import("@paris-ias/data/graphql/queries/item/publications.gql"),
54
+ },
55
+ }),
56
+
57
+ // Add other modules similarly...
58
+ }
59
+
60
+ // Initialize empty stores object
61
+ const stores: Record<string, any> = {}
62
+ const queries = {}
63
+
64
+ // Preload all required modules
65
+ await Promise.all(
66
+ appConfig.list.modules.map(async (type) => {
67
+ try {
68
+ const imports = await moduleImports[
69
+ type as keyof typeof moduleImports
70
+ ]()
71
+ const model = (await imports.model).default
72
+ queries[type] = {
73
+ list: (await imports.queries.list).default,
74
+ get: (await imports.queries.get).default,
75
+ }
76
+
77
+ stores[type] = createDynamicStore(type, { ...model, queries })()
78
+ } catch (error) {
79
+ console.error(`Failed to initialize ${type} store:`, error)
80
+ }
81
+ })
82
+ )
83
+
84
+ // Provide synchronous access to stores and queries
85
+ nuxtApp.provide("rootStore", rootStore)
86
+ nuxtApp.provide("stores", stores)
87
+ nuxtApp.provide("queries", queries)
88
+ })
@@ -0,0 +1,21 @@
1
+ import { createVuetify } from "vuetify"
2
+ import * as components from "vuetify/components"
3
+ import * as directives from "vuetify/directives"
4
+
5
+ export default defineNuxtPlugin((nuxtApp) => {
6
+ const vuetify = createVuetify({
7
+ ssr: true,
8
+ components,
9
+ directives,
10
+ mobileBreakpoint: "sm",
11
+ /* thresholds: {
12
+ xs: 0,
13
+ sm: 340,
14
+ md: 540,
15
+ lg: 800,
16
+ xl: 1280,
17
+ }, */
18
+ })
19
+
20
+ nuxtApp.vueApp.use(vuetify)
21
+ })
@@ -0,0 +1,18 @@
1
+ export const createDynamicStore = (storeName: string, moduleState: object) => {
2
+ return defineStore(storeName, () => {
3
+ const state = reactive({
4
+ loading: false,
5
+ total: 0,
6
+ skip: 0,
7
+ page: 1,
8
+ numberOfPages: 0,
9
+ search: "",
10
+ error: null as string | null,
11
+ ...moduleState,
12
+ })
13
+
14
+ return {
15
+ ...toRefs(state),
16
+ }
17
+ })
18
+ }
@@ -0,0 +1,353 @@
1
+ /* import filtersRaw from '~/assets/data/filters'
2
+ import lists from '~/assets/data/lists' */
3
+
4
+ /* import api from "~/server/api/github" */
5
+ import { defineStore } from "pinia"
6
+ import type { Views, ModuleType } from "@paris-ias/data"
7
+
8
+ import SEARCH from "../graphql/queries/list/search.gql"
9
+ export const useRootStore = defineStore("rootStore", {
10
+ state: (): Record<
11
+ string,
12
+ boolean | number | string | ModuleType | searchResults
13
+ > => ({
14
+ scrolled: import.meta.browser ? window.scrollY > 0 : false,
15
+ loading: false,
16
+ total: 0,
17
+ skip: 0,
18
+ page: 1,
19
+ numberOfPages: 0,
20
+ search: "",
21
+ results: {
22
+ events: {},
23
+ news: {},
24
+ people: {},
25
+ projects: {},
26
+ fellowships: {},
27
+ publications: {},
28
+ },
29
+ }),
30
+
31
+ actions: {
32
+ setLoading(value: boolean, type: string = "") {
33
+ const { $stores } = useNuxtApp()
34
+ this.loading = value
35
+ if (type.length) $stores[type].loading = value
36
+ },
37
+ setScrolled() {
38
+ if (import.meta.browser) {
39
+ this.scrolled = window.scrollY > 0
40
+ }
41
+ },
42
+ loadRouteQuery(type: string) {
43
+ const { currentRoute } = useRouter()
44
+ const { $stores } = useNuxtApp()
45
+ const query = currentRoute.value.query
46
+ if (Object.keys(query)?.length) {
47
+ Object.keys(query).forEach((filter) => {
48
+ if (Object.keys($stores[type].filters).includes(filter))
49
+ $stores[type].filters[filter].value = (this[type] as ModuleType)
50
+ .list.filters[filter].multiple
51
+ ? JSON.parse(query[filter] as string)
52
+ : query[filter]
53
+ })
54
+ /* if (query.view) {
55
+ ;$stores[type].view = query.view as
56
+ | string
57
+ | Views
58
+ | undefined
59
+ }
60
+ if (query.page) {
61
+ this.page = +query.page
62
+ } else {
63
+ this.page = 1
64
+ } */
65
+
66
+ /* const sortObj = $stores[type].sort
67
+ const defaultSortKey = Object.keys(sortObj).find(
68
+ (item) => sortObj[item].default === true,
69
+ )
70
+ const defaultSort = [sortObj[defaultSortKey as string]]
71
+
72
+ const sortDesc = $stores[type].sortDesc
73
+ let sortDescItem
74
+ sortDescItem = (sortDesc as number[] | boolean[])[0]
75
+
76
+ if (query.sortBy) {
77
+ ;$stores[type].sortBy = [query.sortBy] as string[]
78
+ }
79
+ if (typeof query.sortDesc !== "undefined") {
80
+ sortDescItem = !!(query.sortDesc === "true")
81
+ } else {
82
+ sortDescItem = defaultSort[0].value[1]
83
+ } */
84
+ }
85
+ console.log("query loaded")
86
+ },
87
+
88
+ setFiltersCount(type: string) {
89
+ const { $stores } = useNuxtApp()
90
+ let filtersCount = 0 as number
91
+ Object.keys($stores[type].filters)
92
+ // remove empty values
93
+ .forEach((filter) => {
94
+ /*console.log("filter: ", filter)
95
+ console.log("filters[filter]?.value: ", filters[filter].value)
96
+ */ /* console.log(
97
+ 'typeof filters[filter]?.value !== "undefined": ',
98
+ typeof filters[filter]?.value !== "undefined",
99
+ ) */
100
+ if (
101
+ $stores[type].filters[filter]?.value?.length &&
102
+ typeof $stores[type].filters[filter]?.value !== "undefined"
103
+ ) {
104
+ filtersCount++
105
+ }
106
+ return filtersCount
107
+ })
108
+
109
+ $stores[type].filtersCount = filtersCount
110
+ },
111
+ setBlankFilterLoad(type: string) {
112
+ /* ;(this[type] as ModuleType).loading = false */
113
+ },
114
+ setDefaults() {
115
+ // lang
116
+ const lang = localStorage.getItem("lang")
117
+ /* if(lang)i18n.global.locale = lang; */
118
+ // dark mode
119
+
120
+ // event
121
+ // people
122
+ // news
123
+ // project
124
+ // fellowships
125
+ },
126
+ updateRouteQuery(type: string) {
127
+ const router = useRouter()
128
+ const { $stores } = useNuxtApp()
129
+ // update route
130
+ const routeQuery: Record<string, string> = {
131
+ // Add search if it exists and is defined
132
+ ...(this.search ? { search: this.search } : {}),
133
+
134
+ // Add page if it's greater than 1
135
+ ...(this.page > 1 ? { page: this.page.toString() } : {}),
136
+
137
+ // Add filters with defined values
138
+ ...Object.entries($stores[type].filters).reduce(
139
+ (acc, [filterKey, filter]) => {
140
+ if (!$stores[type].filters[filterKey]?.value) {
141
+ return acc
142
+ }
143
+ return {
144
+ ...acc,
145
+ ...{
146
+ [filterKey]: $stores[type].filters[filterKey]?.value,
147
+ },
148
+ }
149
+ },
150
+ {} as Record<string, string>
151
+ ),
152
+ }
153
+ router.replace({ query: routeQuery })
154
+ },
155
+ resetState() {
156
+ const { $stores } = useNuxtApp()
157
+ console.log("resetState")
158
+ this.search = ""
159
+ this.page = 1
160
+ this.scrolled = false
161
+ this.loading = false
162
+ this.total = 0
163
+ this.skip = 0
164
+ this.numberOfPages = 0
165
+ const modules = [
166
+ "events",
167
+ "news",
168
+ "people",
169
+ "projects",
170
+ "fellowships",
171
+ "publications",
172
+ ]
173
+ /* this.events.list.filters = events.list.filters
174
+ this.news.list.filters = news.list.filters
175
+ this.people.list.filters = people.list.filters
176
+ this.projects.list.filters = projects.list.filters
177
+ this.fellowships.list.filters = fellowships.list.filters
178
+ this.publications.list.filters = publications.list.filters */
179
+ modules.forEach((type) => {
180
+ /* const viewsObj = $stores[type].views as Record<
181
+ string,
182
+ Views
183
+ >
184
+ const defaultViewsKey = Object.keys(viewsObj).find(
185
+ (item) => viewsObj[item].default === true
186
+ )
187
+ const defaultView = viewsObj[defaultViewsKey as string]
188
+
189
+ const sortObj = $stores[type].sort
190
+ const defaultSortKey = Object.keys(sortObj).find(
191
+ (item) => sortObj[item].default === true
192
+ )
193
+ const defaultSort = sortObj[defaultSortKey as string] */
194
+ /*
195
+ // TODO make dynamic based on an ~/assets located file
196
+ ;$stores[type].view = defaultView
197
+ ;$stores[type].sortBy = [defaultSort.value[0]]
198
+ ;$stores[type].sortDesc = [defaultSort.value[1]] */
199
+ })
200
+ },
201
+ updateSort({ value, type }: { value: number[] | string[]; type: string }) {
202
+ const { $stores } = useNuxtApp()
203
+ $stores[type].sortBy = [value[0]] as string[]
204
+ $stores[type].sortDesc = [value[1]] as number[]
205
+ this.page = 1
206
+ this.updateLocalStorage(type + "_sort", value.join("_"))
207
+ this.update(type)
208
+ },
209
+ updateView({ value, type }: { value: string; type: string }) {
210
+ const { $stores } = useNuxtApp()
211
+ $stores[type].view = {
212
+ ...($stores[type].views[value] as Views),
213
+ name: value,
214
+ }
215
+ this.updateLocalStorage(type + "_view", value)
216
+ this.update(type)
217
+ },
218
+ updateLocalStorage(key: string, value: string) {
219
+ const local = JSON.parse(localStorage.getItem("PARIS_IAS") as any) || {}
220
+ local[key] = value
221
+ localStorage.setItem("PARIS_IAS", JSON.stringify(local))
222
+ },
223
+ updateFilter(key: string, val: any, type: string) {
224
+ const { $stores } = useNuxtApp()
225
+ console.log("update filter: ", { key, val, type })
226
+
227
+ if (["online", "outside", "past"].includes(key) && val === false) {
228
+ $stores[type].filters[key].value = null
229
+ } else {
230
+ $stores[type].filters[key].value = val
231
+ }
232
+
233
+ this.updatePage({ page: 1, type })
234
+ },
235
+ updateItemsPerPage({ value, type }: { value: number; type: string }) {
236
+ const { $stores } = useNuxtApp()
237
+ this.page = 1
238
+ $stores[types].itemsPerPage = value
239
+
240
+ this.update(type)
241
+ },
242
+ updatePage({ page, type }: { page: number; type: string }) {
243
+ this.page = page
244
+ this.update(type)
245
+ },
246
+ async updateSearch({
247
+ type = "all",
248
+ search = "",
249
+ lang = "en",
250
+ }: {
251
+ type: string
252
+ search: string
253
+ lang: string
254
+ }) {
255
+ this.search = search
256
+ /* console.log("updateSearch: ", search + " " + lang) */
257
+ this.setLoading(true)
258
+
259
+ await this.update(type, lang)
260
+ },
261
+
262
+ async update(type: string, lang: string = "en") {
263
+ const { $stores } = useNuxtApp()
264
+ this.setLoading(true)
265
+ if (type !== "all") {
266
+ $stores[type].loading = true
267
+ }
268
+
269
+ // fetch the item categories
270
+
271
+ const itemsPerPage =
272
+ type === "all" ? 3 : ($stores[type]?.itemsPerPage as number)
273
+ const filters: Record<string, any> = {}
274
+
275
+ if (type !== "all") {
276
+ for (const filter in $stores[type].filters) {
277
+ const filterValue = $stores[type].filters[filter]?.value
278
+
279
+ // Prune empty values
280
+ if (typeof filterValue !== "undefined" && filterValue?.length) {
281
+ filters[filter] = filterValue
282
+ }
283
+ }
284
+ }
285
+
286
+ const args = JSON.parse(
287
+ JSON.stringify({
288
+ options: {
289
+ // skip
290
+ skip: +this.page === 1 ? 0 : (+this.page - 1) * itemsPerPage,
291
+ // limit
292
+ limit: itemsPerPage,
293
+ // sort, array of keys and array of directions - to have x tie breakers if necessary
294
+ sortBy: type === "all" ? "searchScore" : $stores[type].sortBy,
295
+ sortDesc:
296
+ type === "all" ? -1 : $stores[type].sortDesc > 0 ? true : false,
297
+ // search (if set)
298
+ ...((this.search as string)?.length &&
299
+ type !== "all" && { search: this.search }),
300
+ // add the store module filters
301
+ filters,
302
+ },
303
+ ...((this.search as string)?.length &&
304
+ type === "all" && { search: this.search }),
305
+ appId: "iea",
306
+ lang,
307
+ })
308
+ )
309
+ args.options.filters = JSON.stringify(args.options.filters)
310
+ let result: any = {}
311
+ console.log("args: ", args)
312
+
313
+ console.log(`Fetching ${type}`)
314
+ const { $queries } = useNuxtApp()
315
+ const { data, error } = await useAsyncQuery(
316
+ type === "all" ? SEARCH : $queries[type].list,
317
+ args
318
+ )
319
+ /* console.log("data: ", data) */
320
+ if (error.value) console.log(error.value)
321
+ const key =
322
+ type === "all"
323
+ ? "search"
324
+ : "list" + type.charAt(0).toUpperCase() + type.slice(1)
325
+
326
+ if (type === "all") {
327
+ this.results = data?.value?.[key]
328
+ } else {
329
+ const items = data?.value?.[key]?.items ?? []
330
+ this.total = data?.value?.[key]?.total
331
+ result = {
332
+ ...data?.value?.[key],
333
+ items: items.map(({ id, ...rest }) => ({
334
+ ...rest,
335
+ _path: `/${id}`,
336
+ })),
337
+ }
338
+ $stores[type].items = result["items"]
339
+
340
+ const lastPage = Math.ceil(result.total / itemsPerPage)
341
+ /* this.updateRouteQuery(type) */
342
+ this.setFiltersCount(type)
343
+ this.setBlankFilterLoad(type)
344
+ /* console.log("type2: ", type) */
345
+ $stores[type].numberOfPages = lastPage
346
+ }
347
+ /* console.log("this.total: ", this.total)
348
+ */
349
+ this.setLoading(false, type)
350
+ return true
351
+ },
352
+ },
353
+ })