Skip to content
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

Restyle amendments to toggle more affected items #700

Merged
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
101 changes: 53 additions & 48 deletions src/customHooks/useDisruptionAffectedItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,54 +124,59 @@ const useDisruptionAffectedItems = (disruption) => {
</>
)}
{/* Affected stops / Tram */}
{disruption.mode === 'tram' && disruption?.servicesAffected && disruption?.stopsAffected && (
<>
{disruption.stopsAffected
.sort((a, b) => {
// Convert stop name text to lowercase
const x = a.name.toLowerCase();
const y = b.name.toLowerCase();
// Return minus or plus values when comparing prev/next string. This ensures alphabetical sorting.
if (x < y) return -1;
if (x > y) return 1;
return 0;
})
// Sort again to move a user's selected items to the front so it's not "hidden" behind the button
.sort((a, b) => {
const atcoCodeA = a.atcoCode;
const atcoCodeB = b.atcoCode;
if (atcoCodeA === selectedItem?.id || atcoCodeA === selectedItemTo?.id) return -1;
return atcoCodeB === selectedItem?.id || atcoCodeB === selectedItemTo?.id ? 1 : 0;
})
.slice(0, sliceUpper)
.map((affected) => (
<FavBtn
id={affected.atcoCode}
severity={disruption.disruptionSeverity}
text={affected.name.replace(' (Midland Metro Stop)', '')}
title={disruption?.servicesAffected[0]?.routeDescriptions[0]?.description}
mode={disruption.mode}
key={affected.atcoCode}
narrow
/>
))}
<div className="wmnds-m-t-md">
{disruption.stopsAffected.length > maxShownBeforeHiding && (
<ToggleMoreAffectedItems
handleClick={toggleExpanded}
id={`toggleMoreAffectedItems_${disruption.id}`}
isExpanded={isExpanded}
amountHidden={disruption.stopsAffected.length - maxShownBeforeHiding}
serviceText={
disruption.stopsAffected.length - maxShownBeforeHiding > 1
? whatIsAffected
: whatIsAffectedSingular
}
/>
)}
</div>
</>
)}
{disruption.mode === 'tram' &&
disruption?.servicesAffected &&
disruption?.stopsAffected && (
<>
{disruption.stopsAffected
.sort((a, b) => {
// Convert stop name text to lowercase
const x = a.name.toLowerCase();
const y = b.name.toLowerCase();
// Return minus or plus values when comparing prev/next string. This ensures alphabetical sorting.
if (x < y) return -1;
if (x > y) return 1;
return 0;
})
// Sort again to move a user's selected items to the front so it's not "hidden" behind the button
.sort((a, b) => {
const atcoCodeA = a.atcoCode;
const atcoCodeB = b.atcoCode;
if (atcoCodeA === selectedItem?.id || atcoCodeA === selectedItemTo?.id)
return -1;
return atcoCodeB === selectedItem?.id || atcoCodeB === selectedItemTo?.id
? 1
: 0;
})
.slice(0, sliceUpper)
.map((affected) => (
<FavBtn
id={affected.atcoCode}
severity={disruption.disruptionSeverity}
text={affected.name.replace(' (Midland Metro Stop)', '')}
title={disruption?.servicesAffected[0]?.routeDescriptions[0]?.description}
mode={disruption.mode}
key={affected.atcoCode}
narrow
/>
))}
<div className="wmnds-m-t-md">
{disruption.stopsAffected.length > maxShownBeforeHiding && (
<ToggleMoreAffectedItems
handleClick={toggleExpanded}
id={`toggleMoreAffectedItems_${disruption.id}`}
isExpanded={isExpanded}
amountHidden={disruption.stopsAffected.length - maxShownBeforeHiding}
serviceText={
disruption.stopsAffected.length - maxShownBeforeHiding > 1
? whatIsAffected
: whatIsAffectedSingular
}
/>
)}
</div>
</>
)}
{/* Affected services / Tram */}
{disruption.mode === 'tram' &&
!disruption?.stopsAffected &&
Expand Down