Skip to content

Commit

Permalink
feat: showHidden is already working
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosMealha committed Jan 24, 2023
1 parent 8292ec9 commit 04a1c18
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 14 deletions.
6 changes: 6 additions & 0 deletions src/actions/searchOffersActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const OfferSearchTypes = Object.freeze({
DISABLE_OFFER: "DISABLE_OFFER",
COMPANY_ENABLE_OFFER: "COMPANY_ENABLE_OFFER",
ADMIN_ENABLE_OFFER: "ADMIN_ENABLE_OFFER",
SET_SHOW_HIDDEN: "SET_SHOW_HIDDEN",
});

export const setLoadingOffers = (loading) => ({
Expand Down Expand Up @@ -100,3 +101,8 @@ export const resetAdvancedSearchFields = () => (dispatch) => {
dispatch(setFields([]));
dispatch(setTechs([]));
};

export const setShowHidden = (showHidden) => ({
type: OfferSearchTypes.SET_SHOW_HIDDEN,
showHidden,
});
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const AdvancedSearchDesktop = () => {
const {
advancedOptions, resetAdvancedSearch, FieldsSelectorProps, TechsSelectorProps, JobTypeSelectorProps, JobDurationSwitchProps,
ResetButtonProps, JobDurationSliderText, JobDurationCollapseProps, JobDurationSwitchLabel, JobHiddenSwitchLabel,
JobDurationSliderProps,
JobDurationSliderProps, ShowHiddenSwitchProps,
} = useContext(AdvancedSearchControllerContext);

return (
Expand Down Expand Up @@ -104,19 +104,19 @@ const AdvancedSearchDesktop = () => {
}}
/>
<div className={classes.resetBtnWrapper}>
<Button
{...ResetButtonProps}
_id="reset_btn"
color="primary"
onClick={resetAdvancedSearch}
>
Reset Advanced Fields
</Button>
</div>
<Button
{...ResetButtonProps}
_id="reset_btn"
color="primary"
onClick={resetAdvancedSearch}
>
Reset Advanced Fields
</Button>
</div>
{sessionData?.isAdmin &&
<FormControlLabel
className={classes.jobHiddenSliderToggle}
control={<Switch {...JobDurationSwitchProps} />}
control={<Switch {...ShowHiddenSwitchProps} />}
label={JobHiddenSwitchLabel}
/>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export default ({
technologies,
setTechs,
resetAdvancedSearchFields,
showHidden,
setShowHidden,
}) => {

const jobDuration = [jobMinDuration, jobMaxDuration];
Expand Down Expand Up @@ -72,6 +74,15 @@ export default ({
const FieldsSelectorProps = useFieldSelector(fields, setFields);
const TechsSelectorProps = useTechSelector(technologies, setTechs);

const toggleShowHidden = useCallback(() => {
setShowHidden(!showHidden);
}, [setShowHidden, showHidden]);

const ShowHiddenSwitchProps = {
checked: showHidden,
onChange: toggleShowHidden,
value: "filterShowHiddenOffers",
};

const advancedOptionsActive = showJobDurationSlider
|| (jobType !== INITIAL_JOB_TYPE)
Expand Down Expand Up @@ -104,5 +115,6 @@ export default ({
JobDurationSliderProps,
JobDurationSliderText,
ResetButtonProps,
ShowHiddenSwitchProps,
};
};
15 changes: 13 additions & 2 deletions src/components/HomePage/SearchArea/SearchArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
setShowJobDurationSlider,
setTechs,
hideOffer,
setShowHidden,
} from "../../../actions/searchOffersActions";
import { INITIAL_JOB_TYPE, INITIAL_JOB_DURATION } from "../../../reducers/searchOffersReducer";

Expand All @@ -37,7 +38,8 @@ export const AdvancedSearchControllerContext = React.createContext({});
export const AdvancedSearchController = ({
enableAdvancedSearchDefault, showJobDurationSlider, setShowJobDurationSlider, jobMinDuration,
jobMaxDuration, setJobDuration, jobType, setJobType, fields, setFields, technologies, setTechs,
resetAdvancedSearchFields, onSubmit, searchValue, setSearchValue, onMobileClose,
resetAdvancedSearchFields, onSubmit, searchValue, setSearchValue, onMobileClose, showHidden,
setShowHidden,
}) => {

const {
Expand Down Expand Up @@ -73,6 +75,8 @@ export const AdvancedSearchController = ({
setTechs: actualSetTechs,
resetAdvancedSearchFields: actualResetAdvancedSearchFields,
hideOffer,
showHidden,
setShowHidden,
});

const { search: searchOffers } = useOffersSearcher({
Expand All @@ -82,6 +86,7 @@ export const AdvancedSearchController = ({
jobType,
fields,
technologies,
showHidden,
});

const submitForm = useCallback((e, updateUrl = true) => {
Expand Down Expand Up @@ -126,7 +131,8 @@ export const AdvancedSearchController = ({
export const SearchArea = ({ onSubmit, searchValue,
jobMinDuration = INITIAL_JOB_DURATION, jobMaxDuration = INITIAL_JOB_DURATION + 1, jobType = INITIAL_JOB_TYPE,
fields, technologies, showJobDurationSlider, setShowJobDurationSlider, advanced: enableAdvancedSearchDefault = false,
setSearchValue, setJobDuration, setJobType, setFields, setTechs, resetAdvancedSearchFields, onMobileClose }) => {
setSearchValue, setJobDuration, setJobType, setFields, setTechs, resetAdvancedSearchFields, onMobileClose, showHidden,
setShowHidden }) => {

const classes = useSearchAreaStyles();
const {
Expand All @@ -142,6 +148,7 @@ export const SearchArea = ({ onSubmit, searchValue,
enableAdvancedSearchDefault, showJobDurationSlider, setShowJobDurationSlider, jobMinDuration,
jobMaxDuration, setJobDuration, jobType, setJobType, fields, setFields, technologies, setTechs,
resetAdvancedSearchFields, hideOffer, onSubmit, searchValue, setSearchValue, onMobileClose,
showHidden, setShowHidden,
},
AdvancedSearchControllerContext
);
Expand Down Expand Up @@ -202,6 +209,8 @@ SearchArea.propTypes = {
setTechs: PropTypes.func.isRequired,
setShowJobDurationSlider: PropTypes.func.isRequired,
onMobileClose: PropTypes.func,
showHidden: PropTypes.bool,
setShowHidden: PropTypes.func,
advanced: PropTypes.bool,
};

Expand All @@ -213,6 +222,7 @@ export const mapStateToProps = ({ offerSearch }) => ({
fields: offerSearch.fields,
technologies: offerSearch.technologies,
showJobDurationSlider: offerSearch.filterJobDuration,
showHidden: offerSearch.showHidden,
});

export const mapDispatchToProps = (dispatch) => ({
Expand All @@ -222,6 +232,7 @@ export const mapDispatchToProps = (dispatch) => ({
setFields: (fields) => dispatch(setFields(fields)),
setTechs: (technologies) => dispatch(setTechs(technologies)),
setShowJobDurationSlider: (val) => dispatch(setShowJobDurationSlider(val)),
setShowHidden: (val) => dispatch(setShowHidden(val)),
resetAdvancedSearchFields: () => dispatch(resetAdvancedSearchFields()),
});

Expand Down
1 change: 0 additions & 1 deletion src/components/HomePage/SearchArea/searchAreaStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,5 @@ export default makeStyles((theme) => ({
jobHiddenSliderToggle: {
gridRowStart: 4,
gridColumnStart: 2,

},
}));
6 changes: 6 additions & 0 deletions src/reducers/searchOffersReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const initialState = {
offers: [],
loading: false,
error: INITIAL_ERROR,
showHidden: false,
};

export default (state = initialState, action) => {
Expand Down Expand Up @@ -107,6 +108,11 @@ export default (state = initialState, action) => {
new Offer({ ...offer, isHidden: false, hiddenReason: null, adminReason: null })
: offer
) };
case OfferSearchTypes.SET_SHOW_HIDDEN:
return {
...state,
showHidden: action.showHidden,
};
default:
return state;
}
Expand Down

0 comments on commit 04a1c18

Please sign in to comment.