Prevent logged calls table flashes

This commit is contained in:
David Corbitt
2023-08-15 02:49:46 -07:00
parent b22a4cd93b
commit 897e77b054
2 changed files with 14 additions and 12 deletions

View File

@@ -1,20 +1,11 @@
import { Card, Table, Tbody } from "@chakra-ui/react";
import { useState, useEffect } from "react";
import { useState } from "react";
import { useLoggedCalls } from "~/utils/hooks";
import { TableHeader, TableRow } from "./TableRow";
export default function LoggedCallsTable() {
const [expandedRow, setExpandedRow] = useState<string | null>(null);
const { data, isLoading } = useLoggedCalls();
const [loggedCalls, setLoggedCalls] = useState(data);
useEffect(() => {
// persist data while loading
if (!isLoading) {
setLoggedCalls(data);
}
}, [data, isLoading]);
const loggedCalls = useLoggedCalls().data;
return (
<Card width="100%" overflow="hidden">

View File

@@ -181,10 +181,21 @@ export const useLoggedCalls = () => {
const { page, pageSize } = usePageParams();
const filters = useAppStore((state) => state.logFilters.filters);
return api.loggedCalls.list.useQuery(
const { data, isLoading, ...rest } = api.loggedCalls.list.useQuery(
{ projectId: selectedProjectId ?? "", page, pageSize, filters },
{ enabled: !!selectedProjectId },
);
const [stableData, setStableData] = useState(data);
useEffect(() => {
// Prevent annoying flashes while logs are loading from the server
if (!isLoading) {
setStableData(data);
}
}, [data, isLoading]);
return { data: stableData, isLoading, ...rest };
};
export const useTagNames = () => {