feat(tools): remove assertion in params inside challenge editor (#49931)

This commit is contained in:
Muhammed Mustafa
2023-04-03 20:38:22 +02:00
committed by GitHub
parent b9fd70cdfc
commit 6e89d3b2dd
2 changed files with 14 additions and 30 deletions

View File

@@ -1,17 +1,9 @@
export interface ChallengeContentRequiredProps {
superblock: string;
block: string;
challenge: string;
export interface BlockRequiredProps {
superblock?: string;
block?: string;
}
export interface ChallengeContentRequiredProps extends BlockRequiredProps {
challenge?: string;
content: string;
}
export interface ChallengeRequiredProps {
superblock: string;
block: string;
challenge: string;
}
export interface BlockRequiredProps {
superblock: string;
block: string;
}

View File

@@ -22,11 +22,7 @@ const Editor = () => {
fileData: ''
});
const [input, setInput] = useState('');
const params = useParams() as {
superblock: string;
block: string;
challenge: string;
};
const { superblock, block, challenge } = useParams();
useEffect(() => {
fetchData();
@@ -35,9 +31,7 @@ const Editor = () => {
const fetchData = () => {
setLoading(true);
fetch(
`${API_LOCATION}/${params.superblock}/${params.block}/${params.challenge}`
)
fetch(`${API_LOCATION}/${superblock}/${block}/${challenge}`)
.then(res => res.json() as Promise<ChallengeContent>)
.then(
content => {
@@ -70,7 +64,7 @@ const Editor = () => {
<div>
<h1>{items.name}</h1>
<span className='breadcrumb'>
{params.superblock} / {params.block}
{superblock} / {block}
</span>
<CodeMirror
value={input}
@@ -86,15 +80,13 @@ const Editor = () => {
}}
/>
<SaveChallenge
superblock={params.superblock}
block={params.block}
challenge={params.challenge}
superblock={superblock}
block={block}
challenge={challenge}
content={input}
/>
<p>
<Link to={`/${params.superblock}/${params.block}`}>
Return to Block
</Link>
<Link to={`/${superblock}/${block}`}>Return to Block</Link>
</p>
</div>
);