Skip to content
Open
Changes from all commits
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
125 changes: 69 additions & 56 deletions 03-router-and-zustand/src/components/JobCard.jsx
Original file line number Diff line number Diff line change
@@ -1,66 +1,79 @@
import { useState } from "react"
import { Link } from "./Link"
import styles from './JobCard.module.css'
import { useFavoritesStore } from "../store/favoritesStore"
import { useAuthStore } from "../store/authStore"
import { useState } from "react";
import { Link } from "./Link";
import styles from "./JobCard.module.css";
import { useFavoritesStore } from "../store/favoritesStore";
import { useAuthStore } from "../store/authStore";

function JobCardFavoriteButton ({ jobId }) {
const { isLoggedIn } = useAuthStore()
// suscríbete a TODA la store y extra TODA la store
const { toggleFavorite, isFavorite } = useFavoritesStore()
function JobCardFavoriteButton({ jobId }) {
const { isLoggedIn } = useAuthStore();
// suscríbete a TODA la store y extra TODA la store
const toggleFavorite = useFavoritesStore((state) => state.toggleFavorite);
const isFavorite = useFavoritesStore((state) =>
state.favorites.includes(jobId)
);

return (
<button
disabled={!isLoggedIn}
onClick={() => toggleFavorite(jobId)}
aria-label={isFavorite(jobId) ? 'Remove from favorites' : 'Add to favorites'}
>
{isFavorite(jobId) ? '❤️' : '🤍'}
</button>
)
return (
<button
disabled={!isLoggedIn}
onClick={() => toggleFavorite(jobId)}
aria-label={isFavorite ? "Remove from favorites" : "Add to favorites"}
>
{isFavorite ? "❤️" : "🤍"}
</button>
);
}

function JobCardApplyButton ({ jobId }) {
const [isApplied, setIsApplied] = useState(false)
const { isLoggedIn } = useAuthStore()
function JobCardApplyButton({ jobId }) {
const [isApplied, setIsApplied] = useState(false);
const { isLoggedIn } = useAuthStore();

const buttonClasses = isApplied ? 'button-apply-job is-applied' : 'button-apply-job'
const buttonText = isApplied ? 'Aplicado' : 'Aplicar'
const buttonClasses = isApplied
? "button-apply-job is-applied"
: "button-apply-job";
const buttonText = isApplied ? "Aplicado" : "Aplicar";

const handleApplyClick = () => {
console.log('Aplicando al trabajo con id:', jobId)
setIsApplied(true)
}
const handleApplyClick = () => {
console.log("Aplicando al trabajo con id:", jobId);
setIsApplied(true);
};

return (
<button disabled={!isLoggedIn} className={buttonClasses} onClick={handleApplyClick}>{buttonText}</button>
)
return (
<button
disabled={!isLoggedIn}
className={buttonClasses}
onClick={handleApplyClick}
>
{buttonText}
</button>
);
}

export function JobCard({ job }) {
return (
<article
className="job-listing-card"
data-modalidad={job.data.modalidad}
data-nivel={job.data.nivel}
data-technology={job.data.technology}
>
<div>
<h3>
<Link className={styles.title} href={`/jobs/${job.id}`}>
{job.titulo}
</Link>
</h3>
<small>{job.empresa} | {job.ubicacion}</small>
<p>{job.descripcion}</p>
</div>
<div className={styles.actions}>
<Link href={`/jobs/${job.id}`} className={styles.details}>
Ver detalles
</Link>
<JobCardApplyButton jobId={job.id} />
<JobCardFavoriteButton jobId={job.id} />
</div>
</article>
)
}
return (
<article
className="job-listing-card"
data-modalidad={job.data.modalidad}
data-nivel={job.data.nivel}
data-technology={job.data.technology}
>
<div>
<h3>
<Link className={styles.title} href={`/jobs/${job.id}`}>
{job.titulo}
</Link>
</h3>
<small>
{job.empresa} | {job.ubicacion}
</small>
<p>{job.descripcion}</p>
</div>
<div className={styles.actions}>
<Link href={`/jobs/${job.id}`} className={styles.details}>
Ver detalles
</Link>
<JobCardApplyButton jobId={job.id} />
<JobCardFavoriteButton jobId={job.id} />
</div>
</article>
);
}