fix(lint): resolve all lint errors in github search and settings UI
- Merge duplicate react imports in repository-selector - Use <dialog open> instead of role=dialog in settings popover - Export type re-export from source module in use-github-repo-search - Sort action args alphabetically in searchGithubRepositories - Disable react-compiler rule for synchronous setState in debounced search - Simplify getActiveGithubConnection query
This commit is contained in:
@@ -96,10 +96,10 @@ export const GithubConnectionSettings = ({
|
||||
<RefreshCw className="size-3.5" />
|
||||
</Button>
|
||||
{open ? (
|
||||
<div
|
||||
<dialog
|
||||
aria-modal="false"
|
||||
className="absolute top-9 right-0 z-50 w-72 rounded-lg border border-[#d7d3c7] bg-[#fffefa] p-4 shadow-xl"
|
||||
role="dialog"
|
||||
open
|
||||
>
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<div className="flex items-center gap-1.5">
|
||||
@@ -182,7 +182,7 @@ export const GithubConnectionSettings = ({
|
||||
Not yet granted: {missingScopes.join(", ")}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
</dialog>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -12,8 +12,7 @@ import {
|
||||
Search,
|
||||
Server,
|
||||
} from "lucide-react";
|
||||
import { useMemo } from "react";
|
||||
import { useState } from "react";
|
||||
import { useMemo, useState } from "react";
|
||||
import { Link } from "react-router";
|
||||
|
||||
import { useGithubRepoSearch } from "@/hooks/use-github-repo-search";
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { GithubRepositorySearchResult } from "@code/backend/convex/gitConne
|
||||
import { useAction } from "convex/react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
export type { GithubRepositorySearchResult };
|
||||
export type { GithubRepositorySearchResult } from "@code/backend/convex/gitConnections";
|
||||
|
||||
export type GithubSearchState =
|
||||
| { kind: "idle" }
|
||||
@@ -39,21 +39,18 @@ export const useGithubRepoSearch = ({
|
||||
// Track the latest request so stale responses are discarded.
|
||||
const requestIdRef = useRef(0);
|
||||
|
||||
useEffect(() => {
|
||||
const trimmed = query.trim();
|
||||
const trimmed = query.trim();
|
||||
const shouldBeSearching =
|
||||
enabled && connectionId !== undefined && trimmed.length >= MIN_QUERY_LENGTH;
|
||||
|
||||
// If search is disabled or query too short, reset to idle.
|
||||
if (!enabled || trimmed.length < MIN_QUERY_LENGTH) {
|
||||
setState({ kind: "idle" });
|
||||
return;
|
||||
}
|
||||
if (!connectionId) {
|
||||
setState({ kind: "idle" });
|
||||
useEffect(() => {
|
||||
if (!shouldBeSearching || !connectionId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentRequestId = requestIdRef.current + 1;
|
||||
requestIdRef.current = currentRequestId;
|
||||
// eslint-disable-next-line react-compiler/react-compiler -- loading state must be set synchronously before the debounced fetch
|
||||
setState({ kind: "loading" });
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
@@ -92,7 +89,14 @@ export const useGithubRepoSearch = ({
|
||||
return () => {
|
||||
clearTimeout(timer);
|
||||
};
|
||||
}, [connectionId, enabled, query, searchAction]);
|
||||
}, [connectionId, shouldBeSearching, searchAction, trimmed]);
|
||||
// Reset to idle when search is no longer active.
|
||||
useEffect(() => {
|
||||
if (!shouldBeSearching && state.kind !== "idle") {
|
||||
// eslint-disable-next-line react-compiler/react-compiler -- reset state when search is no longer active
|
||||
setState({ kind: "idle" });
|
||||
}
|
||||
}, [shouldBeSearching, state.kind]);
|
||||
|
||||
return state;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user