Skip to content

Commit

Permalink
feat: adding timeout to mobile nav bar notification
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonNotJson committed Oct 6, 2023
1 parent 1a7df35 commit 19bc081
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions apps/forum/src/components/Board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const Board = ({ triggerRefresh, setBoard }: any) => {
boards.find((board) => board.slug === boardSlug)?.slug || ""
);

localStorage.setItem("mobileNavCheck", "false");

// Use Effect to set the board state in the parent component for tag filtering
useEffect(() => {
setBoard(boardSlug);
Expand Down
13 changes: 11 additions & 2 deletions apps/root/src/components/frame/MobileNav.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react"
import React, { useState, useEffect } from "react"

import { getUserAttr, signOut } from "wasedatime-ui"
import { useTranslation } from "react-i18next"
Expand All @@ -19,6 +19,15 @@ const MobileNav = ({ navItems, openSignInModal }: Props) => {
const [currentPath, setCurrentPath] = useState(window.location.pathname)
const notSignedIn = !userAttr
if (notSignedIn) getUserAttr().then((attr) => setUserAttr(attr))
const [showTooltip, setShowTooltip] = useState(true)

useEffect(() => {
const timeoutId = setTimeout(() => {
setShowTooltip(false) // Hide tooltip after 3 seconds
}, 3000)

return () => clearTimeout(timeoutId) // Cleanup on unmount
}, []) // Run once after the initial render

const styledLinks = navItems.map((item) => (
<LinkOutsideRouter
Expand All @@ -34,7 +43,7 @@ const MobileNav = ({ navItems, openSignInModal }: Props) => {
<div className="text-lg text-light-text2 group-hover:text-light-main dark:text-dark-text2 dark:group-hover:text-dark-text1">
{item.name}
</div>
{item.tooltip && (
{item.tooltip && showTooltip && (
<span className="absolute top-0 left-1/2 z-10 -translate-x-1/2 -translate-y-full transform whitespace-nowrap rounded bg-light-main px-3 py-2 text-lg text-dark-text1 dark:bg-dark-main">
{item.tooltip}
</span>
Expand Down

0 comments on commit 19bc081

Please sign in to comment.