fix entity list unnecessary parameters

This commit is contained in:
dswbx
2025-01-17 13:43:45 +01:00
parent a723d6f618
commit c19d3b2d75
5 changed files with 48 additions and 18 deletions

View File

@@ -10,9 +10,9 @@ export type IconType =
const styles = {
xs: { className: "p-0.5", size: 13 },
sm: { className: "p-0.5", size: 16 },
md: { className: "p-1", size: 20 },
lg: { className: "p-1.5", size: 24 }
sm: { className: "p-0.5", size: 15 },
md: { className: "p-1", size: 18 },
lg: { className: "p-1.5", size: 22 }
} as const;
interface IconButtonProps extends ComponentPropsWithoutRef<"button"> {

View File

@@ -0,0 +1,32 @@
import { useEffect, useRef } from "react";
export function useEffectOnce(effect: () => void | (() => void | undefined), deps: any[]): void {
const hasRunRef = useRef(false);
const savedDepsRef = useRef<any[] | undefined>(deps);
useEffect(() => {
const depsChanged = !hasRunRef.current || !areDepsEqual(savedDepsRef.current, deps);
if (depsChanged) {
hasRunRef.current = true;
savedDepsRef.current = deps;
return effect();
}
}, [deps]);
}
function areDepsEqual(prevDeps: any[] | undefined, nextDeps: any[]): boolean {
if (prevDeps && prevDeps.length === 0 && nextDeps.length === 0) {
return true;
}
if (!prevDeps && nextDeps.length === 0) {
return true;
}
if (!prevDeps || !nextDeps || prevDeps.length !== nextDeps.length) {
return false;
}
return prevDeps.every((dep, index) => Object.is(dep, nextDeps[index]));
}

View File

@@ -40,8 +40,8 @@ export function DataEntityList({ params }) {
useBrowserTitle(["Data", entity?.label ?? params.entity]);
const [navigate] = useNavigate();
const search = useSearch(searchSchema, {
select: entity?.getSelect(undefined, "table") ?? [],
sort: entity?.getDefaultSort()
select: undefined,
sort: undefined
});
const $q = useApiQuery(
@@ -50,7 +50,7 @@ export function DataEntityList({ params }) {
select: search.value.select,
limit: search.value.perPage,
offset: (search.value.page - 1) * search.value.perPage,
sort: search.value.sort
sort: `${search.value.sort.dir === "asc" ? "" : "-"}${search.value.sort.by}`
}),
{
enabled: !!entity,
@@ -131,7 +131,7 @@ export function DataEntityList({ params }) {
<EntityTable2
data={data ?? null}
entity={entity}
/*select={search.value.select}*/
select={search.value.select}
onClickRow={handleClickRow}
page={search.value.page}
sort={search.value.sort}

View File

@@ -1,17 +1,18 @@
import { IconHome } from "@tabler/icons-react";
import { useEffect } from "react";
import { useAuth } from "ui/client";
import { useEffectOnce } from "ui/hooks/use-effect";
import { Empty } from "../components/display/Empty";
import { useBrowserTitle } from "../hooks/use-browser-title";
import * as AppShell from "../layouts/AppShell/AppShell";
import { useNavigate } from "../lib/routes";
export const Root = ({ children }) => {
const { verify } = useAuth();
const { verify, user } = useAuth();
useEffect(() => {
useEffectOnce(() => {
verify();
}, []);
}, [user?.id]);
return (
<AppShell.Root>