Skip to content

Commit

Permalink
feat: skeleton loader for query page
Browse files Browse the repository at this point in the history
  • Loading branch information
frectonz committed Jun 15, 2024
1 parent be20a48 commit 645be07
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions ui/src/routes/query.lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createLazyRoute } from "@tanstack/react-router";

import { fetchQuery } from "@/api";
import { Editor } from "@/components/editor";
import { Skeleton } from "@/components/ui/skeleton";

export const Route = createLazyRoute("/query")({
component: Query,
Expand All @@ -20,14 +21,15 @@ function Query() {
queryFn: () => fetchQuery(code),
});

const columns = data?.columns.map((col) => ({ key: col, name: col })) ?? [];
const rows =
data?.rows.map((row) =>
row.reduce((acc, curr, i) => {
acc[data.columns[i]] = curr;
return acc;
}, {}),
) ?? [];
if (!data) return <QuerySkeleton />;

const columns = data.columns.map((col) => ({ key: col, name: col }));
const rows = data.rows.map((row) =>
row.reduce((acc, curr, i) => {
acc[data.columns[i]] = curr;
return acc;
}, {}),
);

return (
<>
Expand All @@ -39,3 +41,12 @@ function Query() {
</>
);
}

function QuerySkeleton() {
return (
<>
<Skeleton className="w-full h-[200px]" />
<Skeleton className="w-full h-[300px]" />
</>
);
}

0 comments on commit 645be07

Please sign in to comment.