@ludo.ninja/components 1.4.1 → 1.4.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ludo.ninja/components",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "dev": "next dev -p 4000",
@@ -2,6 +2,7 @@ export * from './likes/useGetLikesAsset';
2
2
  export * from './apollo';
3
3
  export * from './favorites';
4
4
  export * from './galleries';
5
+ export * from './searchFiltersConnector';
5
6
 
6
7
 
7
8
 
@@ -0,0 +1,184 @@
1
+ import React, { useEffect, useState } from 'react';
2
+
3
+ import { useRouter } from 'next/router';
4
+
5
+ import { searchSchema as schema } from '@ludo.ninja/api';
6
+
7
+ import { useFetchSearchResultSelections } from '@/api/server-preferences/queries/fetchSearchResultSelections';
8
+ import {
9
+ DefaultsCollectionsSearchPageProps,
10
+ DefaultsNftSearchPageProps,
11
+ } from '@/api/server-preferences/queries/fetchSearchResultSelections/queryData';
12
+
13
+ import Filters from '@/components/filters';
14
+
15
+ import { SelectsType } from '@/system/Filters/type';
16
+
17
+ export const useSearchFiltersConnector = function <
18
+ TFilterInput extends
19
+ | schema.ICreationFilterInput
20
+ | schema.ICollectionFilterInput = schema.ICreationFilterInput
21
+ >({
22
+ defaults,
23
+ isDisabledTypeFilters,
24
+ isMobile,
25
+ }: {
26
+ defaults: DefaultsNftSearchPageProps | DefaultsCollectionsSearchPageProps;
27
+ isDisabledTypeFilters?: boolean;
28
+ isMobile: boolean;
29
+ }) {
30
+ const defaultCopyWithoutTerm = {
31
+ time: defaults.time,
32
+ blockchain: defaults.blockchain,
33
+ category: defaults.category,
34
+ status: defaults.status,
35
+ ...('type' in defaults
36
+ ? {
37
+ type: defaults.type,
38
+ }
39
+ : {}),
40
+ } as TFilterInput;
41
+
42
+ const { searchResultSelections } = useFetchSearchResultSelections();
43
+
44
+ const [filterInput, setFilterInput] = useState<TFilterInput>(
45
+ defaultCopyWithoutTerm
46
+ );
47
+
48
+ const router = useRouter();
49
+
50
+ useEffect(() => {
51
+ router.replace(
52
+ {
53
+ query: {
54
+ ...router.query,
55
+ ...defaultCopyWithoutTerm,
56
+ },
57
+ },
58
+ undefined,
59
+ { shallow: true }
60
+ );
61
+ }, []);
62
+
63
+ const handleFilterInput = async (
64
+ fieldName:
65
+ | keyof schema.ICreationFilterInput
66
+ | keyof schema.ICollectionFilterInput,
67
+ fieldValue: string
68
+ ) => {
69
+ await router.replace(
70
+ {
71
+ query: { ...router.query, [fieldName]: fieldValue },
72
+ },
73
+ undefined,
74
+ { shallow: true }
75
+ );
76
+ setFilterInput((prevFilters) => ({
77
+ ...prevFilters,
78
+ [fieldName]: fieldValue,
79
+ }));
80
+ };
81
+ const handleMobileFilterInput = async (
82
+ newFilters: schema.ICreationFilterInput | schema.ICollectionFilterInput
83
+ ) => {
84
+ await router.replace(
85
+ {
86
+ query: { ...router.query, ...newFilters },
87
+ },
88
+ undefined,
89
+ { shallow: true }
90
+ );
91
+ setFilterInput((prevFilters) => ({
92
+ ...prevFilters,
93
+ ...newFilters,
94
+ }));
95
+ };
96
+ const handleResetFilter = () => {
97
+ if (searchResultSelections) {
98
+ const filterInitialStateNft = {
99
+ ...(isDisabledTypeFilters
100
+ ? {}
101
+ : { type: searchResultSelections.typeSelections[0]?.id }),
102
+ time: searchResultSelections.timeSelections[0]?.id,
103
+ blockchain: searchResultSelections.blockchainSelections[0]?.id,
104
+ category: searchResultSelections.categorySelections[0]?.id,
105
+ status: searchResultSelections.statusSelections[0]?.id,
106
+ };
107
+ setFilterInput(filterInitialStateNft as TFilterInput);
108
+ router.replace(
109
+ {
110
+ query: {
111
+ ...router.query,
112
+ ...filterInitialStateNft,
113
+ },
114
+ },
115
+ undefined,
116
+ { shallow: true }
117
+ );
118
+ }
119
+ };
120
+ return {
121
+ filterInput,
122
+ renderFilters: filterInput.time ||
123
+ filterInput.status ||
124
+ filterInput.category ||
125
+ filterInput.blockchain ? (
126
+ <>
127
+ {searchResultSelections && (
128
+ <Filters
129
+ filterInput={filterInput}
130
+ selectData={
131
+ [
132
+ ...(!isDisabledTypeFilters
133
+ ? [
134
+ {
135
+ id: 1,
136
+ data: {
137
+ selectName: 'type',
138
+ selectOptions: searchResultSelections.typeSelections,
139
+ },
140
+ },
141
+ ]
142
+ : []),
143
+ {
144
+ id: 2,
145
+ data: {
146
+ selectName: 'blockchain',
147
+ selectOptions: searchResultSelections.blockchainSelections,
148
+ },
149
+ },
150
+ {
151
+ id: 3,
152
+ data: {
153
+ selectName: 'category',
154
+ selectOptions: searchResultSelections.categorySelections,
155
+ },
156
+ },
157
+ {
158
+ id: 4,
159
+ data: {
160
+ selectName: 'time',
161
+ selectOptions: searchResultSelections.timeSelections,
162
+ },
163
+ },
164
+ {
165
+ id: 5,
166
+ data: {
167
+ selectName: 'status',
168
+ selectOptions: searchResultSelections.statusSelections,
169
+ },
170
+ },
171
+ ] as SelectsType[]
172
+ }
173
+ filterInputHandler={handleFilterInput}
174
+ handleResetFilter={handleResetFilter}
175
+ handleMobileFilterInput={handleMobileFilterInput}
176
+ isMobile={isMobile}
177
+ />
178
+ )}
179
+ </>
180
+ ) : (
181
+ <></>
182
+ ),
183
+ };
184
+ };
@@ -1,9 +1,9 @@
1
1
  import {
2
- ISelection,
3
- Maybe,
4
- } from '@ludo.ninja/api/build/graphql_tools/__generated__/preferencesHost/schema';
2
+ preferencesSchema
3
+ } from '@ludo.ninja/api';
4
+ import { Maybe } from "graphql/jsutils/Maybe";
5
5
 
6
- type Selection = Maybe<Pick<ISelection, 'label'> & { id: string }>;
6
+ type Selection = Maybe<Pick<preferencesSchema.ISelection, 'label'> & { id: string }>;
7
7
 
8
8
  export const findDefaultFilterValue = (
9
9
  queryValue: string | string[] | undefined,
@@ -0,0 +1,2 @@
1
+ export * from './type';
2
+ export * from './helpers';
@@ -8,6 +8,7 @@ export * from './Tabs';
8
8
  export * from './Buttons';
9
9
  export * from './Cards';
10
10
  export * from './Forms';
11
+ export * from './Filters';
11
12
  export { default as CardsHolder } from './CardsHolderWithSkeleton/CardsHolder';
12
13
  export { default as CardsError } from './CardsHolderWithSkeleton/CardsHolder/CardsError';
13
14
  export { default as CardsNoResults } from './CardsHolderWithSkeleton/CardsHolder/CardsNoResults';