mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
replaced all react-query usages with new hooks + removed react-query
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
||||
} from "data";
|
||||
import { MediaField } from "media/MediaField";
|
||||
import { type ComponentProps, Suspense } from "react";
|
||||
import { useClient } from "ui/client";
|
||||
import { useApi, useBaseUrl, useInvalidate } from "ui/client";
|
||||
import { JsonEditor } from "ui/components/code/JsonEditor";
|
||||
import * as Formy from "ui/components/form/Formy";
|
||||
import { FieldLabel } from "ui/components/form/Formy";
|
||||
@@ -215,7 +215,9 @@ function EntityMediaFormField({
|
||||
}) {
|
||||
if (!entityId) return;
|
||||
|
||||
const client = useClient();
|
||||
const api = useApi();
|
||||
const baseUrl = useBaseUrl();
|
||||
const invalidate = useInvalidate();
|
||||
const value = formApi.useStore((state) => {
|
||||
const val = state.values[field.name];
|
||||
if (!val || typeof val === "undefined") return [];
|
||||
@@ -227,22 +229,21 @@ function EntityMediaFormField({
|
||||
value.length === 0
|
||||
? []
|
||||
: mediaItemsToFileStates(value, {
|
||||
baseUrl: client.baseUrl,
|
||||
baseUrl: api.baseUrl,
|
||||
overrides: { state: "uploaded" }
|
||||
});
|
||||
|
||||
const getUploadInfo = useEvent(() => {
|
||||
const api = client.media().api();
|
||||
return {
|
||||
url: api.getEntityUploadUrl(entity.name, entityId, field.name),
|
||||
headers: api.getUploadHeaders(),
|
||||
url: api.media.getEntityUploadUrl(entity.name, entityId, field.name),
|
||||
headers: api.media.getUploadHeaders(),
|
||||
method: "POST"
|
||||
};
|
||||
});
|
||||
|
||||
const handleDelete = useEvent(async (file) => {
|
||||
client.__invalidate(entity.name, entityId);
|
||||
return await client.media().deleteFile(file);
|
||||
const handleDelete = useEvent(async (file: FileState) => {
|
||||
invalidate((api) => api.data.readOne(entity.name, entityId));
|
||||
return api.media.deleteFile(file.path);
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -4,12 +4,11 @@ import { ucFirst } from "core/utils";
|
||||
import type { EntityData, RelationField } from "data";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { TbEye } from "react-icons/tb";
|
||||
import { useClient, useEntityQuery } from "ui/client";
|
||||
import { useEntityQuery } from "ui/client";
|
||||
import { useBknd } from "ui/client/bknd";
|
||||
import { Button } from "ui/components/buttons/Button";
|
||||
import * as Formy from "ui/components/form/Formy";
|
||||
import { Popover } from "ui/components/overlay/Popover";
|
||||
import { useEntities } from "ui/container";
|
||||
import { routes } from "ui/lib/routes";
|
||||
import { useLocation } from "wouter";
|
||||
import { EntityTable } from "../EntityTable";
|
||||
@@ -33,7 +32,6 @@ export function EntityRelationalFormField({
|
||||
const [query, setQuery] = useState<any>({ limit: 10, page: 1, perPage: 10 });
|
||||
const [, navigate] = useLocation();
|
||||
const ref = useRef<any>(null);
|
||||
const client = useClient();
|
||||
const $q = useEntityQuery(field.target(), undefined, {
|
||||
limit: query.limit,
|
||||
offset: (query.page - 1) * query.limit
|
||||
@@ -53,7 +51,7 @@ export function EntityRelationalFormField({
|
||||
const rel_value = field.target();
|
||||
if (!rel_value || !relationalField) return;
|
||||
|
||||
const fetched = await client.api.data.readOne(field.target(), relationalField);
|
||||
const fetched = await $q.api.readOne(field.target(), relationalField);
|
||||
if (fetched.ok && fetched.data) {
|
||||
_setValue(fetched.data as any);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user