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

Migrate to Bootstrap 5x #631

Merged
merged 22 commits into from
Nov 3, 2023
Merged

Migrate to Bootstrap 5x #631

merged 22 commits into from
Nov 3, 2023

Conversation

gedankenstuecke
Copy link
Member

@gedankenstuecke gedankenstuecke commented Oct 10, 2023

This will potentially be a bit of work as a lot of declarations have changed, but it would be good to migrate now rather than later in order to avoid being too outdated. This will also help with a lot of the accessibility improvements identified during the user tests (e.g. #605 & #603).

  • Change main CSS/JS files
  • Check if there are more CSS/JS files that need to be changed
  • Fix navbar
  • Fix broken JS on moderation index page (tabs not working)
  • Fix broken JS on moderation page (selecting moderation reason not working)
  • Fix broken JS on "my stories" page (tabs not working)
  • Fix "badges" on My Stories page
  • Fix "remember tabs" for moderation page & my stories page
  • Fixen toggles (all converted back to regular check boxes)
  • Fix broken "view stories" page (expanding stories does not work)
  • Fix "scrollspy" pages (about, CoC, autism, …)
  • Fix any pages with a form help texts don't properly display
  • Colours of headings on about/autism/coc/help pages are off?
  • Fix carousel on home.html

@github-actions
Copy link

github-actions bot commented Oct 10, 2023

Coverage report

The coverage rate went from 98.79% to 98.79% ⬆️

None of the new lines are part of the tested code. Therefore, there is no coverage data about them.

Diff Coverage details (click to unfold)

server/apps/users/forms.py

100% of new lines are covered (100% of the complete file).

@gedankenstuecke
Copy link
Member Author

Memo for myself: The scrollspy things are half-working now, they work once and then not when scrolling up again 🙈

@gedankenstuecke
Copy link
Member Author

I looked into the changes in colours for some texts, and those are a change in how BS treats it's colours (e.g. the info is now a lot more cyan than the muted colour it used to be). I can go ahead and edit those in our own main.css

@gedankenstuecke
Copy link
Member Author

okay, those colours are fixed :)

@gedankenstuecke
Copy link
Member Author

Okay, I spent another 30 minutes on the scrollspy issue but to no avail 😂

@llewelld
Copy link
Collaborator

This is amazing work @gedankenstuecke.

Concerning scrollspy, I wonder if you could be hitting Bootstrap issue #36431. It looks like a known issue with 5.2.

I tested out your changes with Bootstrap 5.1.3 and found the scrollspy worked considerably better. Would 5.1.3 be enough, at least until the fix is released?

@gedankenstuecke
Copy link
Member Author

Yeah, I found that issue too and wondered if that's somehow related!

The main trade-off between 5.1 and 5.2 is that only 5.2 comes with the dark mode options that at least partially motivated the wish to update bootstrap 🙈 If we wanted to stick with 5.2 we could either decide to up drop the scrollspy or replace it with a 3rd party option instead?

@llewelld
Copy link
Collaborator

llewelld commented Oct 12, 2023

Yes I see; that's a really good point.

Even though it's frustrating, I'd say dropping it or replacing it would both be valid options. It shouldn't be hard functionality to replicate, but it might also be nice to be able to revert back to the Bootstrap version once it's fixed (to avoid pulling in unecessary dependencies).

By the way, perhaps I'm misreading, but it looks like dark mode is 5.3 onwards (but still with the broken srollspy implementation).

@gedankenstuecke
Copy link
Member Author

Ah yes, great catch, it's 5.3+ for the dark theme (and it's the one this PR is currently based on, so that works in principle!)

I'd personally not be too sad about seeing the scrollspy at least temporarily go, especially as it's already disabled (or at least not applicable) for the mobile view where the menu bar hops to the top of the page.

Once I have some time I can look into what an alternative to bs's scrollspy could be!

@gedankenstuecke
Copy link
Member Author

I've removed the scrollspy for now, @llewelld it would be amazing if you had a look!

@gedankenstuecke
Copy link
Member Author

@llewelld I know your official allocation to this has ended, but you had mentioned that you had a look at this already. I just wanted to check if you still wanted to submit that review or if someone else should have a go at it? 🙂

@llewelld
Copy link
Collaborator

llewelld commented Nov 1, 2023

Thanks for prodding me about this @gedankenstuecke. I do have a partial review that I've not had a chance to complete yet. Sorry for this. I still plan to submit it, but do of course feel free to have others take a look as well (if I miss my chance to add my comments, that's on me).

@gedankenstuecke
Copy link
Member Author

Thanks @llewelld, I'll see with @helendduncan if there's any reason that this would be urgent to get merged in!

@helendduncan
Copy link
Collaborator

No hurry from my end @gedankenstuecke @llewelld I am only just back allocated on the project and my next task won't be held up by this, but am also happy to review if needed

@gedankenstuecke
Copy link
Member Author

Great, let's give @llewelld a bit more time to finish his review in that case! David, it's much appreciated that you're taking the time for this! 🙏

Copy link
Collaborator

@llewelld llewelld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really nice. Apart from the menu highlighting which we discussed elsewhere (and which I agree isn't a big loss) things look very similar to the Bootstrap 4 version. Really nice.

There were a couple of points that I can't add as code comments so I'll put them here instead.

I experienced quite a serious scroll glitch on the shared stories page, caused by the 'smooth scroll' behaviour interacting with the code that resets the scroll position after a search. I've no idea why the Bootstrap change might have caused this. At any rate, forcing instant scroll fixed it for me:

diff --git a/static/js/shared-stories-filtering.js b/static/js/shared-stories-filtering.js
index 0c68d0d..9850060 100644
--- a/static/js/shared-stories-filtering.js
+++ b/static/js/shared-stories-filtering.js
@@ -43,7 +43,7 @@ $("#single_trigger_warnings :checkbox").change(function(){
 
 document.addEventListener("DOMContentLoaded", function(event) { 
     var scrollpos = localStorage.getItem('scrollpos');
-    if (scrollpos) window.scrollTo(0, scrollpos);
+    if (scrollpos) window.scrollTo({left: 0, top: scrollpos, behavior: "instant"});
 });
 
 window.onbeforeunload = function(e) {

Completely separately, I found adding this helpful for testing. Although I appreciate this PR isn't supposed to fix everything about dark mode, this code will activate dark mode based on the OS/browser settings:

diff --git a/static/js/main.js b/static/js/main.js
index e69de29..f2d49b0 100644
--- a/static/js/main.js
+++ b/static/js/main.js
@@ -0,0 +1,10 @@
+$(function () {
+  function selectTheme(media) {
+    $("html").attr("data-bs-theme", media.matches ? "dark" : "light");
+  }
+
+  const media = window.matchMedia('(prefers-color-scheme: dark)');
+  selectTheme(media);
+  media.addListener(selectTheme);
+});
+

Overall, the switch to Bootstrap 5 looks great to me.

server/apps/main/templates/main/moderation_list.html Outdated Show resolved Hide resolved

{% block content %}

<script src="{% static 'js/menu-alignment.js' %}"></script>


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a small (0.5 rem) gap that's appearing between the heading menu item and the subsequent items; apparently added by the <h5>.

It looks okay actually, but I think is probably unintentional. Something like this could be used to remove it (added to main.css).

.list-group-item {
  margin-bottom: 0;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch, I hadn't noticed. I've replaced the h5 with a more default declaration for the list view and made that bold instead, as I think that works well :)

</div>
</form>
</form>
</div>
</div>
</div>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something that becomes apparent in dark mode is that these cards have a border. It's barely visible in light mode but in dark mode it's really high contrast. But it highlights that there's no gap between the "Stories" card above and the "Review tabs" below.

It might be worth adding in some kind of gap, e.g. by adding in a top margin to the moderation-table-container:

.moderation-table-container {
  margin-top: 3%;
  margin-bottom: 3%;
} 

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, amazing catch, added that!

@gedankenstuecke
Copy link
Member Author

Thanks a ton @llewelld, well spotted on those issues. I've implemented those fixes. And well done on getting the dark mode thing implemented right away!

@helendduncan feel free to also give it a look and see if it works for you too!

Copy link
Collaborator

@llewelld llewelld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the changes. This all looks great to me. Given the discussion about theming yesterday during the meetup, it sounds like your effort upgrading to v.5 will be very worthwhie.

@gedankenstuecke
Copy link
Member Author

Thanks for all the help @llewelld, and totally agree that it seems like it'll come in really useful to allow people to adapt the way we displays it!

I'll merge it in now, so that we can see if there's any changes needed to #632 after it!

@gedankenstuecke gedankenstuecke merged commit 7628d7b into main Nov 3, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants