itube-specs 0.0.367 → 0.0.369

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.
@@ -1,5 +1,8 @@
1
1
  <template>
2
- <SFilterModelChips :filters="data.filters"/>
2
+ <SFilterChips
3
+ :items="chipsItems"
4
+ @click="(e: IChipsItem)=> onChipsClick(e)"
5
+ />
3
6
  <SFilterPage
4
7
  class="s-model-filters__filters _from-sm"
5
8
  :filters="data.filters"
@@ -44,13 +47,14 @@
44
47
  </template>
45
48
 
46
49
  <script setup lang="ts">
47
- import type { IModelCard, PaginatedResponse } from '../../types';
50
+ import type { IChipsItem, IModelCard, PaginatedResponse } from '../../types';
48
51
 
49
52
  const props = defineProps<{
50
53
  data: PaginatedResponse<IModelCard>,
51
54
  status: string,
52
55
  filterCount: number,
53
56
  title?: string,
57
+ chipsItems: IChipsItem[]
54
58
  }>()
55
59
 
56
60
  const model = defineModel<boolean>();
@@ -80,6 +84,18 @@ const popupTitle = computed(() => {
80
84
  const filterText = props.filterCount > 1 ? t('filters') : t('filter');
81
85
  return `${filterText}${countText}`;
82
86
  })
87
+
88
+ function onChipsClick(item: IChipsItem) {
89
+ const query = { ...route.query };
90
+ if (Array.isArray(item.value) && item.value.length > 1) {
91
+ item.value.forEach((text: string) => {
92
+ delete query[ `${text}` ]
93
+ })
94
+ } else {
95
+ delete query[ `${item.value}` ]
96
+ }
97
+ router.replace({ query });
98
+ }
83
99
  </script>
84
100
 
85
101
  <style scoped lang="scss">
@@ -1,11 +1,17 @@
1
1
  import { computed, unref } from 'vue';
2
2
  import type { Ref } from 'vue';
3
3
  import { useRoute } from 'vue-router';
4
+ import type { IChipsItem } from '../types';
4
5
 
5
- export function useMeta(t, page: string, brandName: string, hasSort?: boolean, text?: Ref<string>, secondText?: Ref<string>) {
6
+ export function useMeta(t, page: string, brandName: string, sortOptions?: IChipsItem[], text?: Ref<string>, secondText?: Ref<string>) {
6
7
  const route = useRoute();
7
8
 
8
- const sortType = computed(() => route?.query?.['sort'] || 'trending');
9
+ const sortType = computed(() => {
10
+ const values = sortOptions?.map(item => item.value);
11
+ const queryValue = String(route?.query?.['sort']);
12
+ const DEFAULT_VALUE = 'trending';
13
+ return queryValue && values?.includes(queryValue) ? queryValue : DEFAULT_VALUE;
14
+ });
9
15
 
10
16
  function getPath(key: string) {
11
17
  const plainSlug = unref(text);
@@ -14,7 +20,7 @@ export function useMeta(t, page: string, brandName: string, hasSort?: boolean, t
14
20
  const pageText = unref(pageNumber) === 1 ? null : ` #${unref(pageNumber)}`;
15
21
 
16
22
  return t(
17
- `meta.${page}.${hasSort ? `${sortType.value}.` : ''}${key}`,
23
+ `meta.${page}.${sortOptions && sortOptions.length > 0 ? `${sortType.value}.` : ''}${key}`,
18
24
  {
19
25
  text: plainSlug,
20
26
  secondText: secondTextValue,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "itube-specs",
3
3
  "type": "module",
4
- "version": "0.0.367",
4
+ "version": "0.0.369",
5
5
  "main": "./nuxt.config.ts",
6
6
  "types": "./types/index.d.ts",
7
7
  "scripts": {
@@ -1,96 +0,0 @@
1
- <template>
2
- <SFilterChips
3
- :items="chipsItems"
4
- @click="(e: IChipsItem)=> onChipsClick(e)"
5
- />
6
- </template>
7
-
8
- <script setup lang="ts">
9
- import type { IChipsItem, IModelFilter, IModelFilterOptions } from '../../types';
10
- import type { LocationQueryValue } from '#vue-router';
11
- import { useRoute, useRouter } from '#vue-router';
12
- import { getMonth } from '../../runtime';
13
-
14
- const props = defineProps<{
15
- filters: IModelFilter[]
16
- }>();
17
-
18
- const { t } = useI18n();
19
- const route = useRoute();
20
- const router = useRouter();
21
-
22
- const chipsItems = computed(() => {
23
- const queryItems = Object.keys(route.query)
24
- .filter(item => item.startsWith('filter'))
25
- .map(item => item.replace('filter_', '')
26
- .replace(/_/g, ' '));
27
-
28
- const groups = Object.values(
29
- queryItems.reduce((acc: Record<string, string[]>, str: string) => {
30
- const parts = str.split(' ');
31
- const last = parts.at(-1);
32
- const key = ['from', 'to'].includes(last)
33
- ? parts.slice(0, -1).join(' ')
34
- : str;
35
-
36
- acc[ key ] ??= [];
37
-
38
- if (last === 'from') acc[ key ].unshift(str);
39
- else acc[ key ].push(str);
40
-
41
- return acc;
42
- }, {})
43
- )
44
-
45
- const getValue = (item: string, index: number) => {
46
- const filter = props.filters.find(filter => {
47
- return filter.name === `${item.replace(/ /g, '_')
48
- .replace('_from', '')
49
- .replace('_to', '')
50
- }`
51
- });
52
- const defaultValue = index === 0 ? filter?.options[ 0 ] : filter?.options[ filter.options.length - 1 ];
53
- const value: LocationQueryValue | LocationQueryValue[] = route.query[ `filter_${item.replace(/ /g, '_')}` ];
54
- const result = () => {
55
- if (item.split(' ').some(item => item === 'month')) {
56
- return getMonth(t, Number(value) - 1 || Number(defaultValue) - 1);
57
- } else if (!isNaN(Number(value))) {
58
- return value;
59
- } else {
60
- return filter?.options.find((option: IModelFilterOptions) => option.name === value)?.title;
61
- }
62
- }
63
- return result() || Number(defaultValue) - 1;
64
- }
65
-
66
- const getValueText = (item: string[]) => [...new Set(item.map((subItem, index) => getValue(subItem, index)))].join(' - ');
67
-
68
- const chipsTitle = ((item: string[]) => {
69
- const key = Array.isArray(item) ? item[0].replace(' from', '') : item;
70
- const convertedKey = props.filters.find(item => item.name.replace(/_/g, ' ') === key)?.name;
71
- const filter = props.filters.find(item => item.name === convertedKey);
72
- const textValue = `${filter?.title}: ${getValueText(item)}`;
73
- return textValue.length > 30 ? getValueText(item) : textValue;
74
- })
75
-
76
- return groups.map((item) => ({
77
- title: chipsTitle(item),
78
- value: item.map(subItem => `filter_${subItem.replace(/ /g, '_')}`),
79
- }));
80
- })
81
-
82
- function onChipsClick(item: IChipsItem) {
83
- const query = { ...route.query };
84
- if (Array.isArray(item.value) && item.value.length > 1) {
85
- item.value.forEach((text: string) => {
86
- delete query[ `${text}` ]
87
- })
88
- } else {
89
- delete query[ `${item.value}` ]
90
- }
91
- router.replace({ query });
92
- }
93
- </script>
94
-
95
- <style scoped lang="scss">
96
- </style>