Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanstitt committed Dec 14, 2024
1 parent 71dafbd commit fac50a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
20 changes: 4 additions & 16 deletions src/app/user-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,13 @@ export const UserNav = () => {
You appear to be a {auth.role} and likely want to{' '}
{auth.isResearcher && (
<>
<ButtonNav href="/researcher/studies">
View Studies
</ButtonNav>
<ButtonNav href="/researcher/studies">View Studies</ButtonNav>
<span> OR </span>
<ButtonNav href="/researcher/study/request/openstax">
Propose a Study
</ButtonNav>
<ButtonNav href="/researcher/study/request/openstax">Propose a Study</ButtonNav>
</>
)}
{auth.isMember && (
<ButtonNav href="/member/openstax/studies/review">
Review Studies
</ButtonNav>
)}
{auth.isAdmin && (
<ButtonNav href="/admin/members">
Administer Members
</ButtonNav>
)}
{auth.isMember && <ButtonNav href="/member/openstax/studies/review">Review Studies</ButtonNav>}
{auth.isAdmin && <ButtonNav href="/admin/members">Administer Members</ButtonNav>}
</Title>
</div>
)
Expand Down
16 changes: 9 additions & 7 deletions src/components/button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Link from 'next/link'
import { Button, type ButtonProps } from '@mantine/core'
import { useDisclosure } from '@mantine/hooks';
import { MouseEventHandler } from 'react';
import { useDisclosure } from '@mantine/hooks'
import { MouseEventHandler } from 'react'

type ButtonLinkProps = ButtonProps & {
href: string
Expand All @@ -10,20 +10,22 @@ type ButtonLinkProps = ButtonProps & {
}

export const ButtonNav: React.FC<ButtonLinkProps> = ({ href, children, target, rel, ...buttonProps }) => {
const [isBusy, { open: setBusy }] = useDisclosure()
const [isBusy, { open: setBusy }] = useDisclosure()

const handleClicks = Boolean(target !== '_blank' && rel !== 'external')

const onClick: MouseEventHandler<HTMLAnchorElement> = (event) => {
if (event.button != null && event.button > 0) return; // 0 == main button
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
if (event.defaultPrevented) return;
if (event.button != null && event.button > 0) return // 0 == main button
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return
if (event.defaultPrevented) return

setBusy()
}
return (
<Link href={href} onClick={handleClicks ? onClick : undefined} target={target} rel={rel}>
<Button {...buttonProps} aria-busy={isBusy} disabled={isBusy} loading={isBusy}>{children}</Button>
<Button {...buttonProps} aria-busy={isBusy} disabled={isBusy} loading={isBusy}>
{children}
</Button>
</Link>
)
}

0 comments on commit fac50a3

Please sign in to comment.