Feature/move list to client (#50)

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-09-01 15:02:12 +02:00
committed by GitHub
parent c2abdaadf2
commit 668434d246
181 changed files with 2922 additions and 1959 deletions

View File

@@ -1,6 +1,8 @@
import { useTransition } from 'react';
import { parseAsInteger, useQueryState } from 'nuqs';
import { useDebounceValue } from './useDebounceValue';
export function useCursor() {
const [loading, startTransition] = useTransition();
const [cursor, setCursor] = useQueryState(
@@ -15,3 +17,18 @@ export function useCursor() {
loading,
};
}
export type UseDebouncedCursor = ReturnType<typeof useDebouncedCursor>;
export function useDebouncedCursor() {
const [cursor, setCursor] = useQueryState(
'cursor',
parseAsInteger.withDefault(0)
);
const debouncedCursor = useDebounceValue(cursor, 200);
return {
value: cursor,
set: setCursor,
debounced: debouncedCursor,
};
}

View File

@@ -7,7 +7,7 @@ interface DebouncedState<T> {
set: React.Dispatch<React.SetStateAction<T>>;
}
export function useDebounceVal<T>(
export function useDebounceState<T>(
initialValue: T,
delay = 500,
options?: Parameters<typeof debounce>[2]

View File

@@ -0,0 +1,10 @@
import { useEffect, useState } from 'react';
export const useDebounceValue = <T>(value: T, delay: number): T => {
const [state, setState] = useState(value);
useEffect(() => {
const handler = setTimeout(() => setState(value), delay);
return () => clearTimeout(handler);
}, [value, delay]);
return state;
};

View File

@@ -14,7 +14,7 @@ export const formatNumber =
return 'N/A';
}
return new Intl.NumberFormat(locale, {
maximumSignificantDigits: 20,
maximumSignificantDigits: 3,
}).format(value);
};