Skip to content

Commit 4fdcd9e

Browse files
authored
Merge pull request #1693 from ActiveLearningStudio/feature/fix-search-library
fix search
2 parents 6450002 + 48ad021 commit 4fdcd9e

File tree

2 files changed

+376
-331
lines changed

2 files changed

+376
-331
lines changed

src/components/Search/SearchLibrary.js

Lines changed: 76 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import PropTypes from "prop-types";
55
import { Accordion, Card } from "react-bootstrap";
66
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
77
import Swal from "sweetalert2";
8+
import { setSearchTypeAction } from "store/actions/search";
89

910
const SearchLibrary = (props) => {
1011
const {
@@ -44,6 +45,8 @@ const SearchLibrary = (props) => {
4445
noWords,
4546
setisLoader,
4647
activeModel,
48+
searchTypeNew,
49+
setSearchActivityNew,
4750
} = props;
4851

4952
const onSubmit = async () => {
@@ -54,10 +57,10 @@ const SearchLibrary = (props) => {
5457
setActiveTab(fromTeam ? "projects" : "Independent activities");
5558
if (searchInput?.length > 255) {
5659
Swal.fire("Character limit should be less than 255.");
57-
} else if (
58-
activeMainSearchType === "Projects" ||
59-
activeMainSearchType === "projects"
60-
) {
60+
return;
61+
}
62+
63+
if (true) {
6164
// Swal.fire({
6265
// title: 'Searching...', // add html attribute if you want or remove
6366
// html: 'We are fetching results for you!',
@@ -66,28 +69,33 @@ const SearchLibrary = (props) => {
6669
// Swal.showLoading();
6770
// },
6871
// });
69-
const dataSend = {
70-
phrase: searchInput?.trim(),
72+
let dataSend;
73+
// eslint-disable-next-line prefer-const
74+
dataSend = {
75+
query: searchInput?.trim(),
7176
subjectArray: activeSubject,
7277
gradeArray: activeEducation,
7378
authorTagsArray: activeAuthorTag,
79+
authors: authorName || undefined,
7480
standardArray: activeType,
75-
author: authorName || undefined,
76-
fromDate: fromdate || undefined,
77-
toDate: todate || undefined,
78-
type: searchType,
7981
from: 0,
82+
model:
83+
activeModel === "total"
84+
? undefined
85+
: activeModel || undefined,
8086
size: 20,
81-
model: "projects",
8287
no_words: noWords || undefined,
8388
};
84-
console.log("dataSend", dataSend);
85-
const result = await dispatch(simpleSearchAction(dataSend));
86-
setTotalCount(result.meta?.projects);
89+
const result = await dispatch(
90+
searchIndependentActivitiesAction(
91+
dataSend,
92+
"showcase_activities"
93+
)
94+
);
95+
setTotalCount(result?.meta?.total);
8796
const tempEducation = [];
8897
const tempSubject = [];
8998
const tempTag = [];
90-
const tempAuthor = [];
9199
if (activeEducation) {
92100
activeEducation.forEach((edu) => {
93101
if (String(edu).includes("&")) {
@@ -114,12 +122,12 @@ const SearchLibrary = (props) => {
114122
activeAuthorTag.forEach((sub) => {
115123
if (String(sub).includes("&")) {
116124
const temp = String(sub).replace("&", "and");
117-
tempAuthor.push(temp);
125+
tempTag.push(temp);
118126
} else {
119-
tempAuthor.push(sub);
127+
tempTag.push(sub);
120128
}
121129
});
122-
setActiveAuthorTag(tempAuthor);
130+
setActiveAuthorTag(tempTag);
123131
}
124132
if (!fromTeam) {
125133
// eslint-disable-next-line max-len
@@ -129,7 +137,9 @@ const SearchLibrary = (props) => {
129137
// }/search?q=${searchInput.trim()}&type=${searchType}&grade=${tempSubject}&education=${tempEducation}&authorTag=${tempTag}&h5p=${activeType}&author=${authorName}`,
130138
// );
131139
}
132-
} else if (activeMainSearchType === "Independent activities") {
140+
}
141+
142+
if (true) {
133143
// Swal.fire({
134144
// title: 'Searching...', // add html attribute if you want or remove
135145
// html: 'We are fetching results for you!',
@@ -138,33 +148,33 @@ const SearchLibrary = (props) => {
138148
// Swal.showLoading();
139149
// },
140150
// });
141-
let dataSend;
142-
// eslint-disable-next-line prefer-const
143-
dataSend = {
144-
query: searchInput?.trim(),
151+
const dataSend = {
152+
phrase: searchInput?.trim(),
145153
subjectArray: activeSubject,
146154
gradeArray: activeEducation,
147155
authorTagsArray: activeAuthorTag,
148-
authors: authorName || undefined,
149156
standardArray: activeType,
157+
author: authorName || undefined,
158+
fromDate: fromdate || undefined,
159+
toDate: todate || undefined,
160+
type: "projects",
150161
from: 0,
151-
model:
152-
activeModel === "total"
153-
? undefined
154-
: activeModel || undefined,
155162
size: 20,
163+
model: "projects",
156164
no_words: noWords || undefined,
157165
};
158-
const result = await dispatch(
159-
searchIndependentActivitiesAction(
160-
dataSend,
161-
"showcase_activities",
162-
),
163-
);
164-
setTotalCount(result?.meta?.total);
166+
//if (searchTypeNew === "Independent activities") {
167+
dispatch(setSearchTypeAction("projects"));
168+
// } else {
169+
// dispatch(setSearchTypeAction("Independent activities"));
170+
// }
171+
172+
const result = await dispatch(simpleSearchAction(dataSend));
173+
setTotalCount(result.meta?.projects);
165174
const tempEducation = [];
166175
const tempSubject = [];
167176
const tempTag = [];
177+
const tempAuthor = [];
168178
if (activeEducation) {
169179
activeEducation.forEach((edu) => {
170180
if (String(edu).includes("&")) {
@@ -191,12 +201,12 @@ const SearchLibrary = (props) => {
191201
activeAuthorTag.forEach((sub) => {
192202
if (String(sub).includes("&")) {
193203
const temp = String(sub).replace("&", "and");
194-
tempTag.push(temp);
204+
tempAuthor.push(temp);
195205
} else {
196-
tempTag.push(sub);
206+
tempAuthor.push(sub);
197207
}
198208
});
199-
setActiveAuthorTag(tempTag);
209+
setActiveAuthorTag(tempAuthor);
200210
}
201211
if (!fromTeam) {
202212
// eslint-disable-next-line max-len
@@ -207,26 +217,25 @@ const SearchLibrary = (props) => {
207217
// );
208218
}
209219
}
220+
dispatch(setSearchTypeAction("Independent activities"));
210221
// setModalShow(true);
211222
};
212223

213224
const clearFilters = async () => {
214225
setSearchInput("");
215226
setNoWords("");
216227
setAuthor("");
228+
setSearch([]);
229+
setSearchActivityNew([]);
217230
setActiveEducation([]);
218231
setActiveSubject([]);
219232
setActiveAuthorTag([]);
220233
setActiveType([]);
221234
// onSubmit();
222-
const result = await dispatch(simpleSearchAction({}));
223-
const result1 = await dispatch(
224-
searchIndependentActivitiesAction(
225-
{},
226-
"showcase_activities",
227-
),
228-
);
229-
235+
// const result = await dispatch(simpleSearchAction({}));
236+
// const result1 = await dispatch(
237+
// searchIndependentActivitiesAction({}, "showcase_activities")
238+
// );
230239
};
231240
return (
232241
<Accordion defaultActiveKey="0">
@@ -311,11 +320,29 @@ const SearchLibrary = (props) => {
311320
}}
312321
/>
313322
</div>
314-
<div style={{ display: "flex", justifyContent: "space-between", color: "#1E68BF", alignItem: "center", alignItems: "center"}}>
315-
<div style={{ cursor: "pointer", textDecoration: "underline" }} onClick={() => clearFilters()}>
323+
<div
324+
style={{
325+
display: "flex",
326+
justifyContent: "space-between",
327+
color: "#1E68BF",
328+
alignItem: "center",
329+
alignItems: "center",
330+
}}
331+
>
332+
<div
333+
style={{
334+
cursor: "pointer",
335+
textDecoration: "underline",
336+
}}
337+
onClick={() => clearFilters()}
338+
>
316339
Clear All
317340
</div>
318-
<div className="src-btn" style={{marginBottom: "unset"}} onClick={() => onSubmit()}>
341+
<div
342+
className="src-btn"
343+
style={{ marginBottom: "unset" }}
344+
onClick={() => onSubmit()}
345+
>
319346
<FontAwesomeIcon icon="search" />
320347
Search
321348
</div>

0 commit comments

Comments
 (0)