optional nitropedia width/height

This commit is contained in:
Layne 2022-03-24 23:09:15 -04:00
parent 4776e3d827
commit 58ccb340df

View File

@ -10,6 +10,7 @@ export const NitropediaView: FC<{}> = props =>
{ {
const [ content, setContent ] = useState<string>(null); const [ content, setContent ] = useState<string>(null);
const [ header, setHeader] = useState<string>(''); const [ header, setHeader] = useState<string>('');
const [wH, setWH] = useState<{w:number,h:number}>({ w:0, h:0 });
const elementRef = useRef<HTMLDivElement>(null); const elementRef = useRef<HTMLDivElement>(null);
const openPage = useCallback(async (link: string) => const openPage = useCallback(async (link: string) =>
@ -24,9 +25,16 @@ export const NitropediaView: FC<{}> = props =>
const splitData = text.split(NEW_LINE_REGEX); const splitData = text.split(NEW_LINE_REGEX);
setWH({ w: 0, h: 0 });
BatchUpdates(() => BatchUpdates(() =>
{ {
setHeader(splitData.shift()); let line = splitData.shift().split('|');
setHeader(line[0]);
if(line[1] && line[1].split(';').length === 2)
setWH({ w: parseInt(line[1].split(';')[0]), h: parseInt(line[1].split(';')[1]) });
setContent(splitData.join('')); setContent(splitData.join(''));
}); });
} }
@ -83,7 +91,7 @@ export const NitropediaView: FC<{}> = props =>
if(!content) return null; if(!content) return null;
return ( return (
<NitroCardView className="nitropedia" theme="primary-slim"> <NitroCardView className="nitropedia" theme="primary-slim" style={wH.w && wH.h ? { width: wH.w, height: wH.h } : {} }>
<NitroCardHeaderView headerText={header} onCloseClick={() => setContent(null)}/> <NitroCardHeaderView headerText={header} onCloseClick={() => setContent(null)}/>
<NitroCardContentView> <NitroCardContentView>
<Base fit innerRef={ elementRef } className="text-black" dangerouslySetInnerHTML={{ __html: content }} /> <Base fit innerRef={ elementRef } className="text-black" dangerouslySetInnerHTML={{ __html: content }} />