Skip to content
Open
Changes from all commits
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
45 changes: 21 additions & 24 deletions examples/ts-code-mode-web/src/lib/reports/use-persisted-reports.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { useState, useEffect, useCallback, useRef } from 'react'
import { useState, useEffect, useCallback } from 'react'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟑 Minor

Fix import member order to satisfy ESLint.

Line 3 currently violates sort-imports (members should be alphabetized), which can fail lint checks.

Suggested fix
-import { useState, useEffect, useCallback } from 'react'
+import { useCallback, useEffect, useState } from 'react'
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { useState, useEffect, useCallback } from 'react'
import { useCallback, useEffect, useState } from 'react'
🧰 Tools
πŸͺ› ESLint

[error] 3-3: Member 'useEffect' of the import declaration should be sorted alphabetically.

(sort-imports)

πŸ€– Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/ts-code-mode-web/src/lib/reports/use-persisted-reports.ts` at line
3, The import member order in the React import in use-persisted-reports.ts is
not alphabetized and violates sort-imports; reorder the named imports in the
statement "import { useState, useEffect, useCallback } from 'react'" to
alphabetic order (useCallback, useEffect, useState) so the import line follows
ESLint's sort-imports rule.

import type { Report, ReportState, UIEvent, UINode } from './types'
import { applyUIEvent, createEmptyReportState } from './apply-event'

Expand Down Expand Up @@ -42,7 +42,6 @@ export function usePersistedReports() {
const [reports, setReports] = useState<Map<string, ReportState>>(new Map())
const [activeReportId, setActiveReportId] = useState<string | null>(null)
const [isHydrated, setIsHydrated] = useState(false)
const saveRef = useRef<ReturnType<typeof debounce<() => void>> | null>(null)

// Load from localStorage on mount
useEffect(() => {
Expand Down Expand Up @@ -74,29 +73,27 @@ export function usePersistedReports() {
useEffect(() => {
if (!isHydrated) return

if (!saveRef.current) {
saveRef.current = debounce(() => {
const data: ReportsStorage = {
reports: Array.from(reports.values()).map(
({ report, nodes, rootIds }) => ({
report,
nodes: Array.from(nodes.entries()),
rootIds,
}),
),
activeReportId,
version: STORAGE_VERSION,
}
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(data))
} catch (e) {
console.error('Failed to save reports to storage:', e)
}
}, 500)
}
const save = debounce(() => {
const data: ReportsStorage = {
reports: Array.from(reports.values()).map(
({ report, nodes, rootIds }) => ({
report,
nodes: Array.from(nodes.entries()),
rootIds,
}),
),
activeReportId,
version: STORAGE_VERSION,
}
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(data))
} catch (e) {
console.error('Failed to save reports to storage:', e)
}
}, 500)

saveRef.current()
return () => saveRef.current?.cancel()
save()
return () => save.cancel()
}, [reports, activeReportId, isHydrated])

// Create a new report
Expand Down