Skip to content

Commit 12ec523

Browse files
committed
improve search box
1 parent 33eea2b commit 12ec523

2 files changed

Lines changed: 61 additions & 4 deletions

File tree

assets/app.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,19 @@ const App = (() => {
514514
}
515515
};
516516

517+
// Manage search input visibility based on current page
518+
const updateSearchInputVisibility = () => {
519+
const searchInput = $('searchInput');
520+
const path = window.location.pathname;
521+
522+
// Show search input only on PR view and robot army pages
523+
if (path === '/' || path.startsWith('/u/') || path === '/robots' || path.match(/^\/robots\/gh\/[^\/]+$/)) {
524+
show(searchInput);
525+
} else {
526+
hide(searchInput);
527+
}
528+
};
529+
517530
// Initialize
518531
const init = async () => {
519532
const urlParams = new URLSearchParams(window.location.search);
@@ -525,6 +538,7 @@ const App = (() => {
525538

526539
// Handle stats page routing
527540
if (urlContext && urlContext.isStats) {
541+
updateSearchInputVisibility();
528542
await Stats.showStatsPage(state, githubAPI, loadCurrentUser,
529543
() => User.updateUserDisplay(state, initiateLogin),
530544
setupHamburgerMenu,
@@ -536,6 +550,7 @@ const App = (() => {
536550
// Handle notifications page routing
537551
const path = window.location.pathname;
538552
if (path === '/notifications' || path.match(/^\/notifications\/gh\/[^\/]+$/)) {
553+
updateSearchInputVisibility();
539554
const token = Auth.getStoredToken();
540555
if (token) {
541556
try {
@@ -552,6 +567,7 @@ const App = (() => {
552567

553568
// Handle robots page routing
554569
if (path === '/robots' || path.match(/^\/robots\/gh\/[^\/]+$/)) {
570+
updateSearchInputVisibility();
555571
const token = Auth.getStoredToken();
556572
if (!token) {
557573
showToast("Please login to configure Robot Army", "error");
@@ -636,12 +652,14 @@ const App = (() => {
636652

637653
// Demo mode - only if explicitly requested
638654
if (demo === "true") {
655+
updateSearchInputVisibility();
639656
initializeDemoMode();
640657
return;
641658
}
642659

643660
// Check for authentication
644661
if (!state.accessToken) {
662+
updateSearchInputVisibility();
645663
if (urlContext && urlContext.username && !urlContext.isStats && !urlContext.isSettings && !urlContext.isNotifications) {
646664
// Only load PRs for actual user PR dashboard pages
647665
try {
@@ -677,6 +695,7 @@ const App = (() => {
677695

678696
// Authenticated flow
679697
try {
698+
updateSearchInputVisibility();
680699
await loadCurrentUser();
681700

682701
// If at root URL, redirect to user's page
@@ -703,6 +722,12 @@ const App = (() => {
703722
await User.loadPullRequests(state, githubAPI, state.isDemoMode);
704723
// Update org filter again after PRs are loaded to include PR organizations
705724
await User.updateOrgFilter(state, parseURL, githubAPI);
725+
726+
// Reset search input placeholder for PR view
727+
const searchInput = $("searchInput");
728+
if (searchInput) {
729+
searchInput.placeholder = "Search PRs...";
730+
}
706731
}
707732

708733
showMainContent();

assets/robots.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,12 @@ export const Robots = (() => {
311311
console.log("[showSettingsPage] Hiding robot config");
312312
hide(robotConfig);
313313
}
314+
315+
// Hide search input when showing organization list
316+
const searchInput = $("searchInput");
317+
if (searchInput) {
318+
hide(searchInput);
319+
}
314320

315321
// Show organization list similar to stats page
316322
await showOrganizationList(
@@ -384,6 +390,24 @@ export const Robots = (() => {
384390

385391
console.log("[showSettingsPage] Calling renderRobotCards...");
386392
renderRobotCards();
393+
394+
// Set up search functionality for robots
395+
const searchInput = $("searchInput");
396+
if (searchInput) {
397+
// Remove any existing listeners first
398+
const newSearchInput = searchInput.cloneNode(true);
399+
searchInput.parentNode.replaceChild(newSearchInput, searchInput);
400+
401+
// Add new listener for robot filtering
402+
newSearchInput.addEventListener("input", (e) => {
403+
const searchTerm = e.target.value;
404+
renderRobotCards(searchTerm);
405+
});
406+
407+
// Update placeholder text for robot page
408+
newSearchInput.placeholder = "Search robots...";
409+
}
410+
387411
console.log("[showSettingsPage] Completed setup");
388412
console.log("[showSettingsPage] Completed successfully");
389413
} catch (error) {
@@ -489,23 +513,31 @@ export const Robots = (() => {
489513
window.location.href = `/robots/gh/${selectedOrg}`;
490514
};
491515

492-
const renderRobotCards = () => {
516+
const renderRobotCards = (searchTerm = '') => {
493517
console.log("[renderRobotCards] Starting...");
494518
const container = $("robotCards");
495519
if (!container) {
496520
console.error("[renderRobotCards] ERROR: robotCards container not found");
497521
return;
498522
}
499523

524+
// Filter robots based on search term
525+
const filteredRobots = searchTerm
526+
? robotDefinitions.filter(robot =>
527+
robot.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
528+
robot.description.toLowerCase().includes(searchTerm.toLowerCase())
529+
)
530+
: robotDefinitions;
531+
500532
console.log(
501533
"[renderRobotCards] Found container, rendering",
502-
robotDefinitions.length,
534+
filteredRobots.length,
503535
"robots",
504536
);
505537

506538
try {
507539
console.log("[renderRobotCards] Creating robot cards HTML...");
508-
const cardsHtml = robotDefinitions
540+
const cardsHtml = filteredRobots
509541
.map((robot) => {
510542
console.log("[renderRobotCards] Creating card for robot:", robot.id);
511543
return createRobotCard(robot);
@@ -519,7 +551,7 @@ export const Robots = (() => {
519551
container.innerHTML = cardsHtml;
520552

521553
console.log("[renderRobotCards] Adding event listeners...");
522-
robotDefinitions.forEach((robot) => {
554+
filteredRobots.forEach((robot) => {
523555
const toggle = $(`toggle-${robot.id}`);
524556
if (toggle) {
525557
toggle.addEventListener("change", (e) => {

0 commit comments

Comments
 (0)