Skip to content

Commit 23f7501

Browse files
fix: resolve all linting errors
- Fix React Hook dependency warnings by using useCallback and useMemo - Fix TypeScript unsafe argument errors with proper Server type - Fix nullish coalescing operator preferences - Fix floating promise warnings with void operator - All ESLint warnings and errors now resolved Ensures clean code quality for PR merge
1 parent f02fe1f commit 23f7501

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/app/_components/InstalledScriptsTab.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { useState, useEffect, useRef } from 'react';
3+
import { useState, useEffect, useRef, useCallback, useMemo } from 'react';
44
import { api } from '~/trpc/react';
55
import { Terminal } from './Terminal';
66
import { StatusBadge } from './Badge';
@@ -160,11 +160,11 @@ export function InstalledScriptsTab() {
160160
});
161161

162162

163-
const scripts: InstalledScript[] = (scriptsData?.scripts as InstalledScript[]) ?? [];
163+
const scripts: InstalledScript[] = useMemo(() => (scriptsData?.scripts as InstalledScript[]) ?? [], [scriptsData?.scripts]);
164164
const stats = statsData?.stats;
165165

166166
// Function to fetch container statuses
167-
const fetchContainerStatuses = () => {
167+
const fetchContainerStatuses = useCallback(() => {
168168
console.log('Fetching container statuses...', { scriptsCount: scripts.length });
169169
const containersWithIds = scripts
170170
.filter(script => script.container_id)
@@ -185,7 +185,7 @@ export function InstalledScriptsTab() {
185185
if (containersWithIds.length > 0) {
186186
containerStatusMutation.mutate({ containers: containersWithIds });
187187
}
188-
};
188+
}, [scripts, containerStatusMutation]);
189189

190190
// Run cleanup when component mounts and scripts are loaded (only once)
191191
useEffect(() => {
@@ -203,7 +203,7 @@ export function InstalledScriptsTab() {
203203
const interval = setInterval(fetchContainerStatuses, 60000); // Every 60 seconds
204204
return () => clearInterval(interval);
205205
}
206-
}, [scripts.length]);
206+
}, [scripts.length, fetchContainerStatuses]);
207207

208208
// Trigger status check when component becomes visible (tab is active)
209209
useEffect(() => {
@@ -215,20 +215,20 @@ export function InstalledScriptsTab() {
215215

216216
return () => clearTimeout(timeoutId);
217217
}
218-
}, []); // Empty dependency array means this runs on mount
218+
}, [scripts.length, fetchContainerStatuses]); // Include dependencies
219219

220220
// Also trigger status check when scripts data loads
221221
useEffect(() => {
222222
if (scripts.length > 0 && !isLoading) {
223223
console.log('Scripts data loaded, triggering status check');
224224
fetchContainerStatuses();
225225
}
226-
}, [scriptsData, isLoading]);
226+
}, [scriptsData, isLoading, scripts.length, fetchContainerStatuses]);
227227

228228
// Update scripts with container statuses
229229
const scriptsWithStatus = scripts.map(script => ({
230230
...script,
231-
container_status: script.container_id ? containerStatuses[script.container_id] || 'unknown' : undefined
231+
container_status: script.container_id ? containerStatuses[script.container_id] ?? 'unknown' : undefined
232232
}));
233233

234234
// Filter and sort scripts

src/server/api/routers/installedScripts.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getDatabase } from "~/server/database";
44
import { exec } from "child_process";
55
import { promisify } from "util";
66
import { getSSHExecutionService } from "~/server/ssh-execution-service";
7+
import type { Server } from "~/types/server";
78

89
const execAsync = promisify(exec);
910

@@ -49,7 +50,7 @@ async function getLocalContainerStatuses(containerIds: string[]): Promise<Record
4950
}
5051

5152
// Helper function to check remote container statuses (multiple containers per server)
52-
async function getRemoteContainerStatuses(containerIds: string[], server: any): Promise<Record<string, 'running' | 'stopped' | 'unknown'>> {
53+
async function getRemoteContainerStatuses(containerIds: string[], server: Server): Promise<Record<string, 'running' | 'stopped' | 'unknown'>> {
5354
return new Promise((resolve) => {
5455
const sshService = getSSHExecutionService();
5556
const statusMap: Record<string, 'running' | 'stopped' | 'unknown'> = {};
@@ -59,7 +60,7 @@ async function getRemoteContainerStatuses(containerIds: string[], server: any):
5960
statusMap[containerId] = 'unknown';
6061
}
6162

62-
sshService.executeCommand(
63+
void sshService.executeCommand(
6364
server,
6465
'pct list',
6566
(data: string) => {
@@ -682,9 +683,7 @@ export const installedScriptsRouter = createTRPCRouter({
682683

683684
for (const { containerId, server } of remoteContainers) {
684685
const serverKey = `${server.id}-${server.name}`;
685-
if (!serverGroups[serverKey]) {
686-
serverGroups[serverKey] = [];
687-
}
686+
serverGroups[serverKey] ??= [];
688687
serverGroups[serverKey].push({ containerId, server });
689688
}
690689

@@ -697,7 +696,7 @@ export const installedScriptsRouter = createTRPCRouter({
697696
if (!server) continue;
698697

699698
const containerIds = containers.map(c => c.containerId).filter(Boolean);
700-
const serverStatuses = await getRemoteContainerStatuses(containerIds, server);
699+
const serverStatuses = await getRemoteContainerStatuses(containerIds, server as Server);
701700

702701
// Merge the results
703702
Object.assign(statusMap, serverStatuses);

0 commit comments

Comments
 (0)