Skip to content

Commit bbcbb8b

Browse files
committed
fix regression
1 parent 92beaad commit bbcbb8b

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

zubhub_frontend/zubhub/public/locales/en/translation.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@
482482
"noResult": "We could not find anything for your search term! Maybe try to search something else?"
483483
},
484484
"loginModal": {
485-
"title": "Log in or Sign up to search for projects"
485+
"title": "Log in or Sign up to search for {{type}}"
486486
}
487487
},
488488

zubhub_frontend/zubhub/src/views/search_results/SearchResults.jsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useCallback } from 'react';
22
import PropTypes from 'prop-types';
33
import { Link } from 'react-router-dom';
44
import { connect } from 'react-redux';
@@ -132,12 +132,16 @@ function SearchResults(props) {
132132
}
133133
};
134134

135-
const getResults = (type, results) => {
136-
if (!results) {
135+
136+
const { t, auth } = props;
137+
138+
const getResults = useCallback((type, results) => {
139+
if (!loading && !results?.length) {
137140
return <ErrorPage error={t('searchResults.errors.noResult')} styleOverrides={{ width: modalClasses.errorPage }}/>
138141
}
139-
142+
140143
if (type === SearchType.CREATORS) {
144+
results.slice(0, 4)
141145
return buildCreatorProfiles(
142146
results,
143147
{ classes, common_classes },
@@ -146,9 +150,14 @@ function SearchResults(props) {
146150
handleSetState,
147151
);
148152
} else {
153+
// Sort the results array
154+
results.sort((a, b) => {
155+
return a.title.localeCompare(b.title);
156+
});
157+
const limitedResults = results.slice(0, 3);
149158
return (
150159
<Grid container spacing={3}>
151-
{results?.map(project => (
160+
{limitedResults?.map(project => (
152161
<Grid
153162
item
154163
xs={12}
@@ -169,7 +178,7 @@ function SearchResults(props) {
169178
</Grid>
170179
)
171180
}
172-
};
181+
}, [classes, common_classes, modalClasses.errorPage, props, state, t])
173182

174183
const {
175184
count,
@@ -178,7 +187,6 @@ function SearchResults(props) {
178187
next: next_page,
179188
loading,
180189
} = state;
181-
const { t, auth } = props;
182190

183191
if (!auth.token) {
184192
return (
@@ -195,13 +203,15 @@ function SearchResults(props) {
195203
</Grid>
196204
{getResults(
197205
getQueryParams(window.location.href).get('type'),
198-
props.auth.token ? results : results[0]?.projects?.results,
206+
results
199207
)}
200208
<Grid className={modalClasses.gridBlur}></Grid>
201209
</Grid>
202210
<Grid className={modalClasses.loginModal}>
203211
<Login {...props}
204-
primaryTitle={t('searchResults.loginModal.title')}
212+
primaryTitle={t('searchResults.loginModal.title', {
213+
type: getQueryParams(window.location.href).get('type')
214+
})}
205215
secondaryTitle=''
206216
styleOverrides={{containerStyles: modalClasses.containerStylesOverrides, titleStyles: modalClasses.titleStylesOverrides}}
207217
/>

zubhub_frontend/zubhub/src/views/search_results/searchResultsScripts.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,13 @@ export const getQueryParams = url => {
3131
*/
3232
export const fetchPage = (page, props, query_string, type) => {
3333
if (type === SearchType.PROJECTS) {
34-
if (props.auth?.token) {
35-
return props.searchProjects({
36-
page,
37-
query_string,
38-
t: props.t,
39-
token: props.auth.token,
40-
tab: 'projects',
41-
});
42-
} else {
43-
return props.getStaffPicks({ token: props.token })
44-
}
45-
34+
return props.searchProjects({
35+
page,
36+
query_string,
37+
t: props.t,
38+
token: props.auth.token,
39+
tab: 'projects',
40+
});
4641
} else if (type === SearchType.CREATORS) {
4742
return props.searchCreators({
4843
page,

0 commit comments

Comments
 (0)