Merge pull request 'fix: change sign to create' (#34) from issue-24 into main
All checks were successful
Release / build_and_release (push) Successful in 1m5s

Reviewed-on: https://git.sigit.io/sig/it/pulls/34
This commit is contained in:
s 2024-05-15 08:46:12 +00:00
commit b48ab86aab
4 changed files with 35 additions and 15 deletions

View File

@ -20,11 +20,11 @@ import {
} from '@mui/material'
import { MuiFileInput } from 'mui-file-input'
import { useEffect, useState } from 'react'
import { Link } from 'react-router-dom'
import { Link, useNavigate } from 'react-router-dom'
import placeholderAvatar from '../../assets/images/nostr-logo.jpg'
import { LoadingSpinner } from '../../components/LoadingSpinner'
import { MetadataController, NostrController } from '../../controllers'
import { getProfileRoute } from '../../routes'
import { appPrivateRoutes, getProfileRoute } from '../../routes'
import { ProfileMetadata, User, UserRole } from '../../types'
import {
encryptArrayBuffer,
@ -44,7 +44,8 @@ import JSZip from 'jszip'
import { useSelector } from 'react-redux'
import { State } from '../../store/rootReducer'
export const SignPage = () => {
export const CreatePage = () => {
const navigate = useNavigate()
const [isLoading, setIsLoading] = useState(false)
const [loadingSpinnerDesc, setLoadingSpinnerDesc] = useState('')
@ -63,6 +64,22 @@ export const SignPage = () => {
const nostrController = NostrController.getInstance()
useEffect(() => {
if (usersPubkey) {
setUsers((prev) => {
const existingUserIndex = prev.findIndex(
(user) => user.pubkey === usersPubkey
)
// make logged in user the first signer by default
if (existingUserIndex === -1)
return [{ pubkey: usersPubkey, role: UserRole.signer }, ...prev]
return prev
})
}
}, [usersPubkey])
const handleAddUser = async () => {
setError(undefined)
@ -89,8 +106,6 @@ export const SignPage = () => {
return updatedUsers
})
setUserInput('')
}
if (userInput.startsWith('npub')) {
@ -168,7 +183,7 @@ export const SignPage = () => {
)
}
const handleSign = async () => {
const handleCreate = async () => {
if (users.length === 0) {
toast.error(
'No signer/viewer is provided. At least add one signer or viewer.'
@ -329,8 +344,13 @@ export const SignPage = () => {
)
}
}
setIsLoading(false)
navigate(
`${appPrivateRoutes.verify}?file=${encodeURIComponent(
fileUrl
)}&key=${encodeURIComponent(encryptionKey)}`
)
}
if (authUrl) {
@ -413,8 +433,8 @@ export const SignPage = () => {
handleRemoveUser={handleRemoveUser}
/>
<Box sx={{ mt: 1, display: 'flex', justifyContent: 'center' }}>
<Button onClick={handleSign} variant='contained'>
Sign
<Button onClick={handleCreate} variant='contained'>
Create
</Button>
</Box>
</>

View File

@ -9,10 +9,10 @@ export const HomePage = () => {
return (
<Box className={styles.container}>
<Button
onClick={() => navigate(appPrivateRoutes.sign)}
onClick={() => navigate(appPrivateRoutes.create)}
variant='contained'
>
Sign
Create
</Button>
<Button
onClick={() => navigate(appPrivateRoutes.verify)}

View File

@ -1,5 +1,5 @@
import { HomePage } from '../pages/home'
import { SignPage } from '../pages/sign'
import { CreatePage } from '../pages/create'
import { LandingPage } from '../pages/landing/LandingPage'
import { Login } from '../pages/login'
import { ProfilePage } from '../pages/profile'
@ -8,7 +8,7 @@ import { VerifyPage } from '../pages/verify'
export const appPrivateRoutes = {
homePage: '/',
sign: '/sign',
create: '/create',
verify: '/verify'
}
@ -45,8 +45,8 @@ export const privateRoutes = [
element: <HomePage />
},
{
path: appPrivateRoutes.sign,
element: <SignPage />
path: appPrivateRoutes.create,
element: <CreatePage />
},
{
path: appPrivateRoutes.verify,