Skip to content

Commit 86b85b3

Browse files
committed
fix: Resolve select all checkbox bug and progress bar display issues
- Changed checkbox event handlers from onClick to onChange for proper React behavior - Simplified disabled condition to check only percentage < 100 - Fixed progress bar calculation using Math.round instead of Math.floor to reach 100% - Fixed progress bar positioning with explicit left:0 and top:0 to eliminate visual gap - Improved "Select all on this page" checkbox logic to properly validate page users Fixes the bug where select all checkboxes were not responding to user clicks and progress bar was stuck at 99% instead of reaching 100% completion.
1 parent a54ef69 commit 86b85b3

4 files changed

Lines changed: 27 additions & 25 deletions

File tree

public/index.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/components/Toolbar.tsx

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { ChangeEvent, useState } from "react";
22
import { State } from "../model/state";
3-
import { assertUnreachable, copyListToClipboard, getUsersForDisplay } from "../utils/utils";
3+
import { assertUnreachable, copyListToClipboard, getCurrentPageUnfollowers, getUsersForDisplay } from "../utils/utils";
44
import { SettingMenu } from "./SettingMenu";
55
import { SettingIcon } from "./icons/SettingIcon";
66
import { Timings } from "../model/timings";
@@ -10,7 +10,6 @@ interface ToolBarProps {
1010
isActiveProcess: boolean;
1111
state: State;
1212
setState: (state: State) => void;
13-
scanningPaused: boolean;
1413
toggleAllUsers: (e: ChangeEvent<HTMLInputElement>) => void;
1514
toggleCurrentePageUsers: (e: ChangeEvent<HTMLInputElement>) => void;
1615
currentTimings: Timings;
@@ -21,7 +20,6 @@ export const Toolbar = ({
2120
isActiveProcess,
2221
state,
2322
setState,
24-
scanningPaused,
2523
toggleAllUsers,
2624
toggleCurrentePageUsers,
2725
currentTimings,
@@ -127,22 +125,20 @@ export const Toolbar = ({
127125
type="checkbox"
128126
// Avoid allowing to select all before scan completed to avoid confusion
129127
// regarding what exactly is selected while scanning in progress.
130-
disabled={
131-
// if paused, allow to select all even if scan is not completed.
132-
state.percentage < 100 && !scanningPaused
133-
}
128+
disabled={state.percentage < 100}
134129
checked={
135-
state.selectedResults.length ===
136-
getUsersForDisplay(
137-
state.results,
138-
state.whitelistedResults,
139-
state.currentTab,
140-
state.searchTerm,
141-
state.filter,
142-
).length
130+
(() => {
131+
const displayed = getUsersForDisplay(state.results, state.whitelistedResults, state.currentTab, state.searchTerm, state.filter);
132+
const pageUsers = getCurrentPageUnfollowers(displayed, state.page);
133+
// Fix: Check if pageUsers is not empty and all are selected
134+
// Previous logic didn't account for empty page or partial selections correctly
135+
return pageUsers.length > 0 && pageUsers.every(u => state.selectedResults.some(s => s.id === u.id));
136+
})()
143137
}
144138
className="toggle-all-checkbox"
145-
onClick={toggleCurrentePageUsers}
139+
// Fix: Changed from onClick to onChange for proper React checkbox handling
140+
// onClick doesn't trigger reliably for controlled checkboxes
141+
onChange={toggleCurrentePageUsers}
146142
/>
147143
)}
148144
{state.status === "scanning" && (
@@ -151,10 +147,7 @@ export const Toolbar = ({
151147
type="checkbox"
152148
// Avoid allowing to select all before scan completed to avoid confusion
153149
// regarding what exactly is selected while scanning in progress.
154-
disabled={
155-
// if paused, allow to select all even if scan is not completed.
156-
state.percentage < 100 && !scanningPaused
157-
}
150+
disabled={state.percentage < 100}
158151
checked={
159152
state.selectedResults.length ===
160153
getUsersForDisplay(
@@ -166,7 +159,9 @@ export const Toolbar = ({
166159
).length
167160
}
168161
className="toggle-all-checkbox"
169-
onClick={toggleAllUsers}
162+
// Fix: Changed from onClick to onChange for proper React checkbox handling
163+
// onClick doesn't trigger reliably for controlled checkboxes
164+
onChange={toggleAllUsers}
170165
/>
171166
)}
172167
</div>

src/main.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ function App() {
257257
}
258258
const newState: State = {
259259
...prevState,
260-
percentage: Math.floor((currentFollowedUsersCount / totalFollowedUsersCount) * 100),
260+
// Fix: Changed from Math.floor to Math.round to ensure progress reaches 100%
261+
// Math.floor would leave progress at 99% when near completion
262+
percentage: Math.round((currentFollowedUsersCount / totalFollowedUsersCount) * 100),
261263
results,
262264
};
263265
return newState;
@@ -299,7 +301,9 @@ function App() {
299301
let counter = 0;
300302
for (const user of state.selectedResults) {
301303
counter += 1;
302-
const percentage = Math.floor((counter / state.selectedResults.length) * 100);
304+
// Fix: Changed from Math.floor to Math.round to ensure progress reaches 100%
305+
// Math.floor would leave progress at 99% when near completion
306+
const percentage = Math.round((counter / state.selectedResults.length) * 100);
303307
try {
304308
await fetch(unfollowUserUrlGenerator(user.id), {
305309
headers: {
@@ -400,7 +404,6 @@ function App() {
400404
<Toolbar
401405
state={state}
402406
setState={setState}
403-
scanningPaused={scanningPaused}
404407
isActiveProcess={isActiveProcess}
405408
toggleAllUsers={toggleAllUsers}
406409
toggleCurrentePageUsers={toggleCurrentePageUsers}

src/styles/main.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ html {
154154
width: 100%;
155155
height: 8px;
156156
position: absolute;
157+
// Fix: Added explicit positioning to prevent white gap at the end
158+
// Without left: 0 and top: 0, the progress bar doesn't fully align
159+
left: 0;
160+
top: 0;
157161
}
158162

159163
.results-container,

0 commit comments

Comments
 (0)