Skip to content

Commit

Permalink
fixing sonarqube issue
Browse files Browse the repository at this point in the history
  • Loading branch information
invisal committed Feb 9, 2024
1 parent d3e0eb2 commit 66c180e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/app/(components)/SchemaView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function SchemaViewmItem({
}

export default function SchemaView() {
const { refresh, schema, loading } = useSchema();
const { refresh, schema } = useSchema();
const [selectedIndex, setSelectedIndex] = useState(-1);

const prepareContextMenu = useCallback(
Expand All @@ -82,7 +82,6 @@ export default function SchemaView() {
className="h-full select-none"
onContextMenu={openContextMenuFromEvent(prepareContextMenu())}
>
{loading && <OpacityLoading />}
<div className="flex flex-col p-2 pr-4">
{schema.map((item, schemaIndex) => {
return (
Expand Down
6 changes: 5 additions & 1 deletion src/components/custom/ErrorMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export default function ErrorMessage({ message }: { message: string }) {
export default function ErrorMessage({
message,
}: {
readonly message: string;
}) {
return <div className="text-xs text-red-500">{message}</div>;
}
4 changes: 2 additions & 2 deletions src/screens/DatabaseScreen/ConnectingDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ export default function ConnectingDialog({
message,
url,
onRetry,
}: {
}: Readonly<{
loading?: boolean;
url?: string;
message?: string;
onRetry?: () => void;
}) {
}>) {
const router = useRouter();

let body = (
Expand Down
17 changes: 7 additions & 10 deletions src/screens/DatabaseScreen/SchemaProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ import {
useCallback,
useContext,
useEffect,
useMemo,
useState,
} from "react";
import ConnectingDialog from "./ConnectingDialog";

const SchemaContext = createContext<{
schema: DatabaseSchemaItem[];
refresh: () => void;
loading: boolean;
}>({
schema: [],
loading: false,
refresh: () => {
throw new Error("Not implemented");
},
Expand All @@ -27,7 +26,7 @@ export function useSchema() {
return useContext(SchemaContext);
}

export function SchemaProvider({ children }: PropsWithChildren) {
export function SchemaProvider({ children }: Readonly<PropsWithChildren>) {
const { updateTableList } = useAutoComplete();
const [error, setError] = useState<string>();
const [schemaItems, setSchemaItems] = useState<DatabaseSchemaItem[]>([]);
Expand All @@ -36,8 +35,6 @@ export function SchemaProvider({ children }: PropsWithChildren) {

const fetchSchema = useCallback(
(refresh?: boolean) => {
console.log("refresh", refresh);

if (refresh) {
setLoading(true);
}
Expand Down Expand Up @@ -68,6 +65,10 @@ export function SchemaProvider({ children }: PropsWithChildren) {
fetchSchema(true);
}, [fetchSchema]);

const props = useMemo(() => {
return { schema: schemaItems, refresh: fetchSchema };
}, [schemaItems, fetchSchema]);

if (error || loading) {
return (
<ConnectingDialog
Expand All @@ -79,10 +80,6 @@ export function SchemaProvider({ children }: PropsWithChildren) {
}

return (
<SchemaContext.Provider
value={{ schema: schemaItems, refresh: fetchSchema, loading }}
>
{children}
</SchemaContext.Provider>
<SchemaContext.Provider value={props}>{children}</SchemaContext.Provider>
);
}

0 comments on commit 66c180e

Please sign in to comment.