Fixed spell description key issue

This commit is contained in:
Benjamin Sherriff
2023-10-23 20:36:25 -04:00
parent 8c246c96e7
commit daf76071ea

View File

@@ -95,13 +95,15 @@ function parseText(text: string, capitalizeFirst?: boolean): (string | JSX.Eleme
const matches = text.matchAll(regex); const matches = text.matchAll(regex);
const result = []; const result = [];
let lastIndex = 0; let lastIndex = 0;
for (const match of matches) { for (const match of matches) {
const key = crypto.randomUUID();
const [full, type, name] = match; const [full, type, name] = match;
result.push(text.slice(lastIndex, match.index)); result.push(<span key={crypto.randomUUID()}>{text.slice(lastIndex, match.index)}</span>);
if (match.index !== undefined) { if (match.index !== undefined) {
if (type == 'dice') { if (type == 'dice') {
result.push( result.push(
<span onClick={() => handleLink(type, name)} className='link'> <span onClick={() => handleLink(type, name)} className='link' key={key}>
{name} {name}
</span> </span>
); );
@@ -109,26 +111,31 @@ function parseText(text: string, capitalizeFirst?: boolean): (string | JSX.Eleme
// scaledice format is {@scaledice 1d6|1-9|1d6|}. Parse this out into dice, levels, and dice again. // scaledice format is {@scaledice 1d6|1-9|1d6|}. Parse this out into dice, levels, and dice again.
const [dice, levels] = name.split('|'); const [dice, levels] = name.split('|');
result.push( result.push(
<span onClick={() => handleLink('dice', dice)} className='link'> <span onClick={() => handleLink('dice', dice)} className='link' key={key}>
{dice} {dice}
</span> </span>
); );
} else if (type == 'bold') { } else if (type == 'bold') {
result.push(<span style={{ fontWeight: 'bold' }}>{name}</span>); result.push(
<span style={{ fontWeight: 'bold' }} key={key}>
{name}
</span>
);
} else if (type == 'subclass') { } else if (type == 'subclass') {
const [className, subclassName] = name.split('|'); const [className, subclassName] = name.split('|');
result.push( result.push(
<span> <span key={key}>
{capitalize(className)} ({capitalize(subclassName)}) {capitalize(className)} ({capitalize(subclassName)})
</span> </span>
); );
} else { } else {
result.push(<span>{capitalizeFirst ? capitalize(name) : name}</span>); result.push(<span key={key}>{capitalizeFirst ? capitalize(name) : name}</span>);
} }
lastIndex = match.index + full.length; lastIndex = match.index + full.length;
} }
} }
result.push(text.slice(lastIndex)); result.push(<span key={crypto.randomUUID()}>{text.slice(lastIndex)}</span>);
return result; return result;
} }