Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #7 from AJRedDevil/develop
Browse files Browse the repository at this point in the history
Location
  • Loading branch information
AjanShrestha authored Dec 23, 2019
2 parents 7a221a8 + 75c7554 commit 2f2e409
Show file tree
Hide file tree
Showing 5 changed files with 267 additions and 3 deletions.
17 changes: 16 additions & 1 deletion client/src/App.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
body {
margin: 20 40px;
margin: 20px 40px;
background-color: rgb(56, 62, 63);
color: white;
}

.job {
Expand Down Expand Up @@ -28,3 +30,16 @@ body {
.job-title-location {
margin-left: 20px;
}

.location {
width: 50%;
display: flex;
justify-content: space-between;
margin: 20px 0;
padding: 20px 10px;
}

.location:hover {
cursor: pointer;
color: #666666;
}
16 changes: 14 additions & 2 deletions client/src/Jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,19 @@ import KeyboardArrowRight from '@material-ui/icons/KeyboardArrowRight';

import Job from './Job';
import JobModal from './JobModal';
import LocationRadio from './LocationRadio';
import {filterJobsByLocation} from './utils';

export default function Jobs({jobs}) {
// location radio section
const [location, setLocation] = React.useState('all');
const handleLocationChange = event => {
setLocation(event.target.value);
};

// filter jobs based on location
const filteredJobs = filterJobsByLocation(jobs, location);

// modal
const [open, setOpen] = React.useState(false);
const [selectedJob, selectJob] = React.useState([]);
Expand All @@ -20,10 +31,10 @@ export default function Jobs({jobs}) {
};

// pagination
const numJobs = jobs.length;
const numJobs = filteredJobs.length;
const numPages = Math.ceil(numJobs / 50);
const [activeStep, setActiveStep] = React.useState(0);
const jobsOnPage = jobs.slice(activeStep * 50, activeStep * 50 + 50);
const jobsOnPage = filteredJobs.slice(activeStep * 50, activeStep * 50 + 50);

// step == 0, show 0-49
// step == 1, show 50-99
Expand Down Expand Up @@ -55,6 +66,7 @@ export default function Jobs({jobs}) {
<Typography variant="h6" component="h2">
Found {numJobs} Jobs
</Typography>
<LocationRadio value={location} handleChange={handleLocationChange} />
{jobsOnPage.map((job, i) => (
<Job
key={i}
Expand Down
52 changes: 52 additions & 0 deletions client/src/LocationRadio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react';
import Paper from '@material-ui/core/Paper';
import Radio from '@material-ui/core/Radio';
import RadioGroup from '@material-ui/core/RadioGroup';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import FormControl from '@material-ui/core/FormControl';
import FormLabel from '@material-ui/core/FormLabel';

export default function LocationRadio({value, handleChange}) {
return (
<Paper className="location">
<div className="flex-align-md">
<FormControl component="fieldset">
<FormLabel component="legend">Location</FormLabel>
<RadioGroup
aria-label="position"
name="location"
value={value}
onChange={handleChange}
row
color="default"
>
<FormControlLabel
value="all"
control={<Radio color="default" />}
label="All"
labelPlacement="start"
/>
<FormControlLabel
value="us"
control={<Radio color="default" />}
label="U.S."
labelPlacement="start"
/>
<FormControlLabel
value="international"
control={<Radio color="default" />}
label="International"
labelPlacement="start"
/>
<FormControlLabel
value="remote"
control={<Radio color="default" />}
label="Remote"
labelPlacement="start"
/>
</RadioGroup>
</FormControl>
</div>
</Paper>
);
}
138 changes: 138 additions & 0 deletions client/src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
export const stateNames = [
'Alabama',
'Alaska',
'American Samoa',
'Arizona',
'Arkansas',
'California',
'Colorado',
'Connecticut',
'Delaware',
'District of Columbia',
'Federated States of Micronesia',
'Florida',
'Georgia',
'Guam',
'Hawaii',
'Idaho',
'Illinois',
'Indiana',
'Iowa',
'Kansas',
'Kentucky',
'Louisiana',
'Maine',
'Marshall Islands',
'Maryland',
'Massachusetts',
'Michigan',
'Minnesota',
'Mississippi',
'Missouri',
'Montana',
'Nebraska',
'Nevada',
'New Hampshire',
'New Jersey',
'New Mexico',
'New York',
'North Carolina',
'North Dakota',
'Northern Mariana Islands',
'Ohio',
'Oklahoma',
'Oregon',
'Palau',
'Pennsylvania',
'Puerto Rico',
'Rhode Island',
'South Carolina',
'South Dakota',
'Tennessee',
'Texas',
'Utah',
'Vermont',
'Virgin Island',
'Virginia',
'Washington',
'West Virginia',
'Wisconsin',
'Wyoming',
];

export const stateAbbrevs = [
'AK',
'AL',
'AR',
'AZ',
'CA',
'CO',
'CT',
'DC',
'DE',
'FL',
'GA',
'HI',
'IA',
'ID',
'IL',
'IN',
'KS',
'KY',
'LA',
'MA',
'MD',
'ME',
'MI',
'MN',
'MO',
'MS',
'MT',
'NC',
'ND',
'NE',
'NH',
'NJ',
'NM',
'NV',
'NY',
'OH',
'OK',
'OR',
'PA',
'RI',
'SC',
'SD',
'TN',
'TX',
'UT',
'VA',
'VT',
'WA',
'WI',
'WV',
'WY',
];

// common us cities
export const USCityNames = [
'Austin',
'San Francisco',
'Los Angeles',
'Denver',
'Houston',
'Portland',
'Seattle',
'Dallas',
'Boston',
'D.C.',
'Baltimore',
'Atlanta',
'Chicago',
'St. Louis',
'St Louis',
'Miami',
'Orlando',
'Nashville',
'New Orleans',
];
47 changes: 47 additions & 0 deletions client/src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {stateNames, stateAbbrevs, USCityNames} from './constants';

const jobIsRemote = job =>
job.location.toLowerCase().includes('remote') ||
job.location.toLowerCase().includes('anywhere');
const jobIsInUs = job => {
return (
stateNames.some(stateName =>
job.location.toLowerCase().includes(stateName.toLowerCase())
) ||
stateAbbrevs.some(stateAbbrev => {
const abbrev = new RegExp(`\\b${stateAbbrev}\\b`, 'gi');
return abbrev.test(job.location);
}) ||
USCityNames.some(cityName => {
return job.location.toLowerCase().includes(cityName.toLowerCase());
})
);
};
const jobIsNotInUS = job => {
return (
stateNames.every(
state => !job.location.toLowerCase().includes(state.toLowerCase())
) &&
stateAbbrevs.every(stateAbbrev => {
const abbrev = new RegExp(`\\b${stateAbbrev}\\b`, 'gi');
return !abbrev.test(job.location);
}) &&
USCityNames.every(cityName => {
return !job.location.toLowerCase().includes(cityName.toLowerCase());
}) &&
!jobIsRemote(job)
);
};

export const filterJobsByLocation = (jobs, location) => {
switch (location) {
case 'us':
return jobs.filter(jobIsInUs);
case 'international':
return jobs.filter(jobIsNotInUS);
case 'remote':
return jobs.filter(jobIsRemote);
default:
return jobs;
}
};

0 comments on commit 2f2e409

Please sign in to comment.