Neighbourhood.omg.lol/Components/ExternalPageComponent.razor
Gordon Pedersen 0c3836b0c8 Simplify and standardise a lot of the loading
I was overcomplicating everything trying to reduce the render lag.
Just simplify it a bit. It works.
2024-06-13 14:46:24 +10:00

36 lines
1,018 B
Text

@inject IJSRuntime JS
@inject State State
@if(Html != null) {
<iframe id="@id" frameborder="0" scrolling="no" srcdoc="@Html" onload="() => iframeResize({ license: 'GPLv3' })"></iframe>
}
@code {
[Parameter]
public string Url { get; set; }
[Parameter]
public string id { get; set; }
public MarkupString? Html { get; set; }
protected override void OnInitialized() {
base.OnInitialized();
State.CurrentPage = Page.Other;
}
protected override async Task OnAfterRenderAsync(bool firstRender) {
if(firstRender){
await Reload();
}
}
public async Task Reload() {
if (Html == null){
RestService api = new RestService();
Html = await api.GetHtml(Url);
string? HtmlString = Html?.ToString();
HtmlString = HtmlString?.Replace("</head>", "<base target='_blank'></head>");
HtmlString = HtmlString?.Replace("</body>", "<script src='https://cdn.jsdelivr.net/npm/@iframe-resizer/child'></script></body>");
Html = (MarkupString)HtmlString;
}
await InvokeAsync(StateHasChanged);
}
}