Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/components/BootstrapBlazor.PdfReader/PdfReader.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
{
<div class="bb-view-toolbar">
<div class="bb-view-title">
<div class="bb-view-icon bb-view-bar" title="@Localizer["ToggleSidebar"]"><i class="fa-solid fa-bars"></i></div>
@if (EnableThumbnails)
{
<div class="bb-view-icon bb-view-bar" title="@Localizer["ToggleSidebar"]"><i class="fa-solid fa-bars"></i></div>
}
<span class="bb-view-subject">@_docTitle</span>
</div>
<div class="@ViewBodyString">
Expand Down
10 changes: 10 additions & 0 deletions src/components/BootstrapBlazor.PdfReader/PdfReader.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public partial class PdfReader
private string? _currentScale;
private string? _dropdownItemCheckIcon;
private string? _dropdownItemDefaultIcon;
private bool _enableThumbnails = true;

private string CurrentPageString
{
Expand Down Expand Up @@ -218,6 +219,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
_currentPage = CurrentPage;
_url = Url;
_currentScale = CurrentScale;
_enableThumbnails = EnableThumbnails;
}

if (_url != Url)
Expand All @@ -241,6 +243,14 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
_currentScale = CurrentScale;
await InvokeVoidAsync("scale", Id, _currentScale);
}
if (_enableThumbnails != EnableThumbnails)
{
_enableThumbnails = EnableThumbnails;
if (_enableThumbnails)
{
await InvokeVoidAsync("resetThumbnails", Id);
Comment thread
ArgoZhang marked this conversation as resolved.
}
}
}

/// <summary>
Expand Down
21 changes: 14 additions & 7 deletions src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ export function scale(id, scale) {
}
}

export function resetThumbnails(id) {
const { el, pdfViewer } = Data.get(id);
if (pdfViewer) {
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing null check for el parameter. The function retrieves el from Data.get(id) but only checks if pdfViewer exists before calling resetThumbnailsView(el, pdfViewer). If el is null or undefined, it will be passed to resetThumbnailsView, which will fail when trying to call el.querySelector() at line 206. Add a check: if (el && pdfViewer) { ... }.

Suggested change
if (pdfViewer) {
if (el && pdfViewer) {

Copilot uses AI. Check for mistakes.
resetThumbnailsView(el, pdfViewer);
}
}

const addEventListener = (el, pdfViewer, eventBus, invoke, options) => {
eventBus.on("pagesinit", async () => {
if (options.fitMode) {
Expand Down Expand Up @@ -139,7 +146,7 @@ const addEventListener = (el, pdfViewer, eventBus, invoke, options) => {
pageNumberEl.value = page;
}

if (options.enableThumbnails) {
if (options.enableThumbnails || false) {
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expression options.enableThumbnails || false is redundant. Since options.enableThumbnails is already a boolean, the || false doesn't change the behavior. If enableThumbnails is true, it returns true; if it's false, the expression evaluates to false. This should be simplified to just options.enableThumbnails.

Suggested change
if (options.enableThumbnails || false) {
if (options.enableThumbnails) {

Copilot uses AI. Check for mistakes.
const thumbnailsContainer = el.querySelector(".bb-view-thumbnails");
if (thumbnailsContainer) {
const active = thumbnailsContainer.querySelector('.active');
Expand Down Expand Up @@ -179,9 +186,9 @@ const addEventListener = (el, pdfViewer, eventBus, invoke, options) => {
EventHandler.on(minus, "click", e => updateScale(pdfViewer, e.target, -1));
EventHandler.on(plus, "click", e => updateScale(pdfViewer, e.target, 1));

const thumbnailsToggle = el.querySelector(".bb-view-bar");
if (thumbnailsToggle) {
EventHandler.on(thumbnailsToggle, "click", e => {
const titleEl = el.querySelector(".bb-view-title");
if (titleEl) {
EventHandler.on(titleEl, "click", '.bb-view-bar', e => {
const thumbnailsEl = el.querySelector(".bb-view-thumbnails");
thumbnailsEl.classList.toggle("show");
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing null check for thumbnailsEl. The code queries for .bb-view-thumbnails but doesn't verify it exists before calling classList.toggle(). While the event delegation pattern ensures this handler only fires when .bb-view-bar is clicked, there's a timing issue: during dynamic state changes (e.g., when EnableThumbnails transitions from true to false), the .bb-view-bar element might still exist briefly while .bb-view-thumbnails is already removed, leading to a null reference error. Add a null check: if (thumbnailsEl) { thumbnailsEl.classList.toggle("show"); }.

Suggested change
thumbnailsEl.classList.toggle("show");
if (thumbnailsEl) {
thumbnailsEl.classList.toggle("show");
}

Copilot uses AI. Check for mistakes.
});
Expand Down Expand Up @@ -314,9 +321,9 @@ export function dispose(id) {
EventHandler.off(towPagesOneView, "click");
}

const thumbnailsToggle = el.querySelector(".bb-view-bar");
if (thumbnailsToggle) {
EventHandler.off(thumbnailsToggle, "click");
const titleEl = el.querySelector(".bb-view-title");
if (titleEl) {
EventHandler.off(titleEl, "click");
}

const thumbnailsContainer = el.querySelector(".bb-view-thumbnails");
Expand Down