pl-fe: wow it compiles

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2024-10-16 17:41:29 +02:00
parent e30d2d8033
commit cf39cf1c36
6 changed files with 8 additions and 10 deletions

View File

@ -147,7 +147,6 @@
"vite-plugin-require": "^1.2.14",
"vite-plugin-static-copy": "^1.0.6",
"wicg-inert": "^3.1.3",
"zod": "^3.23.8",
"zustand": "^5.0.0-rc.2"
},
"devDependencies": {

View File

@ -1,5 +1,5 @@
import { useEffect } from 'react';
import { z } from 'zod';
import * as v from 'valibot';
import { useAppDispatch } from 'pl-fe/hooks/useAppDispatch';
import { useAppSelector } from 'pl-fe/hooks/useAppSelector';
@ -29,7 +29,7 @@ const useBatchedEntities = <TEntity extends Entity>(
const getState = useGetState();
const dispatch = useAppDispatch();
const { entityType, listKey, path } = parseEntitiesPath(expandedPath);
const schema = opts.schema || z.custom<TEntity>();
const schema = opts.schema || v.custom<TEntity>(() => true);
const isEnabled = opts.enabled ?? true;
const isFetching = useListState(path, 'fetching');

View File

@ -1,4 +1,4 @@
import { z } from 'zod';
import * as v from 'valibot';
import { useAppDispatch } from 'pl-fe/hooks/useAppDispatch';
import { useLoading } from 'pl-fe/hooks/useLoading';
@ -31,7 +31,7 @@ const useCreateEntity = <TEntity extends Entity = Entity, TTransformedEntity ext
callbacks: EntityCallbacks<TTransformedEntity, { response?: PlfeResponse }> = {},
): Promise<void> => {
const result = await setPromise(entityFn(data));
const schema = opts.schema || z.custom<TEntity>();
const schema = opts.schema || v.custom<TEntity>(() => true);
let entity: TEntity | TTransformedEntity = v.parse(schema, result);
if (opts.transform) entity = opts.transform(entity);

View File

@ -43,7 +43,7 @@ const useEntities = <TEntity extends Entity, TTransformedEntity extends Entity =
const { entityType, listKey, path } = parseEntitiesPath(expandedPath);
const entities = useAppSelector(state => selectEntities<TTransformedEntity>(state, path));
const schema = opts.schema || z.custom<TEntity>();
const schema = opts.schema || v.custom<TEntity>(() => true);
const isEnabled = opts.enabled ?? true;
const isFetching = useListState(path, 'fetching');

View File

@ -1,5 +1,5 @@
import { useEffect, useState } from 'react';
import z from 'zod';
import * as v from 'valibot';
import { useAppDispatch } from 'pl-fe/hooks/useAppDispatch';
import { useAppSelector } from 'pl-fe/hooks/useAppSelector';
@ -35,7 +35,7 @@ const useEntity = <TEntity extends Entity, TTransformedEntity extends Entity = T
const [entityType, entityId] = path;
const defaultSchema = z.custom<TEntity>();
const defaultSchema = v.custom<TEntity>(() => true);
const schema = opts.schema || defaultSchema;
const entity = useAppSelector(state => selectEntity<TTransformedEntity>(state, entityType, entityId));

View File

@ -1,6 +1,5 @@
import { useEffect, useState } from 'react';
import * as v from 'valibot';
import { z } from 'zod';
import { useAppDispatch } from 'pl-fe/hooks/useAppDispatch';
import { useAppSelector } from 'pl-fe/hooks/useAppSelector';
@ -23,7 +22,7 @@ const useEntityLookup = <TEntity extends Entity, TTransformedEntity extends Enti
entityFn: EntityFn<void>,
opts: UseEntityOpts<TEntity, TTransformedEntity> = {},
) => {
const { schema = z.custom<TEntity>() } = opts;
const { schema = v.custom<TEntity>(() => true) } = opts;
const dispatch = useAppDispatch();
const [fetchedEntity, setFetchedEntity] = useState<TTransformedEntity | undefined>();