Skip to content

Commit

Permalink
fix regression
Browse files Browse the repository at this point in the history
  • Loading branch information
coderatomy committed Nov 12, 2023
1 parent fcf6b91 commit f14ae18
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion zubhub_frontend/zubhub/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@
"noResult": "We could not find anything for your search term! Maybe try to search something else?"
},
"loginModal": {
"title": "Log in or Sign up to search for projects"
"title": "Log in or Sign up to search for {{type}}"
}
},

Expand Down
28 changes: 19 additions & 9 deletions zubhub_frontend/zubhub/src/views/search_results/SearchResults.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useCallback } from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';
import { connect } from 'react-redux';
Expand Down Expand Up @@ -132,12 +132,16 @@ function SearchResults(props) {
}
};

const getResults = (type, results) => {
if (!results) {

const { t, auth } = props;

const getResults = useCallback((type, results) => {
if (!loading && !results?.length) {
return <ErrorPage error={t('searchResults.errors.noResult')} styleOverrides={{ width: modalClasses.errorPage }}/>
}

if (type === SearchType.CREATORS) {
results.slice(0, 4)
return buildCreatorProfiles(
results,
{ classes, common_classes },
Expand All @@ -146,9 +150,14 @@ function SearchResults(props) {
handleSetState,
);
} else {
// Sort the results array
results.sort((a, b) => {
return a.title.localeCompare(b.title);
});
const limitedResults = results.slice(0, 3);
return (
<Grid container spacing={3}>
{results?.map(project => (
{limitedResults?.map(project => (
<Grid
item
xs={12}
Expand All @@ -169,7 +178,7 @@ function SearchResults(props) {
</Grid>
)
}
};
}, [classes, common_classes, modalClasses.errorPage, props, state, t])

const {
count,
Expand All @@ -178,7 +187,6 @@ function SearchResults(props) {
next: next_page,
loading,
} = state;
const { t, auth } = props;

if (!auth.token) {
return (
Expand All @@ -195,13 +203,15 @@ function SearchResults(props) {
</Grid>
{getResults(
getQueryParams(window.location.href).get('type'),
props.auth.token ? results : results[0]?.projects?.results,
results
)}
<Grid className={modalClasses.gridBlur}></Grid>
</Grid>
<Grid className={modalClasses.loginModal}>
<Login {...props}
primaryTitle={t('searchResults.loginModal.title')}
primaryTitle={t('searchResults.loginModal.title', {
type: getQueryParams(window.location.href).get('type')
})}
secondaryTitle=''
styleOverrides={{containerStyles: modalClasses.containerStylesOverrides, titleStyles: modalClasses.titleStylesOverrides}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,13 @@ export const getQueryParams = url => {
*/
export const fetchPage = (page, props, query_string, type) => {
if (type === SearchType.PROJECTS) {
if (props.auth?.token) {
return props.searchProjects({
page,
query_string,
t: props.t,
token: props.auth.token,
tab: 'projects',
});
} else {
return props.getStaffPicks({ token: props.token })
}

return props.searchProjects({
page,
query_string,
t: props.t,
token: props.auth.token,
tab: 'projects',
});
} else if (type === SearchType.CREATORS) {
return props.searchCreators({
page,
Expand Down

0 comments on commit f14ae18

Please sign in to comment.