itube-specs 0.0.368 → 0.0.371

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">
@@ -3,7 +3,7 @@ import type { Ref } from 'vue';
3
3
  import { useRoute } from 'vue-router';
4
4
  import type { IChipsItem } from '../types';
5
5
 
6
- export function useMeta(t, page: string, brandName: string, sortOptions?: IChipsItem[], text?: Ref<string>, secondText?: Ref<string>) {
6
+ export function useMeta(t, page: string, brandName: string, sortOptions?: IChipsItem[], text?: Ref<string>, secondText?: Ref<string>, thirdText?: Ref<string>, fourthText?: Ref<string>) {
7
7
  const route = useRoute();
8
8
 
9
9
  const sortType = computed(() => {
@@ -16,6 +16,8 @@ export function useMeta(t, page: string, brandName: string, sortOptions?: IChips
16
16
  function getPath(key: string) {
17
17
  const plainSlug = unref(text);
18
18
  const secondTextValue = unref(secondText);
19
+ const thirdTextValue = unref(thirdText);
20
+ const fourTextValue = unref(fourthText);
19
21
  const pageNumber = computed(() => route.query?.['page'] ? Number(route.query['page']) : 1);
20
22
  const pageText = unref(pageNumber) === 1 ? null : ` #${unref(pageNumber)}`;
21
23
 
@@ -24,6 +26,8 @@ export function useMeta(t, page: string, brandName: string, sortOptions?: IChips
24
26
  {
25
27
  text: plainSlug,
26
28
  secondText: secondTextValue,
29
+ thirdText: thirdTextValue,
30
+ fourText: fourTextValue,
27
31
  brandName: `| ${brandName}`, //черточка '|' нужна обязательно
28
32
  page: pageText,
29
33
  }
@@ -0,0 +1,99 @@
1
+ import type { IChipsItem, IModelFilter, IModelFilterOptions } from '../types'
2
+ import type { LocationQuery } from '#vue-router'
3
+ import { getMonth } from '../runtime'
4
+ import type { Ref } from 'vue';
5
+
6
+ export function useFilterChipsItems(
7
+ filters: Ref<IModelFilter[]>,
8
+ route: { query: LocationQuery },
9
+ t: (key: string) => string
10
+ ) {
11
+ const chipsItems = computed<IChipsItem[]>(() => {
12
+ const queryItems = Object.keys(route.query)
13
+ .filter(item => item.startsWith('filter_'))
14
+ .map(item =>
15
+ item
16
+ .replace('filter_', '')
17
+ .replace(/_/g, ' ')
18
+ )
19
+
20
+ const groups = Object.values(
21
+ queryItems.reduce((acc: Record<string, string[]>, str: string) => {
22
+ const parts = str.split(' ')
23
+ const last = parts.at(-1)
24
+
25
+ const key =
26
+ last === 'from' || last === 'to'
27
+ ? parts.slice(0, -1).join(' ')
28
+ : str
29
+
30
+ acc[key] ??= []
31
+
32
+ if (last === 'from') acc[key].unshift(str)
33
+ else acc[key].push(str)
34
+
35
+ return acc
36
+ }, {})
37
+ )
38
+
39
+ const getValue = (item: string, index: number) => {
40
+ const filter = filters.value.find(filter =>
41
+ filter.name ===
42
+ item
43
+ .replace(/ /g, '_')
44
+ .replace('_from', '')
45
+ .replace('_to', '')
46
+ )
47
+
48
+ const defaultValue =
49
+ index === 0
50
+ ? filter?.options[0]
51
+ : filter?.options.at(-1)
52
+
53
+ const value = route.query[`filter_${item.replace(/ /g, '_')}`]
54
+
55
+ if (item.includes('month')) {
56
+ return getMonth(
57
+ t,
58
+ Number(value ?? defaultValue?.name) - 1
59
+ )
60
+ }
61
+
62
+ if (!isNaN(Number(value))) {
63
+ return value
64
+ }
65
+
66
+ return (
67
+ filter?.options.find(
68
+ (option: IModelFilterOptions) =>
69
+ option.name === value
70
+ )?.title ??
71
+ defaultValue?.title
72
+ )
73
+ }
74
+
75
+ const getValueText = (items: string[]) =>
76
+ [...new Set(items.map(getValue))].join(' - ')
77
+
78
+ const chipsTitle = (items: string[]) => {
79
+ const key = items[0].replace(' from', '')
80
+ const filter = filters.value.find(
81
+ f => f.name.replace(/_/g, ' ') === key
82
+ )
83
+
84
+ const text = `${filter?.title}: ${getValueText(items)}`
85
+ return text.length > 30 ? getValueText(items) : text
86
+ }
87
+
88
+ return groups.map(item => ({
89
+ title: chipsTitle(item),
90
+ value: item.map(
91
+ sub => `filter_${sub.replace(/ /g, '_')}`
92
+ ),
93
+ }))
94
+ })
95
+
96
+ return {
97
+ chipsItems,
98
+ }
99
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "itube-specs",
3
3
  "type": "module",
4
- "version": "0.0.368",
4
+ "version": "0.0.371",
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>