DemocracyLab / CivicTechExchange

https://www.democracylab.org
MIT License
97 stars 64 forks source link

add anchor support to url.section handling #1059

Open PeterBreen opened 1 year ago

PeterBreen commented 1 year ago

Links on democracylab from one dlab page to another dlab page are structured like so: <a href={url.section(Section.NAME) ...

This is defined in url.js, here: https://github.com/DemocracyLab/CivicTechExchange/blob/ede77887f966dc63108c5245ba7fcbe1119be898/common/components/utils/url.js

What we're missing is anchor support. There are two use cases this issue addresses, one of which is anchors generally and the second, anchors specifically within react-tab controlled content.

Here's the short version of this ticket:

Details for each below.

Anchors (jumplinks)

Right now, anchors are manually appended to a link - this is not in pattern. Please update our handler so the section ID can be passed as an argument, like we do with event IDs and similar. That way our construction of all links will be consistent.

example of manual appending (current behavior): https://github.com/DemocracyLab/CivicTechExchange/blob/ede77887f966dc63108c5245ba7fcbe1119be898/common/components/chrome/SiteFooter.jsx#L28-L29

example of using args (intended behavior): https://github.com/DemocracyLab/CivicTechExchange/blob/ede77887f966dc63108c5245ba7fcbe1119be898/common/components/controllers/CreateEventProjectController.jsx#L174-L177

The end result should take a user to the correct page and correct section, just like an html href="/pagename#section" would.

React-tab content + anchors

This one will be a bit trickier. We use react-tabs to control tabs of content on some pages. I'll use the companies page as an example. It has two tabs. The default tab shown without any args is Hackathon, but if we want to link to the Sponsorship tab, that can be done like it is here: https://github.com/DemocracyLab/CivicTechExchange/blob/ede77887f966dc63108c5245ba7fcbe1119be898/common/components/chrome/SponsorFooter.jsx#L49-L53

I've had a request from a designer to also allow for jumplinking to a specific section via anchor after opening a specific tab with react-tabs. So, the end result should take a user to the correct page (Companies, in this example), open a specific tab (Sponsors, in this example) and then the correct section. The reason this may be more difficult is the anchor jump must take place after react-tabs has opened the correct tab, as opposed to typical browser behavior of on page load independent of javascript manipulating the DOM.

(As an aside: please make your solution page agnostic; tabbed content is not unique to companies)

JeremyHcWang commented 1 year ago

Hi @PeterBreen, can I take this one?

PeterBreen commented 1 year ago

Hi @PeterBreen, can I take this one?

Sure can. Let me know if you need anything clarified on the second request, I tried to explain it but may not have done the best job :)

ddfridley commented 7 months ago

@JeremyHcWang Hi, I'm helping with development focus for DemocarcyLab. We've created a DemocracyLab Dashboard and would like to update the status of this issue.

Thanks.