@paris-ias/list 1.0.58 → 1.0.60

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.
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@paris-ias/list",
3
3
  "configKey": "list",
4
- "version": "1.0.58",
4
+ "version": "1.0.60",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.0",
7
7
  "unbuild": "3.5.0"
@@ -9,7 +9,7 @@
9
9
  icon
10
10
  class="ml-auto"
11
11
  v-bind="tooltip"
12
- @click="rootStore.resetState()"
12
+ @click="rootStore.resetState(type)"
13
13
  >
14
14
  <v-icon>mdi-restore</v-icon>
15
15
  </v-btn>
@@ -19,7 +19,7 @@
19
19
  </template>
20
20
 
21
21
  <script setup>
22
- import { useNuxtApp } from "#imports";
22
+ import { useNuxtApp, onMounted } from "#imports";
23
23
  import { useRootStore } from "../../../stores/root";
24
24
  const { $stores } = useNuxtApp();
25
25
  const rootStore = useRootStore();
@@ -8,7 +8,7 @@ export declare const useRootStore: import("pinia").StoreDefinition<"rootStore",
8
8
  setBlankFilterLoad(type: string): void;
9
9
  setDefaults(): void;
10
10
  updateRouteQuery(type: string): void;
11
- resetState(): void;
11
+ resetState(type: string): void;
12
12
  updateSort({ value, type }: {
13
13
  value: number[] | string[];
14
14
  type: string;
@@ -20,31 +20,31 @@ export const useRootStore = defineStore("rootStore", {
20
20
  }
21
21
  }),
22
22
  actions: {
23
- setLoading(value, type2 = "") {
23
+ setLoading(value, type = "") {
24
24
  const { $stores } = useNuxtApp();
25
25
  this.loading = value;
26
- if (type2.length) $stores[type2].loading = value;
26
+ if (type.length) $stores[type].loading = value;
27
27
  },
28
28
  setScrolled() {
29
29
  if (import.meta.browser) {
30
30
  this.scrolled = window.scrollY > 0;
31
31
  }
32
32
  },
33
- saveFiltersToLocalStorage(type2) {
33
+ saveFiltersToLocalStorage(type) {
34
34
  const { $stores } = useNuxtApp();
35
- const filters = $stores[type2].filters ?? {};
35
+ const filters = $stores[type].filters ?? {};
36
36
  const values = Object.fromEntries(
37
37
  Object.entries(filters).map(([key, filter]) => [key, filter.value])
38
38
  );
39
39
  const local = JSON.parse(localStorage.getItem("PARIS_IAS") || "{}");
40
- local[`${type2}_filters`] = values;
40
+ local[`${type}_filters`] = values;
41
41
  localStorage.setItem("PARIS_IAS", JSON.stringify(local));
42
42
  },
43
- loadRouteQuery(type2) {
43
+ loadRouteQuery(type) {
44
44
  const { $stores } = useNuxtApp();
45
45
  const { currentRoute } = useRouter();
46
46
  const query = currentRoute.value.query;
47
- const filters = $stores[type2].filters;
47
+ const filters = $stores[type].filters;
48
48
  if (Object.keys(query)?.length) {
49
49
  Object.keys(query).forEach((filter) => {
50
50
  if (filter in filters) {
@@ -53,48 +53,48 @@ export const useRootStore = defineStore("rootStore", {
53
53
  });
54
54
  }
55
55
  console.log("query loaded");
56
- this.setFiltersCount(type2);
56
+ this.setFiltersCount(type);
57
57
  },
58
- loadFiltersFromLocalStorage(type2) {
58
+ loadFiltersFromLocalStorage(type) {
59
59
  const { $stores } = useNuxtApp();
60
60
  const local = JSON.parse(localStorage.getItem("PARIS_IAS") || "{}");
61
- const saved = local[`${type2}_filters`] ?? null;
61
+ const saved = local[`${type}_filters`] ?? null;
62
62
  if (!saved) {
63
- console.log(`[${type2}] Aucune donn\xE9e \xE0 restaurer.`);
63
+ console.log(`[${type}] Aucune donn\xE9e \xE0 restaurer.`);
64
64
  return;
65
65
  }
66
- const filters = $stores[type2].filters ?? {};
66
+ const filters = $stores[type].filters ?? {};
67
67
  for (const [key, value] of Object.entries(saved)) {
68
68
  if (filters[key]) {
69
69
  filters[key].value = value;
70
70
  }
71
71
  }
72
- this.setFiltersCount(type2);
73
- this.updateRouteQuery(type2);
74
- console.log(`[${type2}] Filtres restaur\xE9s depuis localStorage`, saved);
72
+ this.setFiltersCount(type);
73
+ this.updateRouteQuery(type);
74
+ console.log(`[${type}] Filtres restaur\xE9s depuis localStorage`, saved);
75
75
  },
76
- setFiltersCount(type2) {
76
+ setFiltersCount(type) {
77
77
  const { $stores } = useNuxtApp();
78
- const filters = $stores[type2].filters ?? {};
78
+ const filters = $stores[type].filters ?? {};
79
79
  const count = Object.values(filters).reduce((acc, filter) => {
80
80
  const value = filter?.value;
81
81
  const isEmpty = value === void 0 || value === null || Array.isArray(value) && value.length === 0 || typeof value === "string" && value.trim() === "";
82
82
  return isEmpty ? acc : acc + 1;
83
83
  }, 0);
84
- $stores[type2].filtersCount = count;
84
+ $stores[type].filtersCount = count;
85
85
  },
86
- setBlankFilterLoad(type2) {
86
+ setBlankFilterLoad(type) {
87
87
  },
88
88
  setDefaults() {
89
89
  const lang = localStorage.getItem("lang");
90
90
  },
91
- updateRouteQuery(type2) {
91
+ updateRouteQuery(type) {
92
92
  const router = useRouter();
93
93
  const { $stores } = useNuxtApp();
94
94
  const routeQuery = {
95
95
  ...this.search ? { search: this.search } : {},
96
96
  ...this.page > 1 ? { page: this.page.toString() } : {},
97
- ...Object.entries($stores[type2].filters).reduce(
97
+ ...Object.entries($stores[type].filters).reduce(
98
98
  (acc, [key, filter]) => {
99
99
  const value = filter?.value;
100
100
  console.log("valueStore", value);
@@ -110,7 +110,7 @@ export const useRootStore = defineStore("rootStore", {
110
110
  };
111
111
  router.replace({ query: routeQuery });
112
112
  },
113
- resetState() {
113
+ resetState(type) {
114
114
  const { $stores } = useNuxtApp();
115
115
  $stores[type].$reset();
116
116
  console.log("resetState");
@@ -122,68 +122,68 @@ export const useRootStore = defineStore("rootStore", {
122
122
  this.skip = 0;
123
123
  this.numberOfPages = 0;
124
124
  },
125
- updateSort({ value, type: type2 }) {
125
+ updateSort({ value, type }) {
126
126
  const { $stores } = useNuxtApp();
127
- $stores[type2].sortBy = [value[0]];
128
- $stores[type2].sortDesc = [value[1]];
127
+ $stores[type].sortBy = [value[0]];
128
+ $stores[type].sortDesc = [value[1]];
129
129
  this.page = 1;
130
- this.updateLocalStorage(type2 + "_sort", value.join("_"));
131
- this.update(type2);
130
+ this.updateLocalStorage(type + "_sort", value.join("_"));
131
+ this.update(type);
132
132
  },
133
- updateView({ value, type: type2 }) {
133
+ updateView({ value, type }) {
134
134
  const { $stores } = useNuxtApp();
135
- $stores[type2].view = {
136
- ...$stores[type2].views[value],
135
+ $stores[type].view = {
136
+ ...$stores[type].views[value],
137
137
  name: value
138
138
  };
139
- this.updateLocalStorage(type2 + "_view", value);
140
- this.update(type2);
139
+ this.updateLocalStorage(type + "_view", value);
140
+ this.update(type);
141
141
  },
142
142
  updateLocalStorage(key, value) {
143
143
  const local = JSON.parse(localStorage.getItem("PARIS_IAS")) || {};
144
144
  local[key] = value;
145
145
  localStorage.setItem("PARIS_IAS", JSON.stringify(local));
146
146
  },
147
- updateFilter(key, val, type2) {
147
+ updateFilter(key, val, type) {
148
148
  const { $stores } = useNuxtApp();
149
- console.log("update filter: ", { key, val, type: type2 });
150
- $stores[type2].filters[key].value = val;
151
- this.setFiltersCount(type2);
152
- this.saveFiltersToLocalStorage(type2);
153
- this.updateRouteQuery(type2);
149
+ console.log("update filter: ", { key, val, type });
150
+ $stores[type].filters[key].value = val;
151
+ this.setFiltersCount(type);
152
+ this.saveFiltersToLocalStorage(type);
153
+ this.updateRouteQuery(type);
154
154
  this.page = 1;
155
- this.update(type2);
155
+ this.update(type);
156
156
  },
157
- updateItemsPerPage({ value, type: type2 }) {
157
+ updateItemsPerPage({ value, type }) {
158
158
  const { $stores } = useNuxtApp();
159
159
  this.page = 1;
160
- $stores[type2].itemsPerPage = value;
161
- this.update(type2);
160
+ $stores[type].itemsPerPage = value;
161
+ this.update(type);
162
162
  },
163
- updatePage({ page, type: type2 }) {
163
+ updatePage({ page, type }) {
164
164
  this.page = page;
165
- this.update(type2);
165
+ this.update(type);
166
166
  },
167
167
  async updateSearch({
168
- type: type2 = "all",
168
+ type = "all",
169
169
  search = "",
170
170
  lang = "en"
171
171
  }) {
172
172
  this.search = search;
173
173
  this.setLoading(true);
174
- await this.update(type2, lang);
174
+ await this.update(type, lang);
175
175
  },
176
- async update(type2, lang = "en") {
176
+ async update(type, lang = "en") {
177
177
  const { $stores } = useNuxtApp();
178
178
  this.setLoading(true);
179
- if (type2 !== "all") {
180
- $stores[type2].loading = true;
179
+ if (type !== "all") {
180
+ $stores[type].loading = true;
181
181
  }
182
- const itemsPerPage = type2 === "all" ? 3 : $stores[type2]?.itemsPerPage;
182
+ const itemsPerPage = type === "all" ? 3 : $stores[type]?.itemsPerPage;
183
183
  const filters = {};
184
- if (type2 !== "all") {
185
- for (const filter in $stores[type2].filters) {
186
- const filterValue = $stores[type2].filters[filter]?.value;
184
+ if (type !== "all") {
185
+ for (const filter in $stores[type].filters) {
186
+ const filterValue = $stores[type].filters[filter]?.value;
187
187
  if (typeof filterValue !== "undefined" && filterValue?.length) {
188
188
  filters[filter] = filterValue;
189
189
  }
@@ -197,14 +197,14 @@ export const useRootStore = defineStore("rootStore", {
197
197
  // limit
198
198
  limit: itemsPerPage,
199
199
  // sort, array of keys and array of directions - to have x tie breakers if necessary
200
- sortBy: type2 === "all" ? "searchScore" : $stores[type2].sortBy,
201
- sortDesc: type2 === "all" ? -1 : $stores[type2].sortDesc > 0 ? true : false,
200
+ sortBy: type === "all" ? "searchScore" : $stores[type].sortBy,
201
+ sortDesc: type === "all" ? -1 : $stores[type].sortDesc > 0 ? true : false,
202
202
  // search (if set)
203
- ...this.search?.length && type2 !== "all" && { search: this.search },
203
+ ...this.search?.length && type !== "all" && { search: this.search },
204
204
  // add the store module filters
205
205
  filters
206
206
  },
207
- ...this.search?.length && type2 === "all" && { search: this.search },
207
+ ...this.search?.length && type === "all" && { search: this.search },
208
208
  appId: "iea",
209
209
  lang
210
210
  })
@@ -212,15 +212,15 @@ export const useRootStore = defineStore("rootStore", {
212
212
  args.options.filters = JSON.stringify(args.options.filters);
213
213
  let result = {};
214
214
  console.log("args: ", args);
215
- console.log(`Fetching ${type2}`);
215
+ console.log(`Fetching ${type}`);
216
216
  const { $queries } = useNuxtApp();
217
217
  const { data, error } = await useAsyncQuery(
218
- type2 === "all" ? SEARCH : $queries[type2].list,
218
+ type === "all" ? SEARCH : $queries[type].list,
219
219
  args
220
220
  );
221
221
  if (error.value) console.log(error.value);
222
- const key = type2 === "all" ? "search" : "list" + type2.charAt(0).toUpperCase() + type2.slice(1);
223
- if (type2 === "all") {
222
+ const key = type === "all" ? "search" : "list" + type.charAt(0).toUpperCase() + type.slice(1);
223
+ if (type === "all") {
224
224
  this.results = data?.value?.[key];
225
225
  } else {
226
226
  const items = data?.value?.[key]?.items ?? [];
@@ -232,13 +232,13 @@ export const useRootStore = defineStore("rootStore", {
232
232
  _path: `/${id}`
233
233
  }))
234
234
  };
235
- $stores[type2].items = result["items"];
235
+ $stores[type].items = result["items"];
236
236
  const lastPage = Math.ceil(result.total / itemsPerPage);
237
- this.setFiltersCount(type2);
238
- this.setBlankFilterLoad(type2);
239
- $stores[type2].numberOfPages = lastPage;
237
+ this.setFiltersCount(type);
238
+ this.setBlankFilterLoad(type);
239
+ $stores[type].numberOfPages = lastPage;
240
240
  }
241
- this.setLoading(false, type2);
241
+ this.setLoading(false, type);
242
242
  return true;
243
243
  }
244
244
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "license": "AGPL-3.0-only",
3
3
  "main": "./dist/module.mjs",
4
- "version": "1.0.58",
4
+ "version": "1.0.60",
5
5
  "name": "@paris-ias/list",
6
6
  "repository": {
7
7
  "url": "git+https://github.com/IEA-Paris/list.git",