@blaze-cms/react-page-builder 0.124.0-alpha.20 → 0.124.0-alpha.23
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/CHANGELOG.md +24 -0
- package/lib/components/Card/CardContainer.js +1 -2
- package/lib/components/Card/CardContainer.js.map +1 -1
- package/lib/components/SearchContent/SearchContent.js +26 -59
- package/lib/components/SearchContent/SearchContent.js.map +1 -1
- package/lib/components/SearchContent/SearchContentItems.js +48 -0
- package/lib/components/SearchContent/SearchContentItems.js.map +1 -0
- package/lib/components/SearchContent/SearchContentResults.js +45 -0
- package/lib/components/SearchContent/SearchContentResults.js.map +1 -0
- package/lib/components/SearchContent/SearchContentToggleIcon.js +38 -0
- package/lib/components/SearchContent/SearchContentToggleIcon.js.map +1 -0
- package/lib/components/SearchContent/index.js +2 -294
- package/lib/components/SearchContent/index.js.map +1 -1
- package/lib-es/components/Card/CardContainer.js +1 -2
- package/lib-es/components/Card/CardContainer.js.map +1 -1
- package/lib-es/components/SearchContent/SearchContent.js +25 -54
- package/lib-es/components/SearchContent/SearchContent.js.map +1 -1
- package/lib-es/components/SearchContent/SearchContentItems.js +31 -0
- package/lib-es/components/SearchContent/SearchContentItems.js.map +1 -0
- package/lib-es/components/SearchContent/SearchContentResults.js +31 -0
- package/lib-es/components/SearchContent/SearchContentResults.js.map +1 -0
- package/lib-es/components/SearchContent/SearchContentToggleIcon.js +28 -0
- package/lib-es/components/SearchContent/SearchContentToggleIcon.js.map +1 -0
- package/lib-es/components/SearchContent/index.js +1 -202
- package/lib-es/components/SearchContent/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/Card/CardContainer.js +2 -3
- package/src/components/SearchContent/SearchContent.js +23 -55
- package/src/components/SearchContent/SearchContentItems.js +22 -0
- package/src/components/SearchContent/SearchContentResults.js +27 -0
- package/src/components/SearchContent/SearchContentToggleIcon.js +25 -0
- package/src/components/SearchContent/index.js +1 -216
|
@@ -1,218 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { gql, useApolloClient } from '@apollo/client';
|
|
4
|
-
|
|
5
|
-
import { useRouter } from 'next/router';
|
|
6
|
-
import { getPublishedContent } from '../../application/query';
|
|
7
|
-
import BlazeLink from '../BlazeLink';
|
|
8
|
-
|
|
9
|
-
const logError = error => error;
|
|
10
|
-
|
|
11
|
-
const SearchContent = ({
|
|
12
|
-
entities,
|
|
13
|
-
searchInputAlignment,
|
|
14
|
-
searchInputWrapperMobile,
|
|
15
|
-
searchInputWrapperDesktop,
|
|
16
|
-
collapsible,
|
|
17
|
-
isMobile,
|
|
18
|
-
placeholder
|
|
19
|
-
}) => {
|
|
20
|
-
if (!entities) return null;
|
|
21
|
-
|
|
22
|
-
const [collapsed, setCollapsed] = useState(collapsible);
|
|
23
|
-
const [searchTerm, setSearchTerm] = useState(null);
|
|
24
|
-
const [data, setData] = useState([]);
|
|
25
|
-
|
|
26
|
-
const router = useRouter();
|
|
27
|
-
const client = useApolloClient();
|
|
28
|
-
|
|
29
|
-
const capitalize = s => {
|
|
30
|
-
if (typeof s !== 'string') return '';
|
|
31
|
-
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
React.useEffect(() => {
|
|
35
|
-
if (data && data.length !== 0) return;
|
|
36
|
-
|
|
37
|
-
const promises = entities.map(entity => {
|
|
38
|
-
const [a, b] = entity.split('_');
|
|
39
|
-
|
|
40
|
-
const entityName = capitalize(a) + capitalize(b);
|
|
41
|
-
|
|
42
|
-
const rawQueryStringified = JSON.stringify({
|
|
43
|
-
size: 0,
|
|
44
|
-
query: {
|
|
45
|
-
bool: {
|
|
46
|
-
should: [
|
|
47
|
-
{
|
|
48
|
-
match: {
|
|
49
|
-
docType: entity
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
],
|
|
53
|
-
minimum_should_match: 1
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
const query = gql`
|
|
59
|
-
${getPublishedContent(entityName)}
|
|
60
|
-
`;
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
return client.query({
|
|
64
|
-
query,
|
|
65
|
-
variables: {
|
|
66
|
-
rawQueryStringified,
|
|
67
|
-
offset: 0,
|
|
68
|
-
limit: 5
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
} catch (e) {
|
|
72
|
-
return [];
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
(async () => {
|
|
78
|
-
try {
|
|
79
|
-
const fetchResults = await Promise.all(promises);
|
|
80
|
-
const searchResults = fetchResults
|
|
81
|
-
.map(result => {
|
|
82
|
-
const { data: resultData } = result;
|
|
83
|
-
return resultData.searchPublishedContent.results;
|
|
84
|
-
})
|
|
85
|
-
.flat();
|
|
86
|
-
|
|
87
|
-
setData(searchResults);
|
|
88
|
-
} catch (e) {
|
|
89
|
-
logError(e);
|
|
90
|
-
}
|
|
91
|
-
})();
|
|
92
|
-
} catch (e) {
|
|
93
|
-
logError(e);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
const handleClick = (e, url) => {
|
|
98
|
-
e.preventDefault();
|
|
99
|
-
router.push(url);
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const handleKeyPress = e => {
|
|
103
|
-
if (e.key === 'Enter' && e.target.value !== '') {
|
|
104
|
-
router.push(`/search?search_term=${e.target.value}`);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const renderResults = () =>
|
|
109
|
-
// eslint-disable-next-line no-undef
|
|
110
|
-
data?.map(dataItem => {
|
|
111
|
-
const { name, image, url } = dataItem;
|
|
112
|
-
|
|
113
|
-
if (searchTerm && searchTerm !== '') {
|
|
114
|
-
return (
|
|
115
|
-
<BlazeLink href={url} onClick={e => handleClick(e, url)}>
|
|
116
|
-
<div className="search-content--results__wrapper">
|
|
117
|
-
{image.url ? (
|
|
118
|
-
<img src={image.url} alt={name} className="search-content--results__image" />
|
|
119
|
-
) : null}
|
|
120
|
-
<span className="search-content--results__title">{name}</span>
|
|
121
|
-
</div>
|
|
122
|
-
</BlazeLink>
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
return null;
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
const searchResultsMessage = searchTerm ? `Search results for: ${searchTerm}` : '';
|
|
129
|
-
|
|
130
|
-
return collapsed ? (
|
|
131
|
-
<div className={isMobile ? searchInputWrapperMobile : searchInputWrapperDesktop}>
|
|
132
|
-
<div className="search-content--collapse__wrapper">
|
|
133
|
-
<label className="search-content--collapse__label">
|
|
134
|
-
<span className="search-content--collapse__icon_wrapper">
|
|
135
|
-
<svg className="search-content--collapse__icon" viewBox="0 0 20 20">
|
|
136
|
-
<path
|
|
137
|
-
fillRule="evenodd"
|
|
138
|
-
d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z"
|
|
139
|
-
clipRule="evenodd"
|
|
140
|
-
/>
|
|
141
|
-
</svg>
|
|
142
|
-
</span>
|
|
143
|
-
<input
|
|
144
|
-
onFocus={() => setCollapsed(false)}
|
|
145
|
-
onChange={e => setSearchTerm(e.target.value)}
|
|
146
|
-
type="text"
|
|
147
|
-
name="search"
|
|
148
|
-
value=""
|
|
149
|
-
className="search-content--collapse__input"
|
|
150
|
-
/>
|
|
151
|
-
</label>
|
|
152
|
-
</div>
|
|
153
|
-
</div>
|
|
154
|
-
) : (
|
|
155
|
-
<>
|
|
156
|
-
<div className={`${isMobile ? searchInputWrapperMobile : searchInputWrapperDesktop}`}>
|
|
157
|
-
<div className="search-content--expanded__wrapper">
|
|
158
|
-
<label className="search-content--expanded__label">
|
|
159
|
-
<span className="search-content--expanded__icon_wrapper">
|
|
160
|
-
<svg className="search-content--expanded__icon" viewBox="0 0 20 20">
|
|
161
|
-
<path
|
|
162
|
-
fillRule="evenodd"
|
|
163
|
-
d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z"
|
|
164
|
-
clipRule="evenodd"
|
|
165
|
-
/>
|
|
166
|
-
</svg>
|
|
167
|
-
</span>
|
|
168
|
-
<input
|
|
169
|
-
type="text"
|
|
170
|
-
name="search"
|
|
171
|
-
onChange={e => setSearchTerm(e.target.value)}
|
|
172
|
-
onKeyPress={handleKeyPress}
|
|
173
|
-
className="search-content--expanded__input"
|
|
174
|
-
placeholder={placeholder}
|
|
175
|
-
onBlur={() => {
|
|
176
|
-
if (!collapsible) return;
|
|
177
|
-
if (!searchTerm || searchTerm === '') setCollapsed(true);
|
|
178
|
-
}}
|
|
179
|
-
/>
|
|
180
|
-
</label>
|
|
181
|
-
</div>
|
|
182
|
-
{data &&
|
|
183
|
-
searchResultsMessage !== '' && (
|
|
184
|
-
<div className="search-content--results__wrapper">
|
|
185
|
-
<div className="search-content--results__wrapper--message">
|
|
186
|
-
<div className="text-sm pt-2">{searchResultsMessage}</div>
|
|
187
|
-
|
|
188
|
-
<div className="search-content--results__message">
|
|
189
|
-
<div className="search-content--results__content">{renderResults()}</div>
|
|
190
|
-
</div>
|
|
191
|
-
</div>
|
|
192
|
-
</div>
|
|
193
|
-
)}
|
|
194
|
-
</div>
|
|
195
|
-
</>
|
|
196
|
-
);
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
SearchContent.propTypes = {
|
|
200
|
-
searchInputAlignment: PropTypes.string,
|
|
201
|
-
searchInputWrapperMobile: PropTypes.string,
|
|
202
|
-
searchInputWrapperDesktop: PropTypes.string,
|
|
203
|
-
placeholder: PropTypes.string,
|
|
204
|
-
isMobile: PropTypes.bool,
|
|
205
|
-
collapsible: PropTypes.bool,
|
|
206
|
-
entities: PropTypes.array.isRequired
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
SearchContent.defaultProps = {
|
|
210
|
-
searchInputAlignment: '',
|
|
211
|
-
searchInputWrapperMobile: '',
|
|
212
|
-
searchInputWrapperDesktop: '',
|
|
213
|
-
placeholder: '',
|
|
214
|
-
isMobile: false,
|
|
215
|
-
collapsible: false
|
|
216
|
-
};
|
|
1
|
+
import SearchContent from './SearchContent';
|
|
217
2
|
|
|
218
3
|
export default SearchContent;
|