-
Notifications
You must be signed in to change notification settings - Fork 90
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
Improve "place in" box on dev place pages #4774
Changes from 3 commits
a6ae975
1b809c8
aa15fd3
cc21801
8735c5f
7155ad0
c3fd13a
ed33faa
0a22e9a
e33ccea
d42f8a5
3334241
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -395,24 +395,46 @@ const RelatedPlaces = (props: { | |
place: NamedTypedPlace; | ||
childPlaces: NamedTypedPlace[]; | ||
}) => { | ||
const [isCollapsed, setIsCollapsed] = useState(true); | ||
const { place, childPlaces } = props; | ||
if (!childPlaces || childPlaces.length === 0) { | ||
return null; | ||
} | ||
const NUM_PLACES = 15; | ||
const showToggle = childPlaces.length > NUM_PLACES; | ||
const toggleShowMore = () => { | ||
setIsCollapsed(!isCollapsed); | ||
}; | ||
|
||
return ( | ||
<div className="related-places"> | ||
<div className="related-places-callout">Places in {place.name}</div> | ||
<div className="item-list-container"> | ||
<div className="item-list-inner"> | ||
{childPlaces.map((place) => ( | ||
<div key={place.dcid} className="item-list-item"> | ||
<a className="item-list-text" href={`/dev-place/${place.dcid}`}> | ||
{place.name} | ||
</a> | ||
</div> | ||
))} | ||
{childPlaces | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might argue this is starting to add a lot of logic within the render block. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call out. Stored the slice in a different variable and now just toggle between the lists which looks much cleaner now. |
||
.slice( | ||
0, | ||
showToggle && isCollapsed ? NUM_PLACES : childPlaces.length | ||
) | ||
.map((place) => ( | ||
<div key={place.dcid} className="item-list-item"> | ||
<a className="item-list-text" href={`/dev-place/${place.dcid}`}> | ||
{place.name} | ||
</a> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
{showToggle && ( | ||
<div className="show-more-toggle" onClick={toggleShowMore}> | ||
<span className="show-more-toggle-text"> | ||
{isCollapsed ? "Show more" : "Show less"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add the count for show more? e.g., "Show 25 more" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great idea, done! Also updated screenshots in the PR description. |
||
</span> | ||
<span className="material-icons-outlined"> | ||
{isCollapsed ? "expand_more" : "expand_less"} | ||
</span> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious - how did we choose 15?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Admittedly a bit arbitrarily -- this looks good to my eyes for now. My thought is to use
NUM_PLACES = 15
to unblock experimental release before the code freeze, and we can decide on a better solution after.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After thinking about this more, i think a better experience might be to make this responsive and to show more items when the page is larger, and fewer for smaller screen sizes. Wdyt @miss-o-soup ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I'll discuss with @miss-o-soup and add responsive behavior in a follow-up PR, I don't think this needs to block release.