Skip to content

Commit

Permalink
2927: Split poster single up into components
Browse files Browse the repository at this point in the history
  • Loading branch information
tuj committed Feb 5, 2025
1 parent bf3214f commit 195cbe9
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 88 deletions.
80 changes: 80 additions & 0 deletions src/components/slide/content/poster/poster-single-events.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { Button } from "react-bootstrap";
import { React } from "react";
import PropTypes from "prop-types";
import { useTranslation } from "react-i18next";
import { formatDate } from "./poster-helper";

/**
* @param {object} props The props.
* @param {Array} props.events The events to present.
* @param {Function} props.handleSelectEvent Handle select event.
* @returns {React.JSX.Element} The events list component.
*/
function PosterSingleEvents({ events, handleSelectEvent }) {
const { t } = useTranslation("common", { keyPrefix: "poster-selector-v2" });

return (
<table className="table table-hover text-left">
<thead>
<tr>
<th scope="col">{t("table-image")}</th>
<th scope="col">{t("table-event")}</th>
<th scope="col">{t("table-date")}</th>
<th scope="col" aria-label={t("table-actions")} />
</tr>
</thead>
<tbody>
{events?.map(
({ entityId, title, imageUrls, organizer, occurrences }) => (
<tr key={entityId}>
<td>
{imageUrls?.small && (
<img
src={imageUrls?.small}
alt={t("search-result-image")}
style={{ maxWidth: "80px" }}
/>
)}
</td>
<td>
<b>{title}</b>
<br />
{organizer?.name}
</td>
<td>
{occurrences?.length > 0 && formatDate(occurrences[0]?.start)}
{occurrences?.length > 1 && <span>, ...</span>}
</td>
<td>
<Button
onClick={() =>
handleSelectEvent(
entityId,
occurrences.map(
({ entityId: occurrenceEntityId }) => occurrenceEntityId
)
)
}
>
{t("choose-event")}
</Button>
</td>
</tr>
)
)}
{events?.length === 0 && (
<tr>
<td colSpan="3">{t("no-results")}</td>
</tr>
)}
</tbody>
</table>
);
}

PosterSingleEvents.propTypes = {
events: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
handleSelectEvent: PropTypes.func.isRequired,
};

export default PosterSingleEvents;
56 changes: 56 additions & 0 deletions src/components/slide/content/poster/poster-single-occurences.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Button } from "react-bootstrap";
import { React } from "react";
import PropTypes from "prop-types";
import { useTranslation } from "react-i18next";
import { formatDate } from "./poster-helper";

/**
* @param {object} props The props.
* @param {Array} props.occurrences The occurrences.
* @param {Function} props.handleSelectOccurrence The select callback.
* @returns {React.JSX.Element} The occurrences list component.
*/
function PosterSingleOccurrences({ occurrences, handleSelectOccurrence }) {
const { t } = useTranslation("common", { keyPrefix: "poster-selector-v2" });

return (
<>
<h5>{t("choose-an-occurrence")}</h5>
<table className="table table-hover text-left">
<thead>
<tr>
<th scope="col">{t("table-date")}</th>
<th scope="col">{t("table-price")}</th>
<th scope="col" aria-label={t("table-actions")} />
</tr>
</thead>
<tbody>
{occurrences.map(({ entityId, start, ticketPriceRange }) => (
<tr key={entityId}>
<td>{formatDate(start)}</td>
<td>{ticketPriceRange}</td>
<td>
<Button onClick={() => handleSelectOccurrence(entityId)}>
{t("choose-occurrence")}
</Button>
</td>
</tr>
))}
</tbody>
</table>
</>
);
}

PosterSingleOccurrences.propTypes = {
occurrences: PropTypes.arrayOf(
PropTypes.shape({
entityId: PropTypes.number.isRequired,
start: PropTypes.string.isRequired,
ticketPriceRange: PropTypes.string.isRequired,
})
).isRequired,
handleSelectOccurrence: PropTypes.func.isRequired,
};

export default PosterSingleOccurrences;
98 changes: 10 additions & 88 deletions src/components/slide/content/poster/poster-single.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Col from "react-bootstrap/Col";
import { formatDate, getHeaders } from "./poster-helper";
import PosterSingleOverride from "./poster-single-override";
import PosterSingleSearch from "./poster-single-search";
import PosterSingleEvents from "./poster-single-events.jsx";
import PosterSingleOccurrences from "./poster-single-occurences.jsx";

/**
* @param {object} props Props.
Expand Down Expand Up @@ -203,101 +205,21 @@ function PosterSingle({ configurationChange, feedSource, configuration }) {

{singleSearchEvents && (
<Row className="mb-2">
<table className="table table-hover text-left">
<thead>
<tr>
<th scope="col">{t("table-image")}</th>
<th scope="col">{t("table-event")}</th>
<th scope="col">{t("table-date")}</th>
<th scope="col" aria-label={t("table-actions")} />
</tr>
</thead>
<tbody>
{singleSearchEvents?.map(
({
entityId,
title,
imageUrls,
organizer,
occurrences,
}) => (
<tr key={entityId}>
<td>
{imageUrls?.small && (
<img
src={imageUrls?.small}
alt={t("search-result-image")}
style={{ maxWidth: "80px" }}
/>
)}
</td>
<td>
<b>{title}</b>
<br />
{organizer?.name}
</td>
<td>
{occurrences?.length > 0 &&
formatDate(occurrences[0]?.start)}
{occurrences?.length > 1 && <span>, ...</span>}
</td>
<td>
<Button
onClick={() =>
handleSelectEvent(
entityId,
occurrences.map(
({ entityId: occurrenceEntityId }) =>
occurrenceEntityId
)
)
}
>
{t("choose-event")}
</Button>
</td>
</tr>
)
)}
{singleSearchEvents?.length === 0 && (
<tr>
<td colSpan="3">{t("no-results")}</td>
</tr>
)}
</tbody>
</table>
<PosterSingleEvents
handleSelectEvent={handleSelectEvent}
events={singleSearchEvents}
/>
</Row>
)}
</>
)}

{singleSelectedEvent !== null && singleSelectedOccurrence === null && (
<Row className="mb-2">
<h5>{t("choose-an-occurrence")}</h5>
<table className="table table-hover text-left">
<thead>
<tr>
<th scope="col">{t("table-date")}</th>
<th scope="col">{t("table-price")}</th>
<th scope="col" aria-label={t("table-actions")} />
</tr>
</thead>
<tbody>
{singleSelectedEvent.occurrences.map(
({ entityId, start, ticketPriceRange }) => (
<tr key={entityId}>
<td>{formatDate(start)}</td>
<td>{ticketPriceRange}</td>
<td>
<Button onClick={() => handleSelectOccurrence(entityId)}>
{t("choose-occurrence")}
</Button>
</td>
</tr>
)
)}
</tbody>
</table>
<PosterSingleOccurrences
occurrences={singleSelectedEvent.occurrences}
handleSelectOccurrence={handleSelectOccurrence}
/>
</Row>
)}
</>
Expand Down

0 comments on commit 195cbe9

Please sign in to comment.