mirror of
https://github.com/billsonnn/nitro-react.git
synced 2025-01-18 13:26:27 +01:00
Update
This commit is contained in:
parent
58ccb340df
commit
87d16f355c
@ -10,7 +10,7 @@ export const NitropediaView: FC<{}> = props =>
|
||||
{
|
||||
const [ content, setContent ] = useState<string>(null);
|
||||
const [ header, setHeader] = useState<string>('');
|
||||
const [wH, setWH] = useState<{w:number,h:number}>({ w:0, h:0 });
|
||||
const [ dimensions, setDimensions ] = useState<{ width: number, height: number}>(null);
|
||||
const elementRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const openPage = useCallback(async (link: string) =>
|
||||
@ -22,19 +22,26 @@ export const NitropediaView: FC<{}> = props =>
|
||||
if(!response) return;
|
||||
|
||||
const text = await response.text();
|
||||
|
||||
const splitData = text.split(NEW_LINE_REGEX);
|
||||
const line = splitData.shift().split('|');
|
||||
|
||||
setWH({ w: 0, h: 0 });
|
||||
|
||||
BatchUpdates(() =>
|
||||
{
|
||||
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]) });
|
||||
|
||||
setDimensions(prevValue =>
|
||||
{
|
||||
if(line[1] && (line[1].split(';').length === 2))
|
||||
{
|
||||
return {
|
||||
width: parseInt(line[1].split(';')[0]),
|
||||
height: parseInt(line[1].split(';')[1])
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
setContent(splitData.join(''));
|
||||
});
|
||||
}
|
||||
@ -91,8 +98,8 @@ export const NitropediaView: FC<{}> = props =>
|
||||
if(!content) return null;
|
||||
|
||||
return (
|
||||
<NitroCardView className="nitropedia" theme="primary-slim" style={wH.w && wH.h ? { width: wH.w, height: wH.h } : {} }>
|
||||
<NitroCardHeaderView headerText={header} onCloseClick={() => setContent(null)}/>
|
||||
<NitroCardView className="nitropedia" theme="primary-slim" style={ dimensions ? { width: dimensions.width, height: dimensions.height } : {} }>
|
||||
<NitroCardHeaderView headerText={header} onCloseClick={ () => setContent(null) }/>
|
||||
<NitroCardContentView>
|
||||
<Base fit innerRef={ elementRef } className="text-black" dangerouslySetInnerHTML={{ __html: content }} />
|
||||
</NitroCardContentView>
|
||||
|
Loading…
Reference in New Issue
Block a user