This commit is contained in:
Hein 2025-09-22 17:03:11 +02:00
parent ea6b100225
commit 04c516f702
2 changed files with 44 additions and 2 deletions

View File

@ -0,0 +1,42 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import React, { useEffect } from 'react';
import type { APIOptions } from '../utils/types';
import { useGridlerStore } from './Store';
interface LocalDataAdaptorProps extends APIOptions {
data: Array<unknown>;
}
//The computer component does not need to be recalculated on every render, so we use React.memo to prevent unnecessary re-renders.
export const LocalDataAdaptor = React.memo((props: LocalDataAdaptorProps) => {
const [setStateFN, setState, getState, addError, mounted] = useGridlerStore((s) => [
s.setStateFN,
s.setState,
s.getState,
s.addError,
s.mounted
]);
const useAPIQuery: (index: number) => Promise<any> = async (index: number) => {
const colSort = getState('colSort');
const pageSize = getState('pageSize');
const colFilters = getState('colFilters');
const _active_requests = getState('_active_requests');
if (!(props.data && Array.isArray(props.data))) {
return [];
}
setState('total_rows', props.data.length);
return props.data.slice(index * (pageSize ?? 50), (index + 1) * (pageSize ?? 50));
};
useEffect(() => {
setState('useAPIQuery', useAPIQuery);
}, [props.url, props.authtoken, mounted, setState]);
return <></>;
});

View File

@ -36,7 +36,7 @@ export const useGridTheme = () => {
const gridThemeDark = {
accentColor: 'none',
accentLight: '#2824ab3c',
accentLight: theme.colors.blue[9],
baseFontStyle: '13px',
@ -58,7 +58,7 @@ export const useGridTheme = () => {
'Inter, Roboto, -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Ubuntu, noto, arial, sans-serif',
headerFontStyle: '500 13px',
linkColor: '#4F5DFF',
linkColor: theme.colors.blue[4],
textBubble: '#ffffff',