Skip to content

Commit

Permalink
implement no results found design
Browse files Browse the repository at this point in the history
  • Loading branch information
brrkrmn committed Jan 18, 2024
1 parent f80de80 commit 563dc1c
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 14 deletions.
4 changes: 3 additions & 1 deletion zubhub_frontend/zubhub/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,9 @@
},
"errors": {
"unexpected": "Uh oh! Seems like we hit a snag :( Maybe try again later?",
"noResult": "We could not find anything for your search term! Maybe try to search something else?"
"noResult": "We could not find anything for your search term! Maybe try to search something else?",
"noResult2": "Sorry, but we couldn't find any results for ",
"noResultDescription": "Try searching for something else or browse our suggestions!"
},
"loginCard": {
"title": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ export const styles = theme => ({
},
creatorsContainerStyle: {
width: '100%',
display: 'flex',
gap: '1em',
},
creatorsContainerLoggedOutStyle: {
display: 'flex',
justifyContent: 'center'
},
projectsContainerStyle: {
Expand All @@ -57,7 +58,7 @@ export const styles = theme => ({
backgroundColor: '#ffffff',
},
cardLoggedOutStyle: {
marginBottom: '3em',
marginBottom: '9em',
boxShadow: 'none',
},
avatarStyle: {
Expand Down Expand Up @@ -127,6 +128,44 @@ export const styles = theme => ({
background: 'white',
marginTop: '-6em',
},
notFoundRobotStyle: {
width: '20em',
marginTop: '3em',
[theme.breakpoints.down('600')]: {
width: '15em'
},
[theme.breakpoints.down('400')]: {
width: '12em'
}
},
noResultContainerStyle: {
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center'
},
noResultTitleStyle: {
width: '70%',
padding: '0 1em',
[theme.breakpoints.down('600')]: {
width: '100%',
fontSize: '1.5rem'
}

},
noResultDescStyle: {
padding: '0 1em',
fontSize: '1.2rem',
textAlign: 'center',
marginBottom: '3em',
[theme.breakpoints.down('600')]: {
fontSize: '1rem'
}
},
marginBottom: {
marginBottom: '4em',
zIndex: 10
},
});

export const loginStyleOverrides = (theme) => ({
Expand Down Expand Up @@ -154,4 +193,25 @@ export const loginStyleOverrides = (theme) => ({
grid: {
margin: 0
}
})

export const staffPickStyleOverrides = (theme) => ({
root: {
margin: 0,
width: '80%',
[theme.breakpoints.down('400')]: {
width: '100%'
}
},
mainContainerStyle: {
margin: 0
},
MessagePrimaryStyle: {
fontSize: '1.8rem',
fontWeight: 700,
[theme.breakpoints.down('600')]: {
fontSize: '1.5rem',
},
},

})
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ function StaffPick(props) {
return staff_pick.projects &&
staff_pick.projects.results &&
staff_pick.projects.results.length > 0 ? (
<Box className={classes.root}>
<Grid container spacing={3}>
<Box className={clsx(classes.root, props.styleOverrides?.root)}>
<Grid container spacing={3} className={clsx(props.styleOverrides?.mainContainer)}>
<Grid item xs={12}>
<Typography
gutterBottom
// component="h2"
// variant="h6"
// color="textPrimary"
className={classes.MessagePrimaryStyle}
className={clsx(classes.MessagePrimaryStyle, props.styleOverrides?.MessagePrimary)}
>
{staff_pick.title}
{/* <CustomButton
Expand Down
75 changes: 67 additions & 8 deletions zubhub_frontend/zubhub/src/views/search_results/SearchResults.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]>
Expand Down Expand Up @@ -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: [],
Expand All @@ -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')));
}, []);

Expand Down Expand Up @@ -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
Expand All @@ -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')}
Expand Down Expand Up @@ -279,11 +336,6 @@ function SearchResults(props) {
</>
}
</Container>
) : (
<ErrorPage
error={t('searchResults.errors.noResult')}
/>
)}
</Box>
);
}
Expand All @@ -302,6 +354,7 @@ SearchResults.propTypes = {
const mapStateToProps = state => {
return {
auth: state.auth,
projects: state.projects,
};
};

Expand All @@ -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));
}
};
};

Expand Down

0 comments on commit 563dc1c

Please sign in to comment.