Skip to content

Commit

Permalink
refactor: shared card wrapper component
Browse files Browse the repository at this point in the history
  • Loading branch information
johnshift committed Mar 18, 2024
1 parent b636e8c commit db354af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/jobs/components/job-card/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import Link from 'next/link';

import { CardWrapper } from '~/shared/components/card-wrapper';
import { Divider } from '~/shared/components/divider';
import { Heading } from '~/shared/components/heading';

import { JOB_TEST_IDS } from '~/jobs/core/constants';
import { JobDetails } from '~/jobs/core/schemas';
import { createJobCardInfoTags } from '~/jobs/utils/create-job-card-info-tags';
import { activeJobIdAtom } from '~/jobs/atoms/active-job-id-atom';
import { JobSkills } from '~/jobs/components/job-skills';

import { JobCardClientWrapper } from './client-wrapper';
import { JobCardInfoTags } from './info-tags';
import { JobCardOrg } from './org';
import { JobCardProjects } from './projects';
Expand All @@ -25,7 +26,7 @@ export const JobCard = ({ job, isInit, filterParamsString = '' }: Props) => {
const jobTags = createJobCardInfoTags(job);

return (
<JobCardClientWrapper id={shortUUID}>
<CardWrapper id={shortUUID} idAtom={activeJobIdAtom}>
<Link
className="flex flex-col gap-3 p-6"
href={`/jobs/${shortUUID}/details${filterParamsString}`}
Expand Down Expand Up @@ -61,6 +62,6 @@ export const JobCard = ({ job, isInit, filterParamsString = '' }: Props) => {
<JobCardTsBookmark timestamp={timestamp} />
</div>
</Link>
</JobCardClientWrapper>
</CardWrapper>
);
};
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
'use client';

import { useAtom } from 'jotai';
import { PrimitiveAtom, useAtom } from 'jotai';

import { cn } from '~/shared/utils/cn';

import { activeJobIdAtom } from '~/jobs/atoms/active-job-id-atom';

interface Props {
id: string;
idAtom: PrimitiveAtom<string | null>;
children: React.ReactNode;
}

export const JobCardClientWrapper = ({ id, children }: Props) => {
const [activeJobId, setActiveJobId] = useAtom(activeJobIdAtom);
const isActive = id === activeJobId;
export const CardWrapper = ({ id, idAtom, children }: Props) => {
const [activeId, setActiveId] = useAtom(idAtom);
const isActive = activeId === id;

const onClickCard = () => {
setActiveJobId(id);
const onClick = () => {
setActiveId(id);
};

return (
Expand All @@ -28,7 +27,7 @@ export const JobCardClientWrapper = ({ id, children }: Props) => {
isActive,
},
)}
onClick={onClickCard}
onClick={onClick}
>
{children}
</div>
Expand Down

0 comments on commit db354af

Please sign in to comment.