diff --git a/actions/job_actions.js b/actions/job_actions.js index aed4f6f..9220677 100644 --- a/actions/job_actions.js +++ b/actions/job_actions.js @@ -3,7 +3,8 @@ import reverseGeocode from 'latlng-to-zip'; import qs from 'qs'; import { - FETCH_JOBS + FETCH_JOBS, + LIKE_JOB } from './types'; const JOB_ROOT_URL = 'http://api.indeed.com/ads/apisearch?'; @@ -32,4 +33,11 @@ export const fetchJobs = (region, callback) => async (dispatch) => { console.error(e); } -}; \ No newline at end of file +}; + +export const likeJob = (job) => { + return { + payload: job, + type: LIKE_JOB + }; +}; diff --git a/actions/types.js b/actions/types.js index ef378da..91a6aec 100644 --- a/actions/types.js +++ b/actions/types.js @@ -1,3 +1,4 @@ export const FACEBOOK_LOGIN_SUCCESS = 'facebook_login_success'; export const FACEBOOK_LOGIN_FAIL = 'facebook_login_fail'; export const FETCH_JOBS = 'fetch_jobs'; +export const LIKE_JOB = 'like_job'; diff --git a/reducers/index.js b/reducers/index.js index 2314000..a5f7131 100644 --- a/reducers/index.js +++ b/reducers/index.js @@ -1,7 +1,8 @@ import { combineReducers } from "redux"; import auth from "./auth_reducer"; import jobs from "./jobs_reducer"; +import likedJobs from "./likes_reducer"; export default combineReducers({ - auth, jobs + auth, jobs, likedJobs }); \ No newline at end of file diff --git a/reducers/likes_reducer.js b/reducers/likes_reducer.js new file mode 100644 index 0000000..7adf67b --- /dev/null +++ b/reducers/likes_reducer.js @@ -0,0 +1,16 @@ +import _ from 'lodash'; +import { + LIKE_JOB +} from '../actions/types'; + +export default function(state = [], action) { + switch (action.type) { + case LIKE_JOB: + // only return unique jobs + return _.uniqBy([ + action.payload, ...state + ], 'jobkey'); + default: + return state; + } +} \ No newline at end of file