@paris-ias/list 1.0.11 → 1.0.13
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/README.md +71 -51
- package/dist/module.d.mts +8 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +64 -0
- package/dist/runtime/components/events/Badges.vue +5 -7
- package/dist/runtime/components/events/DateTimePlace.vue +11 -13
- package/dist/runtime/components/events/DenseItem.vue +7 -6
- package/dist/runtime/components/events/ExpandedItem.vue +3 -5
- package/dist/runtime/components/events/ListContainer.vue +6 -6
- package/dist/runtime/components/events/RegisterModal.vue +4 -5
- package/dist/runtime/components/events/RelatedItem.vue +6 -7
- package/dist/runtime/components/events/RowsItem.vue +12 -11
- package/dist/runtime/components/events/View.vue +10 -13
- package/dist/runtime/components/fellowships/Badges.vue +12 -15
- package/dist/runtime/components/fellowships/DenseItem.vue +7 -7
- package/dist/runtime/components/fellowships/RegisterModal.vue +3 -2
- package/dist/runtime/components/fellowships/RowsItem.vue +19 -21
- package/dist/runtime/components/fellowships/View.vue +43 -49
- package/dist/runtime/components/list/atoms/FiltersMenu.vue +6 -8
- package/dist/runtime/components/list/atoms/SearchInput.vue +42 -50
- package/dist/runtime/components/list/atoms/SearchItem.vue +14 -14
- package/dist/runtime/components/list/atoms/SearchString.vue +6 -7
- package/dist/runtime/components/list/atoms/SortMenu.vue +23 -40
- package/dist/runtime/components/list/atoms/ViewMenu.vue +14 -22
- package/dist/runtime/components/list/inputs/AutoComplete.vue +9 -9
- package/dist/runtime/components/list/inputs/BooleanSwitch.vue +9 -9
- package/dist/runtime/components/list/inputs/Checkbox.vue +11 -11
- package/dist/runtime/components/list/inputs/Select.vue +11 -11
- package/dist/runtime/components/list/molecules/Filters.vue +27 -42
- package/dist/runtime/components/list/molecules/Header.vue +5 -7
- package/dist/runtime/components/list/molecules/Pagination.vue +60 -102
- package/dist/runtime/components/list/organisms/List.vue +28 -36
- package/dist/runtime/components/list/views/Dense.vue +1 -14
- package/dist/runtime/components/list/views/Grid.vue +3 -3
- package/dist/runtime/components/list/views/Rows.vue +3 -3
- package/dist/runtime/components/list/views/Table.vue +3 -3
- package/dist/runtime/components/misc/atoms/CountUp.vue +89 -144
- package/dist/runtime/components/misc/atoms/DateStamp.vue +42 -46
- package/dist/runtime/components/misc/atoms/ImageContainer.vue +14 -22
- package/dist/runtime/components/misc/atoms/ShareMenu.vue +9 -11
- package/dist/runtime/components/misc/atoms/Socials.vue +46 -52
- package/dist/runtime/components/misc/molecules/ChipContainer.vue +7 -11
- package/dist/runtime/components/misc/molecules/Related.vue +9 -11
- package/dist/runtime/components/misc/molecules/RelatedItems.vue +7 -9
- package/dist/runtime/components/misc/molecules/SearchItem.vue +2 -2
- package/dist/runtime/components/news/DenseItem.vue +15 -15
- package/dist/runtime/components/news/ExpandedItem.vue +40 -50
- package/dist/runtime/components/news/Header.vue +3 -5
- package/dist/runtime/components/news/RelatedItem.vue +6 -7
- package/dist/runtime/components/news/RowsItem.vue +14 -16
- package/dist/runtime/components/news/View.vue +9 -20
- package/dist/runtime/components/people/DenseItem.vue +9 -8
- package/dist/runtime/components/people/ExpandedItem.vue +4 -6
- package/dist/runtime/components/people/GroupBadges.vue +6 -8
- package/dist/runtime/components/people/RelatedItem.vue +6 -7
- package/dist/runtime/components/people/RowsItem.vue +12 -19
- package/dist/runtime/components/people/View.vue +7 -7
- package/dist/runtime/components/projects/ExpandedItem.vue +4 -6
- package/dist/runtime/components/projects/RelatedItem.vue +6 -7
- package/dist/runtime/components/projects/RowsItem.vue +21 -26
- package/dist/runtime/components/projects/View.vue +8 -8
- package/dist/runtime/components/publications/RelatedItem.vue +6 -7
- package/dist/runtime/components/publications/RowsItem.vue +20 -22
- package/dist/runtime/components/publications/View.vue +9 -15
- package/dist/runtime/composables/useFetchItem.d.ts +6 -0
- package/dist/runtime/composables/useFetchItem.js +49 -0
- package/dist/runtime/composables/useIcons.d.ts +1 -0
- package/dist/runtime/composables/useIcons.js +30 -0
- package/dist/runtime/composables/useUtils.d.ts +12 -0
- package/dist/runtime/composables/useUtils.js +47 -0
- package/dist/runtime/plugins/pinia.d.ts +2 -0
- package/dist/runtime/plugins/{pinia.ts → pinia.js} +29 -48
- package/dist/runtime/plugins/vuetify.d.ts +2 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/runtime/stores/factory.d.ts +1 -0
- package/dist/runtime/stores/{factory.ts → factory.js} +9 -9
- package/dist/runtime/stores/root.d.ts +34 -0
- package/dist/runtime/stores/root.js +227 -0
- package/dist/types.d.mts +3 -0
- package/package.json +55 -26
- package/dist/runtime/composables/useFetchItem.ts +0 -64
- package/dist/runtime/composables/useIcons.ts +0 -30
- package/dist/runtime/composables/useUtils.ts +0 -75
- package/dist/runtime/stores/root.ts +0 -353
- package/example/.env.example +0 -3
- package/example/nuxt.config.ts +0 -19
- package/example/pages/index.vue +0 -27
- package/index.ts +0 -119
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<template>
|
|
1
|
+
<template>
|
|
2
2
|
<v-col v-ripple cols="12" sm="6" md="4" lg="3" xl="2">
|
|
3
3
|
<MiscAtomsImageContainer
|
|
4
4
|
contain
|
|
@@ -82,24 +82,22 @@
|
|
|
82
82
|
</div>
|
|
83
83
|
</v-col>
|
|
84
84
|
<v-divider />
|
|
85
|
-
</template>
|
|
86
|
-
|
|
87
|
-
<script setup>
|
|
88
|
-
import { useDisplay } from "vuetify"
|
|
89
|
-
const { name } = useDisplay()
|
|
90
|
-
const { locale } = useI18n()
|
|
91
|
-
const { $stores } = useNuxtApp()
|
|
92
|
-
const router = useRouter()
|
|
93
|
-
const localePath = useLocalePath()
|
|
94
|
-
const props = defineProps({
|
|
95
|
-
item: {
|
|
96
|
-
type: Object,
|
|
97
|
-
default: () => {
|
|
98
|
-
return {}
|
|
99
|
-
},
|
|
100
|
-
required: true
|
|
101
|
-
}
|
|
102
|
-
})
|
|
103
|
-
</script>
|
|
104
|
-
|
|
105
|
-
<style lang="scss"></style>
|
|
85
|
+
</template>
|
|
86
|
+
|
|
87
|
+
<script setup>
|
|
88
|
+
import { useDisplay } from "vuetify";
|
|
89
|
+
const { name } = useDisplay();
|
|
90
|
+
const { locale } = useI18n();
|
|
91
|
+
const { $stores } = useNuxtApp();
|
|
92
|
+
const router = useRouter();
|
|
93
|
+
const localePath = useLocalePath();
|
|
94
|
+
const props = defineProps({
|
|
95
|
+
item: {
|
|
96
|
+
type: Object,
|
|
97
|
+
default: () => {
|
|
98
|
+
return {};
|
|
99
|
+
},
|
|
100
|
+
required: true
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
</script>
|
|
@@ -114,26 +114,20 @@
|
|
|
114
114
|
</template>
|
|
115
115
|
|
|
116
116
|
<script setup>
|
|
117
|
-
import { useDisplay } from "vuetify"
|
|
118
|
-
const { $stores } = useNuxtApp()
|
|
119
|
-
const { name } = useDisplay()
|
|
120
|
-
const { locale } = useI18n()
|
|
117
|
+
import { useDisplay } from "vuetify";
|
|
118
|
+
const { $stores } = useNuxtApp();
|
|
119
|
+
const { name } = useDisplay();
|
|
120
|
+
const { locale } = useI18n();
|
|
121
121
|
const props = defineProps({
|
|
122
122
|
item: {
|
|
123
123
|
type: Object,
|
|
124
|
-
required: true
|
|
124
|
+
required: true
|
|
125
125
|
},
|
|
126
126
|
loading: {
|
|
127
127
|
type: Boolean,
|
|
128
128
|
required: false,
|
|
129
|
-
default: false
|
|
130
|
-
}
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
/* const { data: action } = await useAsyncData("actions", () =>
|
|
134
|
-
queryContent("/actions/" + locale.value)
|
|
135
|
-
.limit(1)
|
|
136
|
-
.find()
|
|
137
|
-
) */
|
|
138
|
-
$stores.publications.loading = false
|
|
129
|
+
default: false
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
$stores.publications.loading = false;
|
|
139
133
|
</script>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useRoute } from "vue-router";
|
|
2
|
+
export const useFetchItem = () => {
|
|
3
|
+
const fetchItem = async (payload) => {
|
|
4
|
+
try {
|
|
5
|
+
const { locale } = useI18n();
|
|
6
|
+
const route = useRoute();
|
|
7
|
+
const variables = {
|
|
8
|
+
itemId: route.params.slug?.toString().trim(),
|
|
9
|
+
appId: "iea",
|
|
10
|
+
lang: locale.value
|
|
11
|
+
};
|
|
12
|
+
const { data, error } = await useAsyncQuery(payload.query, variables);
|
|
13
|
+
if (error.value) {
|
|
14
|
+
console.error("GraphQL error:", error.value);
|
|
15
|
+
throw error.value;
|
|
16
|
+
}
|
|
17
|
+
const item = data?.value[payload.key];
|
|
18
|
+
if (!item) {
|
|
19
|
+
throw createError({
|
|
20
|
+
statusCode: 404,
|
|
21
|
+
message: "Item not found in response"
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const setI18nParams = useSetI18nParams();
|
|
25
|
+
if (!route.name.includes("people")) {
|
|
26
|
+
setI18nParams({
|
|
27
|
+
en: { slug: item.slug.en },
|
|
28
|
+
fr: { slug: item.slug.fr }
|
|
29
|
+
});
|
|
30
|
+
} else {
|
|
31
|
+
setI18nParams({
|
|
32
|
+
en: { slug: item.slug },
|
|
33
|
+
fr: { slug: item.slug }
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return item;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.error("Error fetching item:", error);
|
|
39
|
+
throw createError({
|
|
40
|
+
statusCode: 404,
|
|
41
|
+
message: "Item not found",
|
|
42
|
+
cause: error
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
fetchItem
|
|
48
|
+
};
|
|
49
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function getFileIcon(fileName: string): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export default function getFileIcon(fileName) {
|
|
2
|
+
console.log("fileName: ", fileName);
|
|
3
|
+
const fileExtension = fileName.split(".").pop();
|
|
4
|
+
console.log("fileExtension: ", fileExtension);
|
|
5
|
+
switch (fileExtension) {
|
|
6
|
+
case "pdf":
|
|
7
|
+
return "mdi-file-pdf-box";
|
|
8
|
+
case "doc":
|
|
9
|
+
case "docx":
|
|
10
|
+
return "mdi-file-word";
|
|
11
|
+
case "xls":
|
|
12
|
+
case "xlsx":
|
|
13
|
+
return "mdi-file-excel";
|
|
14
|
+
case "ppt":
|
|
15
|
+
case "pptx":
|
|
16
|
+
return "mdi-file-powerpoint";
|
|
17
|
+
case "jpg":
|
|
18
|
+
case "jpeg":
|
|
19
|
+
case "png":
|
|
20
|
+
case "gif":
|
|
21
|
+
return "mdi-file-image";
|
|
22
|
+
case "zip":
|
|
23
|
+
case "rar":
|
|
24
|
+
return "mdi-folder-zip";
|
|
25
|
+
case "txt":
|
|
26
|
+
return "mdi-file-document";
|
|
27
|
+
default:
|
|
28
|
+
return "mdi-file";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const formatDate: (dateStr: string, locale: string) => string;
|
|
2
|
+
export declare const getLocalizedDate: (dateIso: string) => string;
|
|
3
|
+
export declare const getDetailedFormatedDate: (dateStr: string, locale: string) => {
|
|
4
|
+
day: number;
|
|
5
|
+
month: string;
|
|
6
|
+
year: number;
|
|
7
|
+
hours: number;
|
|
8
|
+
minutes: number;
|
|
9
|
+
};
|
|
10
|
+
export declare const capitalize: (value: string, multiple?: boolean) => string;
|
|
11
|
+
export declare const slugify: (str: string) => string;
|
|
12
|
+
export declare const formatDateValue: (date: string | Date, locale: string) => string;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export const formatDate = (dateStr, locale) => {
|
|
2
|
+
const date = new Date(dateStr);
|
|
3
|
+
return date.toLocaleDateString(locale, {
|
|
4
|
+
weekday: "long",
|
|
5
|
+
year: "numeric",
|
|
6
|
+
month: "long",
|
|
7
|
+
day: "numeric"
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export const getLocalizedDate = (dateIso) => {
|
|
11
|
+
const { $i18n } = useNuxtApp();
|
|
12
|
+
return new Date(dateIso).toLocaleDateString(
|
|
13
|
+
$i18n.localeProperties.value.language,
|
|
14
|
+
{
|
|
15
|
+
weekday: "long",
|
|
16
|
+
year: "numeric",
|
|
17
|
+
month: "long",
|
|
18
|
+
day: "numeric"
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
export const getDetailedFormatedDate = (dateStr, locale) => {
|
|
23
|
+
const date = new Date(dateStr);
|
|
24
|
+
return {
|
|
25
|
+
day: date.getDate(),
|
|
26
|
+
month: date.toLocaleString(locale, { month: "long" }),
|
|
27
|
+
year: date.getFullYear(),
|
|
28
|
+
hours: date.getUTCHours(),
|
|
29
|
+
minutes: date.getMinutes()
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export const capitalize = (value, multiple) => multiple ? value.replace(/(?:^|[\s'-])\S/g, (a) => a.toUpperCase()) : value && value.charAt(0).toUpperCase() + value.slice(1);
|
|
33
|
+
export const slugify = (str) => {
|
|
34
|
+
str = str.replace(/^\s+|\s+$/g, "").trim();
|
|
35
|
+
str = str.toLowerCase();
|
|
36
|
+
const from = "\xE0\xE1\xE4\xE2\xE8\xE9\xEB\xEA\xEC\xED\xEF\xEE\xF2\xF3\xF6\xF4\xF9\xFA\xFC\xFB\xF1\xE7\xB7/_,:;";
|
|
37
|
+
const to = "aaaaeeeeiiiioooouuuunc------";
|
|
38
|
+
for (let i = 0, l = from.length; i < l; i++) {
|
|
39
|
+
str = str.replace(new RegExp(from.charAt(i), "g"), to.charAt(i));
|
|
40
|
+
}
|
|
41
|
+
str = str.replace(/[^a-z0-9 -]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-");
|
|
42
|
+
return str;
|
|
43
|
+
};
|
|
44
|
+
export const formatDateValue = (date, locale) => {
|
|
45
|
+
const formattedDate = new Date(date);
|
|
46
|
+
return formattedDate.toLocaleDateString(locale);
|
|
47
|
+
};
|
|
@@ -1,88 +1,69 @@
|
|
|
1
|
-
import { createDynamicStore } from "../stores/factory"
|
|
2
|
-
import type { AppConfig } from "nuxt/schema"
|
|
3
|
-
import { useRootStore } from "../stores/root"
|
|
4
|
-
const rootStore = useRootStore()
|
|
1
|
+
import { createDynamicStore } from "../stores/factory.js";
|
|
5
2
|
export default defineNuxtPlugin(async (nuxtApp) => {
|
|
6
|
-
const appConfig = useAppConfig()
|
|
7
|
-
list: {
|
|
8
|
-
modules: string[]
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// Define module imports
|
|
3
|
+
const appConfig = useAppConfig();
|
|
13
4
|
const moduleImports = {
|
|
14
5
|
events: () => ({
|
|
15
6
|
model: import("@paris-ias/data/dist/list/events.js"),
|
|
16
7
|
queries: {
|
|
17
8
|
list: import("../graphql/queries/list/events.gql"),
|
|
18
|
-
get: import("../graphql/queries/item/events.gql")
|
|
19
|
-
}
|
|
9
|
+
get: import("../graphql/queries/item/events.gql")
|
|
10
|
+
}
|
|
20
11
|
}),
|
|
21
12
|
news: () => ({
|
|
22
13
|
model: import("@paris-ias/data/dist/list/news.js"),
|
|
23
14
|
queries: {
|
|
24
15
|
list: import("../graphql/queries/list/news.gql"),
|
|
25
|
-
get: import("../graphql/queries/item/news.gql")
|
|
26
|
-
}
|
|
16
|
+
get: import("../graphql/queries/item/news.gql")
|
|
17
|
+
}
|
|
27
18
|
}),
|
|
28
19
|
people: () => ({
|
|
29
20
|
model: import("@paris-ias/data/dist/list/people.js"),
|
|
30
21
|
queries: {
|
|
31
22
|
list: import("../graphql/queries/list/people.gql"),
|
|
32
|
-
get: import("../graphql/queries/item/people.gql")
|
|
33
|
-
}
|
|
23
|
+
get: import("../graphql/queries/item/people.gql")
|
|
24
|
+
}
|
|
34
25
|
}),
|
|
35
26
|
projects: () => ({
|
|
36
27
|
model: import("@paris-ias/data/dist/list/projects.js"),
|
|
37
28
|
queries: {
|
|
38
29
|
list: import("../graphql/queries/list/projects.gql"),
|
|
39
|
-
get: import("../graphql/queries/item/projects.gql")
|
|
40
|
-
}
|
|
30
|
+
get: import("../graphql/queries/item/projects.gql")
|
|
31
|
+
}
|
|
41
32
|
}),
|
|
42
33
|
fellowships: () => ({
|
|
43
34
|
model: import("@paris-ias/data/dist/list/fellowships.js"),
|
|
44
35
|
queries: {
|
|
45
36
|
list: import("../graphql/queries/list/fellowships.gql"),
|
|
46
|
-
get: import("../graphql/queries/item/fellowships.gql")
|
|
47
|
-
}
|
|
37
|
+
get: import("../graphql/queries/item/fellowships.gql")
|
|
38
|
+
}
|
|
48
39
|
}),
|
|
49
40
|
publications: () => ({
|
|
50
41
|
model: import("@paris-ias/data/dist/list/publications.js"),
|
|
51
42
|
queries: {
|
|
52
43
|
list: import("../graphql/queries/list/publications.gql"),
|
|
53
|
-
get: import("../graphql/queries/item/publications.gql")
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
|
|
44
|
+
get: import("../graphql/queries/item/publications.gql")
|
|
45
|
+
}
|
|
46
|
+
})
|
|
57
47
|
// Add other modules similarly...
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const queries = {}
|
|
63
|
-
|
|
64
|
-
// Preload all required modules
|
|
48
|
+
};
|
|
49
|
+
const stores = {};
|
|
50
|
+
const queries = {};
|
|
51
|
+
console.log("INITIALIZING STORES");
|
|
65
52
|
await Promise.all(
|
|
66
53
|
appConfig.list.modules.map(async (type) => {
|
|
67
54
|
try {
|
|
68
|
-
const imports = await moduleImports[
|
|
69
|
-
|
|
70
|
-
]()
|
|
71
|
-
const model = (await imports.model).default
|
|
55
|
+
const imports = await moduleImports[type]();
|
|
56
|
+
const model = (await imports.model).default;
|
|
72
57
|
queries[type] = {
|
|
73
58
|
list: (await imports.queries.list).default,
|
|
74
|
-
get: (await imports.queries.get).default
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
stores[type] = createDynamicStore(type, { ...model, queries })()
|
|
59
|
+
get: (await imports.queries.get).default
|
|
60
|
+
};
|
|
61
|
+
stores[type] = createDynamicStore(type, model)();
|
|
78
62
|
} catch (error) {
|
|
79
|
-
console.error(`Failed to initialize ${type} store:`, error)
|
|
63
|
+
console.error(`Failed to initialize ${type} store:`, error);
|
|
80
64
|
}
|
|
81
65
|
})
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
nuxtApp.provide("stores", stores)
|
|
87
|
-
nuxtApp.provide("queries", queries)
|
|
88
|
-
})
|
|
66
|
+
);
|
|
67
|
+
nuxtApp.provide("stores", stores);
|
|
68
|
+
nuxtApp.provide("queries", queries);
|
|
69
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createDynamicStore: (storeName: string, moduleState: object) => import("pinia").StoreDefinition<string, {} | Pick<any, string | number>, {} | Pick<any, string | number>, {} | Pick<any, string | number>>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { defineStore } from "pinia";
|
|
2
|
+
export const createDynamicStore = (storeName, moduleState) => {
|
|
2
3
|
return defineStore(storeName, () => {
|
|
3
4
|
const state = reactive({
|
|
4
5
|
loading: false,
|
|
@@ -7,12 +8,11 @@ export const createDynamicStore = (storeName: string, moduleState: object) => {
|
|
|
7
8
|
page: 1,
|
|
8
9
|
numberOfPages: 0,
|
|
9
10
|
search: "",
|
|
10
|
-
error: null
|
|
11
|
-
...moduleState
|
|
12
|
-
})
|
|
13
|
-
|
|
11
|
+
error: null,
|
|
12
|
+
...moduleState
|
|
13
|
+
});
|
|
14
14
|
return {
|
|
15
|
-
...toRefs(state)
|
|
16
|
-
}
|
|
17
|
-
})
|
|
18
|
-
}
|
|
15
|
+
...toRefs(state)
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare const useRootStore: import("pinia").StoreDefinition<"rootStore", Record<string, any>, {}, {
|
|
2
|
+
setLoading(value: boolean, type?: string): void;
|
|
3
|
+
setScrolled(): void;
|
|
4
|
+
loadRouteQuery(type: string): void;
|
|
5
|
+
setFiltersCount(type: string): void;
|
|
6
|
+
setBlankFilterLoad(type: string): void;
|
|
7
|
+
setDefaults(): void;
|
|
8
|
+
updateRouteQuery(type: string): void;
|
|
9
|
+
resetState(): void;
|
|
10
|
+
updateSort({ value, type }: {
|
|
11
|
+
value: number[] | string[];
|
|
12
|
+
type: string;
|
|
13
|
+
}): void;
|
|
14
|
+
updateView({ value, type }: {
|
|
15
|
+
value: string;
|
|
16
|
+
type: string;
|
|
17
|
+
}): void;
|
|
18
|
+
updateLocalStorage(key: string, value: string): void;
|
|
19
|
+
updateFilter(key: string, val: any, type: string): void;
|
|
20
|
+
updateItemsPerPage({ value, type }: {
|
|
21
|
+
value: number;
|
|
22
|
+
type: string;
|
|
23
|
+
}): void;
|
|
24
|
+
updatePage({ page, type }: {
|
|
25
|
+
page: number;
|
|
26
|
+
type: string;
|
|
27
|
+
}): void;
|
|
28
|
+
updateSearch({ type, search, lang, }: {
|
|
29
|
+
type: string;
|
|
30
|
+
search: string;
|
|
31
|
+
lang: string;
|
|
32
|
+
}): Promise<void>;
|
|
33
|
+
update(type: string, lang?: string): Promise<boolean>;
|
|
34
|
+
}>;
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { defineStore } from "pinia";
|
|
2
|
+
import SEARCH from "../graphql/queries/list/search.gql";
|
|
3
|
+
export const useRootStore = defineStore("rootStore", {
|
|
4
|
+
state: () => ({
|
|
5
|
+
scrolled: import.meta.browser ? window.scrollY > 0 : false,
|
|
6
|
+
loading: false,
|
|
7
|
+
total: 0,
|
|
8
|
+
skip: 0,
|
|
9
|
+
page: 1,
|
|
10
|
+
numberOfPages: 0,
|
|
11
|
+
search: "",
|
|
12
|
+
results: {
|
|
13
|
+
events: {},
|
|
14
|
+
news: {},
|
|
15
|
+
people: {},
|
|
16
|
+
projects: {},
|
|
17
|
+
fellowships: {},
|
|
18
|
+
publications: {}
|
|
19
|
+
}
|
|
20
|
+
}),
|
|
21
|
+
actions: {
|
|
22
|
+
setLoading(value, type = "") {
|
|
23
|
+
const { $stores } = useNuxtApp();
|
|
24
|
+
this.loading = value;
|
|
25
|
+
if (type.length) $stores[type].loading = value;
|
|
26
|
+
},
|
|
27
|
+
setScrolled() {
|
|
28
|
+
if (import.meta.browser) {
|
|
29
|
+
this.scrolled = window.scrollY > 0;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
loadRouteQuery(type) {
|
|
33
|
+
const { currentRoute } = useRouter();
|
|
34
|
+
const { $stores } = useNuxtApp();
|
|
35
|
+
const query = currentRoute.value.query;
|
|
36
|
+
if (Object.keys(query)?.length) {
|
|
37
|
+
Object.keys(query).forEach((filter) => {
|
|
38
|
+
if (Object.keys($stores[type].filters).includes(filter))
|
|
39
|
+
$stores[type].filters[filter].value = this[type].list.filters[filter].multiple ? JSON.parse(query[filter]) : query[filter];
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
console.log("query loaded");
|
|
43
|
+
},
|
|
44
|
+
setFiltersCount(type) {
|
|
45
|
+
const { $stores } = useNuxtApp();
|
|
46
|
+
let filtersCount = 0;
|
|
47
|
+
Object.keys($stores[type].filters).forEach((filter) => {
|
|
48
|
+
if ($stores[type].filters[filter]?.value?.length && typeof $stores[type].filters[filter]?.value !== "undefined") {
|
|
49
|
+
filtersCount++;
|
|
50
|
+
}
|
|
51
|
+
return filtersCount;
|
|
52
|
+
});
|
|
53
|
+
$stores[type].filtersCount = filtersCount;
|
|
54
|
+
},
|
|
55
|
+
setBlankFilterLoad(type) {
|
|
56
|
+
},
|
|
57
|
+
setDefaults() {
|
|
58
|
+
const lang = localStorage.getItem("lang");
|
|
59
|
+
},
|
|
60
|
+
updateRouteQuery(type) {
|
|
61
|
+
const router = useRouter();
|
|
62
|
+
const { $stores } = useNuxtApp();
|
|
63
|
+
const routeQuery = {
|
|
64
|
+
// Add search if it exists and is defined
|
|
65
|
+
...this.search ? { search: this.search } : {},
|
|
66
|
+
// Add page if it's greater than 1
|
|
67
|
+
...this.page > 1 ? { page: this.page.toString() } : {},
|
|
68
|
+
// Add filters with defined values
|
|
69
|
+
...Object.entries($stores[type].filters).reduce(
|
|
70
|
+
(acc, [filterKey, filter]) => {
|
|
71
|
+
if (!$stores[type].filters[filterKey]?.value) {
|
|
72
|
+
return acc;
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
...acc,
|
|
76
|
+
...{
|
|
77
|
+
[filterKey]: $stores[type].filters[filterKey]?.value
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
{}
|
|
82
|
+
)
|
|
83
|
+
};
|
|
84
|
+
router.replace({ query: routeQuery });
|
|
85
|
+
},
|
|
86
|
+
resetState() {
|
|
87
|
+
const { $stores } = useNuxtApp();
|
|
88
|
+
console.log("resetState");
|
|
89
|
+
this.search = "";
|
|
90
|
+
this.page = 1;
|
|
91
|
+
this.scrolled = false;
|
|
92
|
+
this.loading = false;
|
|
93
|
+
this.total = 0;
|
|
94
|
+
this.skip = 0;
|
|
95
|
+
this.numberOfPages = 0;
|
|
96
|
+
const modules = [
|
|
97
|
+
"events",
|
|
98
|
+
"news",
|
|
99
|
+
"people",
|
|
100
|
+
"projects",
|
|
101
|
+
"fellowships",
|
|
102
|
+
"publications"
|
|
103
|
+
];
|
|
104
|
+
modules.forEach((type) => {
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
updateSort({ value, type }) {
|
|
108
|
+
const { $stores } = useNuxtApp();
|
|
109
|
+
$stores[type].sortBy = [value[0]];
|
|
110
|
+
$stores[type].sortDesc = [value[1]];
|
|
111
|
+
this.page = 1;
|
|
112
|
+
this.updateLocalStorage(type + "_sort", value.join("_"));
|
|
113
|
+
this.update(type);
|
|
114
|
+
},
|
|
115
|
+
updateView({ value, type }) {
|
|
116
|
+
const { $stores } = useNuxtApp();
|
|
117
|
+
$stores[type].view = {
|
|
118
|
+
...$stores[type].views[value],
|
|
119
|
+
name: value
|
|
120
|
+
};
|
|
121
|
+
this.updateLocalStorage(type + "_view", value);
|
|
122
|
+
this.update(type);
|
|
123
|
+
},
|
|
124
|
+
updateLocalStorage(key, value) {
|
|
125
|
+
const local = JSON.parse(localStorage.getItem("PARIS_IAS")) || {};
|
|
126
|
+
local[key] = value;
|
|
127
|
+
localStorage.setItem("PARIS_IAS", JSON.stringify(local));
|
|
128
|
+
},
|
|
129
|
+
updateFilter(key, val, type) {
|
|
130
|
+
const { $stores } = useNuxtApp();
|
|
131
|
+
console.log("update filter: ", { key, val, type });
|
|
132
|
+
if (["online", "outside", "past"].includes(key) && val === false) {
|
|
133
|
+
$stores[type].filters[key].value = null;
|
|
134
|
+
} else {
|
|
135
|
+
$stores[type].filters[key].value = val;
|
|
136
|
+
}
|
|
137
|
+
this.updatePage({ page: 1, type });
|
|
138
|
+
},
|
|
139
|
+
updateItemsPerPage({ value, type }) {
|
|
140
|
+
const { $stores } = useNuxtApp();
|
|
141
|
+
this.page = 1;
|
|
142
|
+
$stores[types].itemsPerPage = value;
|
|
143
|
+
this.update(type);
|
|
144
|
+
},
|
|
145
|
+
updatePage({ page, type }) {
|
|
146
|
+
this.page = page;
|
|
147
|
+
this.update(type);
|
|
148
|
+
},
|
|
149
|
+
async updateSearch({
|
|
150
|
+
type = "all",
|
|
151
|
+
search = "",
|
|
152
|
+
lang = "en"
|
|
153
|
+
}) {
|
|
154
|
+
this.search = search;
|
|
155
|
+
this.setLoading(true);
|
|
156
|
+
await this.update(type, lang);
|
|
157
|
+
},
|
|
158
|
+
async update(type, lang = "en") {
|
|
159
|
+
const { $stores } = useNuxtApp();
|
|
160
|
+
this.setLoading(true);
|
|
161
|
+
if (type !== "all") {
|
|
162
|
+
$stores[type].loading = true;
|
|
163
|
+
}
|
|
164
|
+
const itemsPerPage = type === "all" ? 3 : $stores[type]?.itemsPerPage;
|
|
165
|
+
const filters = {};
|
|
166
|
+
if (type !== "all") {
|
|
167
|
+
for (const filter in $stores[type].filters) {
|
|
168
|
+
const filterValue = $stores[type].filters[filter]?.value;
|
|
169
|
+
if (typeof filterValue !== "undefined" && filterValue?.length) {
|
|
170
|
+
filters[filter] = filterValue;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const args = JSON.parse(
|
|
175
|
+
JSON.stringify({
|
|
176
|
+
options: {
|
|
177
|
+
// skip
|
|
178
|
+
skip: +this.page === 1 ? 0 : (+this.page - 1) * itemsPerPage,
|
|
179
|
+
// limit
|
|
180
|
+
limit: itemsPerPage,
|
|
181
|
+
// sort, array of keys and array of directions - to have x tie breakers if necessary
|
|
182
|
+
sortBy: type === "all" ? "searchScore" : $stores[type].sortBy,
|
|
183
|
+
sortDesc: type === "all" ? -1 : $stores[type].sortDesc > 0 ? true : false,
|
|
184
|
+
// search (if set)
|
|
185
|
+
...this.search?.length && type !== "all" && { search: this.search },
|
|
186
|
+
// add the store module filters
|
|
187
|
+
filters
|
|
188
|
+
},
|
|
189
|
+
...this.search?.length && type === "all" && { search: this.search },
|
|
190
|
+
appId: "iea",
|
|
191
|
+
lang
|
|
192
|
+
})
|
|
193
|
+
);
|
|
194
|
+
args.options.filters = JSON.stringify(args.options.filters);
|
|
195
|
+
let result = {};
|
|
196
|
+
console.log("args: ", args);
|
|
197
|
+
console.log(`Fetching ${type}`);
|
|
198
|
+
const { $queries } = useNuxtApp();
|
|
199
|
+
const { data, error } = await useAsyncQuery(
|
|
200
|
+
type === "all" ? SEARCH : $queries[type].list,
|
|
201
|
+
args
|
|
202
|
+
);
|
|
203
|
+
if (error.value) console.log(error.value);
|
|
204
|
+
const key = type === "all" ? "search" : "list" + type.charAt(0).toUpperCase() + type.slice(1);
|
|
205
|
+
if (type === "all") {
|
|
206
|
+
this.results = data?.value?.[key];
|
|
207
|
+
} else {
|
|
208
|
+
const items = data?.value?.[key]?.items ?? [];
|
|
209
|
+
this.total = data?.value?.[key]?.total;
|
|
210
|
+
result = {
|
|
211
|
+
...data?.value?.[key],
|
|
212
|
+
items: items.map(({ id, ...rest }) => ({
|
|
213
|
+
...rest,
|
|
214
|
+
_path: `/${id}`
|
|
215
|
+
}))
|
|
216
|
+
};
|
|
217
|
+
$stores[type].items = result["items"];
|
|
218
|
+
const lastPage = Math.ceil(result.total / itemsPerPage);
|
|
219
|
+
this.setFiltersCount(type);
|
|
220
|
+
this.setBlankFilterLoad(type);
|
|
221
|
+
$stores[type].numberOfPages = lastPage;
|
|
222
|
+
}
|
|
223
|
+
this.setLoading(false, type);
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
});
|
package/dist/types.d.mts
ADDED