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

feat: add conditional routing to single highlight dialog close action #1473

Conversation

babblebey
Copy link
Contributor

@babblebey babblebey commented Aug 3, 2023

Description

This Pull Request introduces conditional routing to the Single Highlight Dialog Close action, bringing a fix to the Initial set-up; when a user clicks on a single highlight from a user profile, a dialog opens on the /feed/[id] route. However, when the user clicks on the close button of the dialog, it routes back to the /feed page, displaying the general highlights.

Changes Made

  1. Added referer to the single highlight SSR returned props, this was destructed from the Request headers req.headers intended to be used in a check to see what page/route (in is returned url value) the single highlight was clicked from. See referer value types below...
  • string - a valid url returned in the case where the /feed/[id] route was requested/clicked from within the web app.
  • null - a serialisable value returned in the case where technically no referer is found, i.e. the /feed/[id] route was via a direct url input to the browser tab or a click from an external website.
  1. Removed the below routing action which was making extra request to the same /feed/[id] route, hence setting the referer to a fixed value.
router.push(`/feed/${props.highlight?.id}`)
  1. Conditionally render Close button for Dialog based on the value of the referer, with each button handling routing in specific manners for different cases.

Implementation

{props.referer !== null && !props.referer.includes("/feed") ? (
  <Button
    variant="text"
    onClick={() => router.back()}
    className="!p-0 !border-0 absolute top-4 right-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-slate-100"
  >
    <AiOutlineClose size={20} />
    <span className="sr-only">Close</span>
  </Button>
) : (
  <DialogCloseButton onClick={() => router.replace("/feed")} />
)}

Case - When referer detects request is made from a page that is NOT the /feed page.

The <Button /> which routes back in history is rendered

Case - When referer detects request is made from the /feed page.

The <DialogCloseButton /> which closes the dialog and replaces current route with with /feed onClick is rendered

  1. Replicated the conditional routing logic in the Dialog component's root onOpenChange prop to inject the logic into the dialogues overlay "background-click-to-close" functionality

Implementation

<Dialog
  open={openSingleHighlight}
  // onOpenChange action/prop
  onOpenChange={(open) => {
    if (openSingleHighlight && !open) {
      if (props.referer !== null && !props.referer.includes("/feed")) {      // <- Logic starts here 🍕
        router.back();
      } else {
        setOpenSingleHighlight(false);
        router.replace("/feed");
      }     // <- ends here 🍕
    }
  }}
>
...
</Dialog>

🍕

What type of PR is this? (check all applicable)

  • 🍕 Feature
  • 🐛 Bug Fix
  • 📝 Documentation Update
  • 🎨 Style
  • 🧑‍💻 Code Refactor
  • 🔥 Performance Improvements
  • ✅ Test
  • 🤖 Build
  • 🔁 CI
  • 📦 Chore (Release)
  • ⏩ Revert

Related Tickets & Documents

Fixes #1414

Mobile & Desktop Screenshots/Recordings

screencast-localhost_3000-2023.08.03-03_32_21.webm

Added tests?

  • 👍 yes
  • 🙅 no, because they aren't needed
  • 🙋 no, because I need help

Added to documentation?

  • 📜 README.md
  • 📓 docs.opensauced.pizza
  • 🍕 dev.to/opensauced
  • 📕 storybook
  • 🙅 no documentation needed

[optional] Are there any post-deployment tasks we need to perform?

NA

[optional] What gif best describes this PR or how it makes you feel?

@netlify
Copy link

netlify bot commented Aug 3, 2023

Deploy Preview for oss-insights ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit a7b0c3b
🔍 Latest deploy log https://app.netlify.com/sites/oss-insights/deploys/64cb23bca831590008e6c61b
😎 Deploy Preview https://deploy-preview-1473--oss-insights.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Aug 3, 2023

Deploy Preview for design-insights ready!

Name Link
🔨 Latest commit a7b0c3b
🔍 Latest deploy log https://app.netlify.com/sites/design-insights/deploys/64cb23bcb72fcd00084d4158
😎 Deploy Preview https://deploy-preview-1473--design-insights.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@babblebey babblebey changed the title feat: add conditional routing to single highlight dialog close feat: add conditional routing to single highlight dialog close action Aug 3, 2023
@babblebey babblebey marked this pull request as ready for review August 3, 2023 07:45
Copy link
Contributor

@OgDev-01 OgDev-01 left a comment

Choose a reason for hiding this comment

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

LGTM 🍕

@OgDev-01 OgDev-01 added the needs review PRs that need review from core engineering team label Aug 3, 2023
@brandonroberts brandonroberts merged commit 1341cba into open-sauced:beta Aug 3, 2023
github-actions bot pushed a commit that referenced this pull request Aug 3, 2023
## [1.59.0-beta.1](v1.58.0...v1.59.0-beta.1) (2023-08-03)

### 🐛 Bug Fixes

* update user interest logo error for machine learning ([#1474](#1474)) ([a286eda](a286eda))

### 🍕 Features

* add conditional routing to single highlight dialog close action ([#1473](#1473)) ([1341cba](1341cba))
@github-actions
Copy link
Contributor

github-actions bot commented Aug 3, 2023

🎉 This PR is included in version 1.59.0-beta.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

open-sauced bot pushed a commit that referenced this pull request Aug 8, 2023
## [1.59.0](v1.58.0...v1.59.0) (2023-08-08)

### 🧑‍💻 Code Refactoring

* replace supabase/ui in design system typography components ([#1438](#1438)) ([38cfb30](38cfb30))

### 🍕 Features

* add a user notifications page ([#1478](#1478)) ([022dc69](022dc69))
* add conditional routing to single highlight dialog close action ([#1473](#1473)) ([1341cba](1341cba))
* add github link to profile ([#1459](#1459)) ([d42bc6d](d42bc6d))
* add support for highlight.new ([#1487](#1487)) ([3daa5c0](3daa5c0))
* improved the UX on the feeds page and scroll behaviour ([#1506](#1506)) ([31c1593](31c1593))
* onboarding auto fetch timezone ([#1488](#1488)) ([ae5cdd7](ae5cdd7))

### 🐛 Bug Fixes

* Feed page responsiveness  ([#1490](#1490)) ([67662b2](67662b2))
* feeds page typography and styles improvements ([#1467](#1467)) ([a3b289e](a3b289e))
* on page reload Insights page redirecting to Dashboard ([#1517](#1517)) ([397c36e](397c36e))
* update environment variable for Sentry ([#1521](#1521)) ([56ac14b](56ac14b))
* update release workflow to use GitHub app for semantic versioning ([#1484](#1484)) ([3f1ce84](3f1ce84))
* update user interest logo error for machine learning ([#1474](#1474)) ([a286eda](a286eda))
* uses session to update user info for notifications check ([#1486](#1486)) ([60d787e](60d787e))
@babblebey babblebey deleted the feat--conditional-routing-to-feed-dialog-close branch August 20, 2023 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review PRs that need review from core engineering team released on @beta
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Add Conditional Routing for Single Highlight Dialog Close Button
4 participants