Repository navigation
Split the booking-page template into a folder of focused files #1721
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d0b3681
WIP: split reservations.tsx (1896 lines) into reservations/ folder — …
stefan-burke f6c1d18
Fix 11 jscpd clones the reservations split surfaced (0% dup, green)
stefan-burke 0784cd9
Merge origin/main into split-reservations
stefan-burke 0e553fe
Merge origin/main into split-reservations (2nd update)
stefan-burke b3f06eb
Resolve PR review comments: fix child-ctx suppression bug, XSS, FP st…
stefan-burke c5660f5
Cover the scheduleNextRefresh stopped-guard (stripe-mock install.ts:157)
stefan-burke 0ce8381
Merge origin/main into split-reservations (3rd update)
stefan-burke d20364b
Merge origin/main into split-reservations (3rd update, complete)
stefan-burke 57c19d7
Merge remote-tracking branch 'origin/main' into split-reservations
stefan-burke 5230392
Merge remote-tracking branch 'origin/main' into split-reservations
stefan-burke 5366ed2
Replace wall-clock timing in stripe-mock test with deterministic sign…
stefan-burke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /** Page-level availability and tree-shaping: the unavailability message, the | ||
| * booking tree plus which listings get their own standalone row, the overall | ||
| * sold-out check, and the lone header listing whose details head the page. */ | ||
|
|
||
| /* jscpd:ignore-start */ | ||
| import { t } from "#i18n"; | ||
| import { | ||
| type BuildTreeInput, | ||
| buildBookingTree, | ||
| } from "#shared/booking/build-tree.ts"; | ||
| import type { TicketListing } from "#shared/booking/model.ts"; | ||
| import { | ||
| type PackageLimitInfo, | ||
| pageBundleLimits, | ||
| } from "#shared/booking/package-cap.ts"; | ||
| import type { PagePackage } from "#shared/booking/page-packages.ts"; | ||
| import type { BookingNode, BookingTree } from "#shared/booking/tree.ts"; | ||
| import { standaloneListingIds } from "#shared/booking/tree.ts"; | ||
| import { isReadOnly } from "#shared/env.ts"; | ||
| import type { ListingWithCount } from "#shared/types.ts"; | ||
| /* jscpd:ignore-end */ | ||
|
|
||
| /** Unavailability message shown when all listings are sold out or closed */ | ||
| export const unavailableMessage = ( | ||
| allClosed: boolean, | ||
| isSingleListing: boolean, | ||
| ): string => { | ||
| if (isReadOnly() || allClosed) return t("public.ticket.registration_closed"); | ||
| return isSingleListing | ||
| ? t("public.ticket.listing_full") | ||
| : t("public.multi.all_sold_out"); | ||
| }; | ||
|
|
||
| /** Each page package's bundle limit, plus whether the whole page should show as | ||
| * sold out (nothing standalone left AND no package bookable). */ | ||
| export const packagePageAvailability = ( | ||
| packages: PagePackage[], | ||
| tree: BookingTree, | ||
| listings: TicketListing[], | ||
| standaloneRowIds: ReadonlySet<number>, | ||
| page: PackageLimitInfo, | ||
| ): { packageLimits: Map<number, number>; soldOut: boolean } => { | ||
| const packageLimits = pageBundleLimits(tree, packages, page); | ||
| const standaloneUnavailable = listings | ||
| .filter((info) => standaloneRowIds.has(info.listing.id)) | ||
| .every((e) => e.isSoldOut || e.isClosed); | ||
| const packagesUnavailable = [...packageLimits.values()].every( | ||
| (limit) => limit === 0, | ||
| ); | ||
| return { | ||
| packageLimits, | ||
| // Sold out only when every standalone row AND every bundle is dead (a | ||
| // bundle with an unavailable member already reads limit 0; a package-less | ||
| // page has no bundles, leaving just its listings' own availability). | ||
| soldOut: standaloneUnavailable && packagesUnavailable, | ||
| }; | ||
| }; | ||
|
|
||
| /** The lone listing whose rich details (image/date/location) head the page and | ||
| * feed its OpenGraph tags, or null for a multi-listing page OR a hidden package | ||
| * — a hidden package with one active member must not expose that member here. */ | ||
| export const headerListing = ( | ||
| listings: TicketListing[], | ||
| packages: PagePackage[], | ||
| ): ListingWithCount | null => | ||
| listings.length === 1 && !packages.some((pkg) => pkg.hideListings) | ||
| ? listings[0]!.listing | ||
| : null; | ||
|
|
||
| /** Build the page's booking tree and the row-shaping facts read off it: which | ||
| * listings get their own quantity row (those with a standalone BUYER_CHOICE | ||
| * node), which node each row reads its field names from (a dual-path listing | ||
| * resolves to its standalone node, not its member node), and whether the page | ||
| * IS one package (every listing a member, nothing sold beside it — the classic | ||
| * package-page layout). */ | ||
| export const buildPageTree = ( | ||
| input: BuildTreeInput, | ||
| packageCount: number, | ||
| ): { | ||
| tree: BookingTree; | ||
| standaloneRowIds: Set<number>; | ||
| nodeByListingId: Map<number, BookingNode>; | ||
| singlePackagePage: boolean; | ||
| } => { | ||
| const tree = buildBookingTree(input); | ||
| const standaloneRowIds = standaloneListingIds(tree); | ||
| const nodeByListingId = new Map<number, BookingNode>(); | ||
| for (const node of tree.nodes) { | ||
| if ( | ||
| !nodeByListingId.has(node.listingId) || | ||
| node.quantityRule.kind === "BUYER_CHOICE" | ||
| ) { | ||
| nodeByListingId.set(node.listingId, node); | ||
| } | ||
| } | ||
| return { | ||
| nodeByListingId, | ||
| singlePackagePage: packageCount === 1 && standaloneRowIds.size === 0, | ||
| standaloneRowIds, | ||
| tree, | ||
| }; | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.