Enhancing UI/UX in My Gatsby Blog: Introducing the New Popup Feature
Tags: gatsby, webdev, programming
Published: 2024-01-05 21:05:12

---
title: Enhancing UI/UX in My Gatsby Blog: Introducing the New Popup Feature
published: true
date: 2024-01-05 00:00:00 UTC
tags: gatsby,webdev,programming
canonical_url: https://logarithmicspirals.com/blog/gatsby-blog-new-popup-alerts/
---

![A stylized computer screen with a "New blog post!" popup, set against a sleek, digitally-inspired abstract background](https://logarithmicspirals.com/static/d0c72fd11bc4e280a3f99e2c8e8aa0e3/f058b/popup_hero.png)

_Image Credit: ChatGPT_

## Introduction[<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#introduction)

Today I am announcing a new feature I've developed for my website. The feature is a small pop up which will allow visitors to quickly navigate to the latest blog post. As a disclaimer, I will be talking about UI and UX, but I am not a UI/UX professional. As someone who works on backend systems for their day job, frontend development and UI/UX are very much hobby interests of mine. As such, this won't be the most in depth or accurate breakdown of how to approach UI/UX design for web development.

**Note:** If you're visiting this post directly on my website, and it's the latest one posted, you won't be able to see the popup 😢. See the following screenshot for an example of what it looks like:

![Screenshot showing the popup in the bottom right corner of the screen on the homepage](https://logarithmicspirals.com/static/6e45ade73f3391c0731833a91434d58a/f058b/popup_screenshot.png)

## Why I Added the Popup[<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#why-i-added-the-popup)

While reviewing search performance results, I observed I've been getting more visits from older posts than newer posts. The realization struck me there is an opportunity to help guide new visitors to the latest content. Someone coming to the site for the first time may have a specific article they're clicking on, but the current layout doesn't make it easy to find the most recent post.

## Designing the Popup[<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#designing-the-popup)

As a long time user of the internet, I've come to find certain design patterns to be quite irritating. In fact, I find popups to often be the cause of many high friction experiences which result in frustration. As such, I felt it was important to come up with a design which is minimally intrusive while providing maximum user value.

Initially, my idea was to add a bell icon to the navbar of the site. When a new post would be added to the site, the bell icon would visually change and perhaps have an animation to get the user's attention. However, I decided against this for now since a bell icon may not be clear as to what it's trying to notify users about.

As such, I decided trying out a popup would be a suitable alternative.

## Building the UI with JSX and Bulma CSS[<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#building-the-ui-with-jsx-and-bulma-css)

Conceptually, I wanted the pop up code to be entirely self-contained in its own component. Ideally, the popup wouldn't need to do very much work on the client side. I broke the popup functionality down into the following steps:

1. Get the latest post from the site data.
2. Check if the last viewed post from the alert does not match the latest post.

  1. And if the user is not on the path of the latest post, show the popup. Otherwise, save the latest post into local storage.
  2. Otherwise, if the last viewed post is the latest post, hide the popup.

As can be seen in those steps, the component uses local storage to control its visibility. By default, the component is hidden and is only displayed when the right conditions are met.

Additionally, I added a button to allow users to dismiss the popup without having to visit the post. The reason for this is I don't want to annoy people who are visiting the site for a very specific article they want to read and aren't interested in other content.

### The Javascript[<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#the-javascript)

Here's what the code for this component looks like:

```javascript
import React, { useEffect } from "react";
import { useStaticQuery, graphql, Link } from "gatsby";

const NewPostAlert = ({ path }) => {
  const data = useStaticQuery(graphql`
    {
      allMarkdownRemark(
        sort: { frontmatter: { date: DESC } }
        limit: 1
        filter: { frontmatter: { title: { ne: "" } } }
      ) {
        nodes {
          frontmatter {
            title
          }
          id
        }
      }
      allSitePage {
        nodes {
          pageContext
          path
        }
      }
    }
  `);

  const pageIdToPath = new Map();

  data.allSitePage.nodes.forEach(node => {
    pageIdToPath.set(node.pageContext.id, node.path);
  });

  const latestPostNode = data.allMarkdownRemark.nodes[0];
  const latestPostTitle = latestPostNode.frontmatter.title;
  const latestPostPath = pageIdToPath.get(latestPostNode.id);

  useEffect(() => {
    var lastViewedAlertPost = localStorage.getItem("lastViewedAlertPost");
    var isCurrentPathLatestPost = latestPostPath === path;

    if (lastViewedAlertPost !== latestPostPath) {
      if (!isCurrentPathLatestPost) {
        document.getElementById("new-post-alert").classList.remove("hide");
      } else {
        localStorage.setItem("lastViewedAlertPost", latestPostPath);
      }
    } else {
      document.getElementById("new-post-alert").classList.add("hide");
    }

    document.querySelectorAll(".close-new-post-alert").forEach(node => {
      node.addEventListener("click", () => {
        document.getElementById("new-post-alert").classList.add("hide");

        localStorage.setItem("lastViewedAlertPost", latestPostPath);
      });
    });
  }, [path, latestPostPath]);

  return (
    <div
      id="new-post-alert"
      className="new-post-alert message is-info m-6 hide jiggle"
    >
      <div className="message-header">
        <i className="fa-solid fa-bell fa-xl"></i>
        New post!
        <button
          className="delete close-new-post-alert"
          aria-label="delete"
        ></button>
      </div>
      <div className="message-body">
        <p>
          <b>{latestPostTitle}</b>
        </p>
        <p>
          Click <Link to={latestPostPath}>here</Link> to read more!
        </p>
      </div>
    </div>
  );
};

export default NewPostAlert;
```

Note the popup requires the current path to function. The way I'm using it is to embed it inside of layout component which is used to create the basic structure of each page. The layout component gets passed the page location and is used for every page on my website.

### The CSS[<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#the-css)

For this component, I opted to style and structure the popup as a [Bulma message component](https://bulma.io/documentation/components/message/). However, you can see I have some CSS classes called `new-post-alert`, `jiggle`, and `hide` which are not part of Bulma. Here's the code for those classes:

```scss
.hide {
  display: none !important;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes jiggle {
  0%, 100% { transform: scale(1); }
  10% { transform: scale(1.05); }
  20% { transform: scale(1.1); }
  30% { transform: scale(1.05); }
  40% { transform: scale(0.95); }
  50% { transform: scale(1); }
  60% { transform: scale(1.03); }
  70% { transform: scale(0.97); }
  80% { transform: scale(1.01); }
}

.new-post-alert {
  position: fixed;
  bottom: 0;
  right: 0;
  max-width: 400px;
  animation: jiggle 0.5s ease-in-out 3s, fade-in 0.5s ease forwards;
}

.new-post-alert > .message {
  max-width: 300px;
}
```

The `hide` class is simply used to control the component's visibility. The `jiggle` and `fade-in` animations are used to influence the user experience. As you can see in the `new-post-alert`, the animation fades in quickly over half a second, and then three seconds later does a small jiggle. The jiggle is to help get the user's attention.

## UX Principles in Action[<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#ux-principles-in-action)

Since I'm not exactly a UI/UX expert, I had to rely on external sources for determining what principles to consider when thinking about the user experience. Some of the UX principles I followed when developing the feature were:

1. **Consistency:** The popup maintains consistency with overall design of the blog by making further use of Bulma's CSS classes. This ensures a cohesive user experience.
2. **Hierarchy:** Importance is given to prominently displaying the latest blog post, guiding users intuitively through the site's content.
3. **User Control:** Users have the freedom to dismiss the popup, providing control over their browsing experience.

You can read more about these principles, and others, on the [CareerFoundry blog](https://careerfoundry.com/en/blog/ux-design/5-key-principles-for-new-ux-designers/) and the [UX Design Institute blog](https://www.uxdesigninstitute.com/blog/ux-design-principles/).

## Conclusion[<svg aria-hidden="true" focusable="false" height="16" version="1.1" viewbox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#conclusion)

The main thing I had reinforced while working on this was good design is hard. While I am proud of having developed this feature, I am still able to think of ways to improve it. For example, I could add a setting to the site so users are able to completely disable the popup. Another thing I could improve is the accessibility of the feature. Of course, the site is very much a constant work in progress so I will probably be working on updates for such things at some point in the future.

Developing this popup feature has been an enlightening journey into the world of UI/UX, albeit from a backend developer's perspective. It underscored for me the delicate balance between functionality and user experience. While the current iteration serves its purpose, I see room for improvement, such as enhanced accessibility options and user customization features. This project has been a valuable reminder websites are like living entitiea, always evolving to better meet user needs. As I continue to refine my skills and this site, I look forward to implementing more user-centric features which align with the core principles of UI/UX design.