Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Update banner styles #1184

Merged
merged 15 commits into from
Apr 15, 2022
Merged

Update banner styles #1184

merged 15 commits into from
Apr 15, 2022

Conversation

sarayourfriend
Copy link
Contributor

@sarayourfriend sarayourfriend commented Mar 25, 2022

Fixes

Fixes #1123 by @panchovm

Description

Primarily focused on updating the banner styles and unifying the implementations so that both have a close button. The unification effort is where most of the changes come from as well as some on-the-fly TypeScript conversion.

I'd like to split this PR into multiple parts but will be on vacation for the next week so just wanted to get my WIP up in case someone else wanted to pick it apart while I'm gone.

Changes proposed:

  • Convert use-storage and use-event-listener to TypeScript and simplify the initial value handling in use-storage.
  • Update local.ts to implement the full Storage API 1:1 instead of using a bespoke API. Also simplify the error handling in it.
  • Convert NotificationBanner to TypeScript and update it to be able to handle dismissal on its own rather than relying on the parent to handle it. This makes it easy to implement new dismissable banners without having to duplicate logic.
  • Update TranslationBanner to use the new NotificationBanner API and remove the unnecessary stuff from use-i18n-sync (which can probably be renamed now that nothing is being "synced")

Testing Instructions

Checkout the branch and run pnpm dev. Visit the site in English and verify there is no banner. Visit the site in Russian (ru) and verify there is a banner and that it can be dismissed and that it stays dismissed between requests (aside from the already existing problem that the banner is rendered SSR, to be fixed by the UI state cookie milestone).

Visit the site in another low-translation percent language like Portuguese (pt). Verify that a new banner shows with the correct information and that it is dismissable and stays dismissed. Verify that you can switch between Russian and Portuguese and get no banner.

Now do the same with two more low-translation-percent languages and do not dismiss the banners and ensure that both show the appropriate banner between page requests.

Note: All of the above could be encoded in e2e tests and I plan to do that when I get back from vacation and have time to implement additional tests for this on top of the already existing ones.

The CC referral banner is not yet implemented but testing it will go as follows:

Visit the site with the referrer=creativecommons.org query param and ensure that the banner shows and that it is dismissable. Ensure that it stays dismissed on subsequent requests to the site with the query param. (note again that this has not yet been implemented on this branch!).

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@sarayourfriend sarayourfriend requested a review from a team as a code owner March 25, 2022 10:59
@sarayourfriend sarayourfriend requested review from obulat and dhruvkb and removed request for a team March 25, 2022 10:59
@sarayourfriend sarayourfriend marked this pull request as draft March 25, 2022 11:02
Base automatically changed from fix/missing-nuxt-types to main March 25, 2022 14:16
@sarayourfriend
Copy link
Contributor Author

Blocked by #1241 for the tapes fix.

@sarayourfriend sarayourfriend marked this pull request as ready for review April 11, 2022 07:56
@@ -91,7 +91,7 @@ export default {
},
data() {
const savedFormatExtension =
local.get(LS_DOWNLOAD_FORMAT_EXTENSION_KEY) ?? null
local.getItem(LS_DOWNLOAD_FORMAT_EXTENSION_KEY) ?? null
Copy link
Contributor

Choose a reason for hiding this comment

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

Would using useStorage composable be an overkill here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess not, I'd just like to avoid doing that refactor in this PR as well if that's okay? We can open a separate issue for it 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, I just remembered looking at this PR previously and trying to understand the difference between the two. Then I saw that useStorage is actually using local internally

v-if="needsTranslationBanner"
:id="bannerKey"
variant="informational"
>
{{
// eslint-disable-next-line @intlify/vue-i18n/no-raw-text
'⚠️'
Copy link
Contributor

Choose a reason for hiding this comment

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

We could add this symbol to ignored strings that @krysal created.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we use that list for anything you think? The ones Krystle added made sense to me because they're used in a couple of places in the app, I think... Hopefully raw emoji aren't that common in the app 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Now that you say so, I guess it does make sense to use that list for repeated strings, and not for single emojis :)

Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

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

The button on the mobile version is positioned incorrectly: it should be at the end horizontally, but it shows at the bottom.

Figma mockup: https://www.figma.com/file/w60dl1XPUvSaRncv1Utmnb/Audio-Release?node-id=953%3A17185

@sarayourfriend
Copy link
Contributor Author

@obulat thanks for catching that. I think it is due to the md: modifiers in VNotificationBanner. They're leftover from the previous, specific implementation. Removing them now to see if it fixes it.

@@ -1,6 +1,6 @@
<template>
<div>
<VMigrationNotice v-show="isReferredFromCc" />
<VMigrationNotice v-if="isReferredFromCc" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this cause client-server mismatch? Often when you use v-if and the server state is different from the client state (i.e., something depends on the client state such as localStorage), the mismatch will cause 'hydration bail' and full re-rendering on the client.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I thought I remembered there being a good reason for it being v-show. I'll put it back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can move it to v-if if we want when we implement the ui state cookie.

Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

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

There needs to be some more logic checking the value in localStorage to show/hide the banner after it's been dismissed and the page is reloaded.

@@ -1,5 +1,9 @@
<template>
<VNotificationBanner v-show="!shouldHideBanner" @close="dismissBanner">
<VNotificationBanner
v-show="needsTranslationBanner"
Copy link
Contributor

Choose a reason for hiding this comment

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

The v-show logic here only uses the translation percentage, and doesn't check for the value in localStorage. This is why if you dismiss a banner, and refresh the page, you will see the banner again, and will not be able to dismiss it anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That logic is handled in the VNotificationBanner component itself, with the local storage. But it seems like stacking v-show or something is messing with it. Thanks for catching this, I will debug it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I think the issue is that because we have a v-show on the external render of the component, and because v-show just uses CSS to show/hide the element, it's overriding the local storage handling inside the component because v-show="true" in the component rendering it, even though inside (I've confirmed) v-show="false".

The only thing I can think of is to forward the "v-show" variable as a new prop to be combined with the local storage variable. Hacky, but I guess it is necessary for v-show because of the way it works.

Copy link
Contributor

Choose a reason for hiding this comment

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

There are two layers of v-show now, in the TranslationBanner and in the NotificationBanner (one checks for local storage, the other - for translation percentage). Maybe they are cancelling each other out? It would be nice to combine them, use the outer v-show value as a prop to NotificationBanner, maybe?

Copy link
Contributor

Choose a reason for hiding this comment

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

The comment was too late, you've already implemented the fixes 🤣

Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

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

Works! Thank you for lots of added tests.

@sarayourfriend
Copy link
Contributor Author

@dhruvkb can you take a look at this if you get a chance today? Thanks!

Copy link
Member

@dhruvkb dhruvkb left a comment

Choose a reason for hiding this comment

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

LGTM, love the tryUse function. Why are the checks failing?

@sarayourfriend
Copy link
Contributor Author

It must be the button variations. Looking into it now. Thanks for the review!

@sarayourfriend sarayourfriend merged commit 983495b into main Apr 15, 2022
@sarayourfriend sarayourfriend deleted the update/banner-styles#1123 branch April 15, 2022 08:20
@zackkrida zackkrida added 🧰 goal: internal improvement Improvement that benefits maintainers, not users 💻 aspect: code Concerns the software code in the repository labels May 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💻 aspect: code Concerns the software code in the repository 🧰 goal: internal improvement Improvement that benefits maintainers, not users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Style update of translation and news banners
4 participants