Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
define AnonSet context to share anon set state
- Loading branch information
Showing
11 changed files
with
121 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { SubmitProofRequest } from '@components' | ||
|
||
export default function Page({ searchParams: { anonSet } }) { | ||
return <SubmitProofRequest anonSet={anonSet} /> | ||
export default function Page() { | ||
return <SubmitProofRequest /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useRef } from 'react' | ||
import { readJsonFile } from '#/read-json-file' | ||
import { ScrollableContainer } from '@components/ScrollableContainer' | ||
import { useAnonSet } from '@context/anonset' | ||
|
||
export function AnonSetFileInput() { | ||
const { anonSet, setAnonSet } = useAnonSet() | ||
const inputRef = useRef<HTMLInputElement>(null) | ||
|
||
const onClick = () => { | ||
inputRef.current?.click() | ||
} | ||
|
||
const onChange = async (event: React.ChangeEvent<HTMLInputElement>) => { | ||
if (event.target.files !== undefined && event.target.files !== null) { | ||
const parsedData = await readJsonFile(event.target.files[0]) | ||
|
||
setAnonSet(parsedData) | ||
} | ||
} | ||
|
||
return anonSet.length === 0 ? ( | ||
<> | ||
<input | ||
type='file' | ||
accept='.json,application/json' | ||
onChange={onChange} | ||
className='hidden' | ||
ref={inputRef} | ||
/> | ||
<button | ||
type='button' | ||
className='nes-btn is-warning w-1/4 self-center' | ||
onClick={onClick} | ||
> | ||
Upload file | ||
</button> | ||
</> | ||
) : ( | ||
<ScrollableContainer data={anonSet} /> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { createContext, FC, ReactNode, useContext, useState } from 'react' | ||
|
||
interface AnonSetContextType { | ||
anonSet: string[] | ||
setAnonSet: (anonSet: string[]) => void | ||
resetAnonSet: () => void | ||
} | ||
|
||
const AnonSetContext = createContext<AnonSetContextType | null>(null) | ||
|
||
export const useAnonSet = () => { | ||
const context = useContext(AnonSetContext) | ||
|
||
if (context === null) | ||
throw new Error('useAnonSet must be used within a AnonSetProvider') | ||
|
||
return context | ||
} | ||
|
||
export const AnonSetProvider: FC<{ children: ReactNode }> = ({ children }) => { | ||
const [anonSet, setAnonSet] = useState<string[]>([]) | ||
const resetAnonSet = () => { | ||
setAnonSet([]) | ||
} | ||
|
||
return ( | ||
<AnonSetContext.Provider value={{ anonSet, resetAnonSet, setAnonSet }}> | ||
{children} | ||
</AnonSetContext.Provider> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters