From e1dfe79aab28e76069a3ab1a36769af233cfea35 Mon Sep 17 00:00:00 2001 From: thecodrr Date: Sat, 12 Jun 2021 09:57:02 +0500 Subject: [PATCH] feat: improve multi action announcement UI --- .../web/src/components/announcements/index.js | 90 +++++++++++-------- apps/web/src/theme/variants/button.js | 14 ++- apps/web/src/utils/use-announcements.js | 9 +- 3 files changed, 69 insertions(+), 44 deletions(-) diff --git a/apps/web/src/components/announcements/index.js b/apps/web/src/components/announcements/index.js index cd9b22ab4..4a6e34cc4 100644 --- a/apps/web/src/components/announcements/index.js +++ b/apps/web/src/components/announcements/index.js @@ -21,10 +21,7 @@ function Announcements({ announcements, removeAnnouncement }) { > - Announcement{" "} - {announcements.length - 1 >= 1 - ? `(${announcements.length - 1} more)` - : ""} + Announcement { + trackEvent(announcement.title, "dismissed"); removeAnnouncement && removeAnnouncement(announcement.id); }} > @@ -51,38 +52,55 @@ function Announcements({ announcements, removeAnnouncement }) { {announcement.description} )} - - {announcement.callToActions?.map((action) => - action.platforms.some( - (platform) => allowedPlatforms.indexOf(platform) > -1 - ) ? ( - - ) : null - )} + sx={{ + ":first-of-type": { + mr: 1, + }, + }} + fontWeight="bold" + onClick={async () => { + trackEvent(action.data, action.type); + switch (action.type) { + case "link": + const url = new URL(action.data); + if (url.origin === window.location.origin) + window.open(action.data, "_self"); + else window.open(action.data, "_blank"); + break; + case "promo": + const coupon = action.data; + await showBuyDialog(coupon); + break; + default: + return; + } + }} + > + {action.title} + + ) : null + )} + ); } diff --git a/apps/web/src/theme/variants/button.js b/apps/web/src/theme/variants/button.js index b349f0645..837cdb602 100644 --- a/apps/web/src/theme/variants/button.js +++ b/apps/web/src/theme/variants/button.js @@ -9,6 +9,7 @@ class ButtonFactory { anchor: new Anchor(), tool: new Tool(), icon: new Icon(), + shade: new Shade(), statusitem: new StatusItem(), }; } @@ -31,6 +32,9 @@ class Default { border: "2px solid", borderColor: "primary", }, + ":hover": { + opacity: 0.8, + }, }; } } @@ -41,10 +45,6 @@ class Primary { variant: "buttons.default", color: "static", bg: "primary", - transition: "opacity 300ms linear", - ":hover": { - opacity: 0.8, - }, ":focus-visible": { border: "2px solid", borderColor: "text", @@ -53,6 +53,12 @@ class Primary { } } +class Shade { + constructor() { + return { variant: "buttons.primary", color: "primary", bg: "shade" }; + } +} + class Secondary { constructor() { return { variant: "buttons.default", color: "text", bg: "border" }; diff --git a/apps/web/src/utils/use-announcements.js b/apps/web/src/utils/use-announcements.js index 8d1fb003b..067008a87 100644 --- a/apps/web/src/utils/use-announcements.js +++ b/apps/web/src/utils/use-announcements.js @@ -11,13 +11,14 @@ export default function useAnnouncements() { useEffect(() => { (async function () { try { - CACHED_ANNOUNCEMENTS = - CACHED_ANNOUNCEMENTS || (await db.announcements()); + CACHED_ANNOUNCEMENTS = CACHED_ANNOUNCEMENTS.length + ? CACHED_ANNOUNCEMENTS + : await db.announcements(); } catch (e) { console.error(e); } finally { - setAnnouncements((announcements) => { - const filtered = announcements.filter((announcement) => + setAnnouncements(() => { + const filtered = CACHED_ANNOUNCEMENTS.filter((announcement) => shouldShowAnnouncement(announcement) ); return filtered;