Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple locations on job listings #674

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/jobs/list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ export type JobItem = {
name: string;
title: string;
location: string;
locations: Array<Location>;
};

export type Location = {
city: string;
state: string;
country: string;
street: string;
};
export type JobListingItemProps = {
item: JobItem;
Expand All @@ -16,9 +24,16 @@ export default function JobListingItem({ item }: JobListingItemProps) {
<section className={style.job__listing__container}>
<div>
<h3 className={and(style.job__title, 'fancy')}>{item.title}</h3>
<span>{item.location}</span>
<span>
{`${item.locations.map((location) => {
return ' ' + location.city;
})}`}
Copy link
Member

@itzjacki itzjacki Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{`${item.locations.map((location) => {
return ' ' + location.city;
})}`}
{item.locations.map((location) => {
return ' ' + location.city;
}).toString()}

Kunne man bare tatt bort disse? Evt med en toString() dersom jsx ikke gjør det for oss

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Av en eller annen uforklarlig grunn (for meg) sørger ${}for å automatisk legge på komma mellom elementene. Det finnes sikkert en god grunn til hvorfor, men jeg tenkte at det var bedre å beholde de automagiske kommaene, enn å lage noe som ordna komma selv 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Det blir om til en array som gjøres toString når det template literals inn og da blir det automatisk komma. Om du vil gjøre det "korrekt" så kan det være slik:

          {item.locations.map((location) => {
            return location.city;
          }).join(', ')}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nå snakker vi, takk!

Copy link
Member

@itzjacki itzjacki Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Har oppdatert forslaget mitt med en toString() som ser ut til å gjøre så man får med seg kommaene. Kommer om forskjeller på hvordan jsx og toString()-funksjonen konkatinerer arrays når den skal stringifisere de. ${``} er i praksis det samme som toString(), bare litt mindre eksplisitt.

Er ikke egentlig så viktig dette altså, men når jeg først kommenterte på det kan jeg like godt følge det opp 😅

Edit: Hadde jeg refresha sida hadde jeg sett at Mikael allerede hadde forklart og kommet med et bedre forslag. Ups.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meeeen Mikael sitt forslag er mer eksplisitt, så støtter det i stedet 🥇

</span>
</div>
<ButtonNextLink href={`/jobs/${item.name}`} aria-label={`Se på stillingen ${item.title} ${item.location}`}>
<ButtonNextLink
href={`/jobs/${item.name}`}
aria-label={`Se på stillingen ${item.title} ${item.location}`}
>
Se på stillingen
</ButtonNextLink>
</section>
Expand Down
9 changes: 9 additions & 0 deletions src/jobs/utils/getListings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,17 @@ type Offer = {
position: number;
department?: string;
location: string;
locations: Array<Location>;
company_name: string;
};

type Location = {
city: string,
state: string,
country: string,
street: string,
}

type OfferResult = {
offers: Array<Offer>;
};
Expand All @@ -92,6 +100,7 @@ async function getValidityStatuses(department?: Office): Promise<Offer[]> {

let offers: Offer[] = [];
for (let offer of data.offers) {
console.log(offer.locations);
Krakels marked this conversation as resolved.
Show resolved Hide resolved
if (!offer.careers_apply_url) {
throw new Error('Could not fetch data from Recruitee');
}
Expand Down
Loading