-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
135 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,13 +34,18 @@ import CustomButton from '../../components/button/Button'; | |
import ErrorPage from '../error/ErrorPage'; | ||
import LoadingPage from '../loading/LoadingPage'; | ||
import Project from '../../components/project/Project'; | ||
import { styles, loginStyleOverrides } from '../../assets/js/styles/views/search_results/searchResultsStyles'; | ||
import { styles, loginStyleOverrides, staffPickStyleOverrides } from '../../assets/js/styles/views/search_results/searchResultsStyles'; | ||
import commonStyles from '../../assets/js/styles'; | ||
import Login from '../login/Login'; | ||
import broken_robot from '../../assets/images/broken_robot.svg'; | ||
import { fetchStaffPicks, updateStaffPicks } from '../home/projectsScripts'; | ||
import StaffPick from '../../components/staff_pick/StaffPick'; | ||
|
||
const useStyles = makeStyles(styles); | ||
const useCommonStyles = makeStyles(commonStyles); | ||
const useLoginStyleOverrides = makeStyles(loginStyleOverrides); | ||
const useStaffPickStyleOverrides = makeStyles(staffPickStyleOverrides) | ||
|
||
/** | ||
* @function buildCreatorProfiles Component | ||
* @author Raymond Ndibe <[email protected]> | ||
|
@@ -110,6 +115,7 @@ function SearchResults(props) { | |
const classes = useStyles(); | ||
const common_classes = useCommonStyles(); | ||
const loginClasses = useLoginStyleOverrides(); | ||
const staffPickClasses = useStaffPickStyleOverrides(); | ||
|
||
const [state, setState] = React.useState({ | ||
results: [], | ||
|
@@ -121,7 +127,7 @@ function SearchResults(props) { | |
|
||
React.useEffect(() => { | ||
const params = getQueryParams(window.location.href); | ||
|
||
fetchStaffPicks(props); | ||
handleSetState(fetchPage(null, props, params.get('q'), params.get('type'))); | ||
}, []); | ||
|
||
|
@@ -175,14 +181,15 @@ function SearchResults(props) { | |
next: next_page, | ||
loading, | ||
} = state; | ||
const staff_picks = props.projects.staff_picks; | ||
const { t } = props; | ||
if (loading) { | ||
return <LoadingPage />; | ||
} else { | ||
return ( | ||
<Box className={classes.root}> | ||
{results && results.length > 0 ? ( | ||
<Container className={classes.mainContainerStyle}> | ||
{results && results.length > 0 ? ( | ||
<Grid container className={clsx(!props.auth.token && classes.mainContainerLoggedOutStyle)}> | ||
<Grid item xs={12}> | ||
<Typography | ||
|
@@ -204,6 +211,56 @@ function SearchResults(props) { | |
)} | ||
</div> | ||
</Grid> | ||
) : ( | ||
<div className={clsx(classes.noResultContainerStyle, !props.auth.token && classes.mainContainerLoggedOutStyle)}> | ||
<div> | ||
<img className={classes.notFoundRobotStyle} src={broken_robot} alt={'error'} /> | ||
</div> | ||
<Typography | ||
className={clsx(classes.pageHeaderStyle, classes.noResultTitleStyle, getQueryParams(window.location.href).get('type') === SearchType.CREATORS && !props.auth?.token && classes.marginBottom)} | ||
variant="h4" | ||
gutterBottom | ||
> | ||
{t('searchResults.errors.noResult2')} | ||
" | ||
{getQueryParams(window.location.href).get('q')} | ||
" | ||
</Typography> | ||
{staff_picks && | ||
getQueryParams(window.location.href).get('type') === SearchType.PROJECTS && ( | ||
<> | ||
<Typography | ||
className={classes.noResultDescStyle} | ||
variant="body2" | ||
color="textSecondary" | ||
component="p" | ||
> | ||
{t('searchResults.errors.noResultDescription')} | ||
</Typography> | ||
{staff_picks.map(staff_pick => ( | ||
<StaffPick | ||
key={staff_pick.id} | ||
staff_pick={staff_pick} | ||
updateProjects={res => | ||
handleSetState( | ||
updateStaffPicks(res, staff_pick.id, props, toast), | ||
) | ||
} | ||
styleOverrides={{ | ||
root: staffPickClasses.root, | ||
mainContainer: staffPickClasses.mainContainerStyle, | ||
MessagePrimary: staffPickClasses.MessagePrimaryStyle, | ||
}} | ||
{...props} | ||
/> | ||
)) | ||
} | ||
</> | ||
) | ||
} | ||
|
||
</div> | ||
)} | ||
{prev_page || next_page && | ||
<ButtonGroup | ||
aria-label={t('searchResults.ariaLabels.prevNxtButtons')} | ||
|
@@ -279,11 +336,6 @@ function SearchResults(props) { | |
</> | ||
} | ||
</Container> | ||
) : ( | ||
<ErrorPage | ||
error={t('searchResults.errors.noResult')} | ||
/> | ||
)} | ||
</Box> | ||
); | ||
} | ||
|
@@ -302,6 +354,7 @@ SearchResults.propTypes = { | |
const mapStateToProps = state => { | ||
return { | ||
auth: state.auth, | ||
projects: state.projects, | ||
}; | ||
}; | ||
|
||
|
@@ -325,6 +378,12 @@ const mapDispatchToProps = dispatch => { | |
toggleSave: args => { | ||
return dispatch(ProjectActions.toggleSave(args)); | ||
}, | ||
getStaffPicks: args => { | ||
return dispatch(ProjectActions.getStaffPicks(args)); | ||
}, | ||
setStaffPicks: args => { | ||
return dispatch(ProjectActions.setStaffPicks(args)); | ||
} | ||
}; | ||
}; | ||
|
||
|