fix: resolve all 15 frontend ESLint errors for green CI

- Replace setState-in-effect with state-based tracking (AdminLayout, EditCategoryModal)
- Convert inline SortIcon component to getSortIcon function (TreeTableView)
- Remove unused catch parameters (CreateCategoryModal, EditCategoryModal)
- Replace `any` types with proper types (SessionFilters, AdminCategoriesPage, SessionHistoryPage)
- Fix unused destructuring variable (StepRatingModal)
- Fix constant binary expression in test (utils.test.ts)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
chihlasm
2026-02-08 18:43:16 -05:00
parent 6752a55ff8
commit f2ae3a51fa
9 changed files with 36 additions and 27 deletions

View File

@@ -5,12 +5,16 @@ import { AdminSidebar } from './AdminSidebar'
export function AdminLayout() {
const [mobileOpen, setMobileOpen] = useState(false)
const [prevPathname, setPrevPathname] = useState('')
const location = useLocation()
// Close on route change
useEffect(() => {
setMobileOpen(false)
}, [location.pathname])
// Close on route change (state-based tracking, no effect needed)
if (prevPathname !== location.pathname) {
setPrevPathname(location.pathname)
if (mobileOpen) {
setMobileOpen(false)
}
}
const handleKeyDown = useCallback((e: KeyboardEvent) => {
if (e.key === 'Escape') setMobileOpen(false)

View File

@@ -43,7 +43,7 @@ export function CreateCategoryModal({
// Reset form on success
setName('')
setDescription('')
} catch (err) {
} catch {
setError('Failed to create category')
}
}

View File

@@ -1,4 +1,4 @@
import { useState, useEffect } from 'react'
import { useState } from 'react'
import { X } from 'lucide-react'
import { cn } from '@/lib/utils'
import type { StepCategoryListItem } from '@/types'
@@ -21,14 +21,17 @@ export function EditCategoryModal({
const [name, setName] = useState('')
const [description, setDescription] = useState('')
const [error, setError] = useState('')
const [prevCategoryId, setPrevCategoryId] = useState<string | null>(null)
// Pre-populate form when category changes
useEffect(() => {
if (category) {
setName(category.name)
setDescription(category.description || '')
}
}, [category])
// Pre-populate form when category changes (state-based tracking)
if (category && category.id !== prevCategoryId) {
setPrevCategoryId(category.id)
setName(category.name)
setDescription(category.description || '')
}
if (!category && prevCategoryId !== null) {
setPrevCategoryId(null)
}
if (!isOpen || !category) return null
@@ -51,7 +54,7 @@ export function EditCategoryModal({
name: name.trim(),
description: description.trim()
})
} catch (err) {
} catch {
setError('Failed to update category')
}
}

View File

@@ -54,7 +54,7 @@ export function TreeTableView({
onSortChange?.(apiSort)
}
const SortIcon = ({ column }: { column: SortColumn }) => {
const getSortIcon = (column: SortColumn) => {
if (sortColumn !== column) return null
return sortDirection === 'asc' ? (
<ChevronUp className="h-3.5 w-3.5" />
@@ -79,7 +79,7 @@ export function TreeTableView({
>
<div className="flex items-center gap-1">
Name
<SortIcon column="name" />
{getSortIcon('name')}
</div>
</th>
<th className="hidden md:table-cell px-4 py-3 text-left text-sm font-medium text-muted-foreground">
@@ -91,7 +91,7 @@ export function TreeTableView({
>
<div className="flex items-center gap-1">
Category
<SortIcon column="category" />
{getSortIcon('category')}
</div>
</th>
<th className="hidden xl:table-cell px-4 py-3 text-left text-sm font-medium text-muted-foreground">
@@ -103,7 +103,7 @@ export function TreeTableView({
>
<div className="flex items-center justify-center gap-1">
Ver.
<SortIcon column="version" />
{getSortIcon('version')}
</div>
</th>
<th
@@ -112,7 +112,7 @@ export function TreeTableView({
>
<div className="flex items-center justify-center gap-1">
Uses
<SortIcon column="usage" />
{getSortIcon('usage')}
</div>
</th>
<th
@@ -121,7 +121,7 @@ export function TreeTableView({
>
<div className="flex items-center gap-1">
Updated
<SortIcon column="updated" />
{getSortIcon('updated')}
</div>
</th>
<th className="px-4 py-3 text-right text-sm font-medium text-muted-foreground">

View File

@@ -33,11 +33,12 @@ export function SessionFilters({ filters, onChange, onClear, trees }: SessionFil
const [showDatePicker, setShowDatePicker] = useState(false)
const [localDateRange, setLocalDateRange] = useState<DateRange | undefined>(filters.dateRange)
const filtersDateRange = filters.dateRange
useEffect(() => {
setLocalDateRange(filters.dateRange)
}, [filters.dateRange])
setLocalDateRange(filtersDateRange)
}, [filtersDateRange])
const handleFilterChange = (key: keyof SessionFilterState, value: any) => {
const handleFilterChange = (key: keyof SessionFilterState, value: SessionFilterState[keyof SessionFilterState]) => {
onChange({ ...filters, [key]: value })
}

View File

@@ -62,7 +62,7 @@ export function StepRatingModal({
const handleSubmit = async () => {
// Filter out steps with no rating
const ratingsToSubmit = new Map(
Array.from(ratings.entries()).filter(([_, data]) => data.rating > 0)
Array.from(ratings.entries()).filter(([, data]) => data.rating > 0)
)
if (ratingsToSubmit.size === 0) {

View File

@@ -7,7 +7,8 @@ describe('cn', () => {
})
it('handles conditional classes', () => {
expect(cn('base', false && 'hidden', 'visible')).toBe('base visible')
const isHidden = false
expect(cn('base', isHidden && 'hidden', 'visible')).toBe('base visible')
})
it('deduplicates tailwind classes', () => {

View File

@@ -13,7 +13,7 @@ import { toast } from '@/lib/toast'
export function AdminCategoriesPage() {
const [categories, setCategories] = useState<StepCategoryListItem[]>([])
const [allSteps, setAllSteps] = useState<any[]>([])
const [allSteps, setAllSteps] = useState<{ category_id?: string }[]>([])
const [isLoading, setIsLoading] = useState(true)
const [showCreateModal, setShowCreateModal] = useState(false)
const [showEditModal, setShowEditModal] = useState(false)

View File

@@ -75,7 +75,7 @@ export function SessionHistoryPage() {
const loadSessions = async () => {
setIsLoading(true)
try {
const params: any = {}
const params: Record<string, string | boolean> = {}
// Tab filter (all/active/completed)
if (filter !== 'all') {