import { useAccountComment } from '@plebbit/plebbit-react-hooks'; import { Link, useLocation, useNavigate, useParams } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { isCatalogView } from '../../lib/utils/view-utils'; import styles from './board-nav.module.css'; import { useDefaultSubplebbitAddresses } from '../../hooks/use-default-subplebbits'; interface BoardNavProps { subplebbitAddresses: string[]; subplebbitAddress?: string; } const BoardNavDesktop = ({ subplebbitAddresses }: BoardNavProps) => { const { t } = useTranslation(); const location = useLocation(); const params = useParams(); const isInCatalogView = isCatalogView(location.pathname, params); return (
[ {subplebbitAddresses.map((address: string, index: number) => { return ( {index === 0 ? null : ' '} {address.includes('.') ? address : address.slice(0, 10).concat('...')} {index !== subplebbitAddresses.length - 1 ? ' /' : null} ); })} ] [{t('settings')}] [{t('home')} ]
); }; const BoardNavMobile = ({ subplebbitAddresses, subplebbitAddress }: BoardNavProps) => { const { t } = useTranslation(); const navigate = useNavigate(); const displaySubplebbitAddress = subplebbitAddress && subplebbitAddress.length > 30 ? subplebbitAddress.slice(0, 30).concat('...') : subplebbitAddress; const currentSubplebbitIsInList = subplebbitAddresses.some((address: string) => address === subplebbitAddress); const isInCatalogView = isCatalogView(useLocation().pathname, useParams()); const boardSelect = ( ); return ( ); }; // sticky menu animation // will trigger more than once with hot reloading during development if (!window.STICKY_MENU_SCROLL_LISTENER) { window.STICKY_MENU_SCROLL_LISTENER = true; const scrollRange = 50; // the animation css px range in stickyMenuAnimation, must also edit css animation 100%: {top} let currentScrollInRange = 0, previousScroll = 0; window.addEventListener('scroll', () => { // find difference between current and last scroll position const currentScroll = window.scrollY; const scrollDifference = currentScroll - previousScroll; previousScroll = currentScroll; // find new current scroll in range const previousScrollInRange = currentScrollInRange; currentScrollInRange += scrollDifference; if (currentScrollInRange > scrollRange) { currentScrollInRange = scrollRange; } else if (currentScrollInRange < 0) { currentScrollInRange = 0; } // fix mobile overflow scroll bug if (currentScroll <= 0) { currentScrollInRange = 0; } // no changes if (currentScrollInRange === previousScrollInRange) { return; } // Get the menu element const menuElement = document.getElementById('sticky-menu'); if (!menuElement) { return; } // control progress of the animation using negative animation-delay (0 to -1s) const animationPercent = currentScrollInRange / scrollRange; menuElement.style.animationDelay = animationPercent * -1 + 's'; }); } const BoardNav = () => { const subplebbitAddresses = useDefaultSubplebbitAddresses(); const params = useParams(); const accountComment = useAccountComment({ commentIndex: params?.accountCommentIndex as any }); const subplebbitAddress = params?.subplebbitAddress || accountComment?.subplebbitAddress; return ( <> ); }; export default BoardNav;