2024-07-29 15:27:20 +02:00
|
|
|
import { Button, IconButton, Modal as ModalMui } from '@mui/material'
|
2024-07-26 15:38:44 +02:00
|
|
|
import {
|
|
|
|
Link,
|
|
|
|
matchPath,
|
|
|
|
Outlet,
|
|
|
|
useLocation,
|
|
|
|
useNavigate
|
|
|
|
} from 'react-router-dom'
|
|
|
|
import styles from './style.module.scss'
|
|
|
|
import { appPublicRoutes } from '../../routes'
|
2024-07-31 14:37:10 +02:00
|
|
|
import { faClose } from '@fortawesome/free-solid-svg-icons'
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
2024-07-26 15:38:44 +02:00
|
|
|
|
|
|
|
function useRouteMatch(patterns: readonly string[]) {
|
|
|
|
const { pathname } = useLocation()
|
|
|
|
|
|
|
|
for (let i = 0; i < patterns.length; i += 1) {
|
|
|
|
const pattern = patterns[i]
|
|
|
|
const possibleMatch = matchPath(pattern, pathname)
|
|
|
|
if (possibleMatch !== null) {
|
|
|
|
return possibleMatch
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Modal = () => {
|
|
|
|
const navigate = useNavigate()
|
|
|
|
const tabs = [
|
|
|
|
{ to: appPublicRoutes.login, title: 'Login', label: 'Login' },
|
|
|
|
{ to: appPublicRoutes.register, title: 'Register', label: 'Register' },
|
2024-07-29 15:27:20 +02:00
|
|
|
{
|
|
|
|
to: appPublicRoutes.nostr,
|
|
|
|
title: 'Login',
|
|
|
|
sx: { padding: '10px' },
|
|
|
|
label: (
|
|
|
|
<img
|
|
|
|
src="https://image.nostr.build/fb557f1b6d58c7bbcdf4d1edb1b48090c76ff1d1384b9d1aae13d652e7a3cfe4.gif"
|
|
|
|
width="25"
|
|
|
|
alt="nostr logo"
|
|
|
|
height="25"
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
2024-07-26 15:38:44 +02:00
|
|
|
]
|
|
|
|
const routeMatch = useRouteMatch(tabs.map((t) => t.to))
|
|
|
|
const activeTab = routeMatch?.pattern?.path
|
|
|
|
const handleClose = () => {
|
|
|
|
navigate(appPublicRoutes.landingPage)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2024-07-29 15:27:20 +02:00
|
|
|
<ModalMui open={true} onClose={handleClose} aria-labelledby="modal-title">
|
|
|
|
<div className={styles.modal}>
|
|
|
|
<header className={styles.header}>
|
|
|
|
<h2 className={styles.title} id="modal-title">
|
|
|
|
{tabs.find((t) => activeTab === t.to)?.title}
|
|
|
|
</h2>
|
|
|
|
<IconButton
|
|
|
|
onClick={handleClose}
|
|
|
|
sx={{
|
|
|
|
fontSize: '18px',
|
2024-07-29 18:06:23 +02:00
|
|
|
color: 'rgba(0, 0, 0, 0.5)',
|
|
|
|
padding: '8px 15px',
|
|
|
|
borderRadius: '4px',
|
|
|
|
':hover': {
|
|
|
|
background: 'var(--primary-light)',
|
|
|
|
color: 'white'
|
|
|
|
}
|
2024-07-29 15:27:20 +02:00
|
|
|
}}
|
|
|
|
>
|
2024-07-31 14:37:10 +02:00
|
|
|
<FontAwesomeIcon icon={faClose} />
|
2024-07-29 15:27:20 +02:00
|
|
|
</IconButton>
|
|
|
|
</header>
|
2024-07-26 15:38:44 +02:00
|
|
|
|
2024-07-29 15:27:20 +02:00
|
|
|
<main className={styles.body}>
|
|
|
|
<ul>
|
|
|
|
{tabs.map((t) => {
|
|
|
|
return (
|
2024-07-29 15:28:19 +02:00
|
|
|
<li key={t.to}>
|
2024-07-29 15:27:20 +02:00
|
|
|
<Button
|
|
|
|
component={Link}
|
|
|
|
to={t.to}
|
|
|
|
sx={{
|
|
|
|
width: '100%',
|
|
|
|
height: '100%',
|
|
|
|
...(t?.sx ? t.sx : {})
|
|
|
|
}}
|
|
|
|
variant={
|
|
|
|
activeTab === t.to || t.to === appPublicRoutes.nostr
|
|
|
|
? 'contained'
|
|
|
|
: 'text'
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{t.label}
|
|
|
|
</Button>
|
|
|
|
</li>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</ul>
|
2024-07-29 17:12:47 +02:00
|
|
|
<div className={styles.tabContent}>
|
|
|
|
<Outlet />
|
|
|
|
</div>
|
2024-07-29 15:27:20 +02:00
|
|
|
</main>
|
2024-07-26 15:38:44 +02:00
|
|
|
|
2024-07-29 15:27:20 +02:00
|
|
|
<footer className={styles.footer}>Welcome to SIGit!</footer>
|
|
|
|
</div>
|
2024-07-26 15:38:44 +02:00
|
|
|
</ModalMui>
|
|
|
|
)
|
|
|
|
}
|