Skip to content

Commit

Permalink
Show current age on performer info screen (#845)
Browse files Browse the repository at this point in the history
  • Loading branch information
InfiniteStash authored Dec 2, 2024
1 parent 8d43659 commit 1fb0229
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
8 changes: 4 additions & 4 deletions frontend/src/hooks/useBeforeUnload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { useEffect } from "react";
export const useBeforeUnload = () => {
const unloadListener = (event: BeforeUnloadEvent) => {
event.preventDefault();
event.returnValue = true
}
event.returnValue = true;
};
useEffect(() => {
window.addEventListener("beforeunload", unloadListener);
}, []);
return () => window.removeEventListener("beforeunload", unloadListener)
}
return () => window.removeEventListener("beforeunload", unloadListener);
};
20 changes: 19 additions & 1 deletion frontend/src/pages/performers/components/performerInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FC, useContext } from "react";
import { parseISO, differenceInYears } from "date-fns";
import { Link } from "react-router-dom";
import { Button, Card, Col, Row, Table } from "react-bootstrap";
import { faCodeMerge } from "@fortawesome/free-solid-svg-icons";
Expand Down Expand Up @@ -86,11 +87,25 @@ const Actions: FC<Props> = ({ performer }) => {
);
};

const PerformerAge = ({
birthdate,
}: {
birthdate?: null | string;
}): React.ReactNode => {
if (!birthdate) return "";
const date = parseISO(birthdate);
if (!date) return "";

const age = differenceInYears(new Date(), date);
return <small className="text-muted ms-2">{`${age} years old`}</small>;
};

export const PerformerInfo: FC<Props> = ({ performer }) => {
const { data: mergedInto } = usePerformer(
{ id: performer.merged_into_id ?? "" },
!performer.merged_into_id,
);

return (
<div className={CLASSNAME}>
<Actions performer={performer} />
Expand Down Expand Up @@ -134,7 +149,10 @@ export const PerformerInfo: FC<Props> = ({ performer }) => {
</tr>
<tr>
<td>Birthdate</td>
<td>{performer.birth_date}</td>
<td>
{performer.birth_date}
<PerformerAge birthdate={performer.birth_date} />
</td>
</tr>
<tr>
<td>Height</td>
Expand Down

0 comments on commit 1fb0229

Please sign in to comment.