mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 21:06:04 +00:00
fix: media infinite should be disabled for dropzone in entities
This commit is contained in:
1
app/.gitignore
vendored
1
app/.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
playwright-report
|
playwright-report
|
||||||
test-results
|
test-results
|
||||||
bknd.config.*
|
bknd.config.*
|
||||||
|
app/__test__/helper.d.ts
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { App } from "App";
|
import type { App } from "App";
|
||||||
import { type Context, Hono } from "hono";
|
import { type Context, Hono } from "hono";
|
||||||
import * as middlewares from "modules/middlewares";
|
import * as middlewares from "modules/middlewares";
|
||||||
|
import type { SafeUser } from "auth";
|
||||||
|
|
||||||
export type ServerEnv = {
|
export type ServerEnv = {
|
||||||
Variables: {
|
Variables: {
|
||||||
@@ -10,7 +11,7 @@ export type ServerEnv = {
|
|||||||
resolved: boolean;
|
resolved: boolean;
|
||||||
registered: boolean;
|
registered: boolean;
|
||||||
skip: boolean;
|
skip: boolean;
|
||||||
user?: { id: any; role?: string; [key: string]: any };
|
user?: SafeUser;
|
||||||
};
|
};
|
||||||
html?: string;
|
html?: string;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { useApi, useApiInfiniteQuery, useInvalidate } from "ui/client";
|
import { useApi, useApiInfiniteQuery, useApiQuery, useInvalidate } from "ui/client";
|
||||||
import { useEvent } from "ui/hooks/use-event";
|
import { useEvent } from "ui/hooks/use-event";
|
||||||
import { Dropzone, type DropzoneProps, type DropzoneRenderProps, type FileState } from "./Dropzone";
|
import { Dropzone, type DropzoneProps, type DropzoneRenderProps, type FileState } from "./Dropzone";
|
||||||
import { mediaItemsToFileStates } from "./helper";
|
import { mediaItemsToFileStates } from "./helper";
|
||||||
@@ -20,6 +20,7 @@ import { useInViewport } from "@mantine/hooks";
|
|||||||
export type DropzoneContainerProps = {
|
export type DropzoneContainerProps = {
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
initialItems?: MediaFieldSchema[] | false;
|
initialItems?: MediaFieldSchema[] | false;
|
||||||
|
infinite?: boolean;
|
||||||
entity?: {
|
entity?: {
|
||||||
name: string;
|
name: string;
|
||||||
id: number;
|
id: number;
|
||||||
@@ -39,6 +40,7 @@ export function DropzoneContainer({
|
|||||||
query,
|
query,
|
||||||
children,
|
children,
|
||||||
randomFilename,
|
randomFilename,
|
||||||
|
infinite = false,
|
||||||
...props
|
...props
|
||||||
}: DropzoneContainerProps) {
|
}: DropzoneContainerProps) {
|
||||||
const id = useId();
|
const id = useId();
|
||||||
@@ -54,7 +56,7 @@ export function DropzoneContainer({
|
|||||||
const entity_name = (media?.entity_name ?? "media") as "media";
|
const entity_name = (media?.entity_name ?? "media") as "media";
|
||||||
//console.log("dropzone:baseUrl", baseUrl);
|
//console.log("dropzone:baseUrl", baseUrl);
|
||||||
|
|
||||||
const selectApi = (api: Api, page: number) =>
|
const selectApi = (api: Api, page: number = 0) =>
|
||||||
entity
|
entity
|
||||||
? api.data.readManyByReference(entity.name, entity.id, entity.field, {
|
? api.data.readManyByReference(entity.name, entity.id, entity.field, {
|
||||||
...query,
|
...query,
|
||||||
@@ -70,7 +72,11 @@ export function DropzoneContainer({
|
|||||||
...defaultQuery(page),
|
...defaultQuery(page),
|
||||||
});
|
});
|
||||||
|
|
||||||
const $q = useApiInfiniteQuery(selectApi, {});
|
const $q = infinite
|
||||||
|
? useApiInfiniteQuery(selectApi, {})
|
||||||
|
: useApiQuery(selectApi, {
|
||||||
|
enabled: initialItems !== false && !initialItems,
|
||||||
|
});
|
||||||
|
|
||||||
const getUploadInfo = useEvent((file) => {
|
const getUploadInfo = useEvent((file) => {
|
||||||
const url = entity
|
const url = entity
|
||||||
@@ -108,11 +114,17 @@ export function DropzoneContainer({
|
|||||||
autoUpload
|
autoUpload
|
||||||
initialItems={_initialItems}
|
initialItems={_initialItems}
|
||||||
footer={
|
footer={
|
||||||
|
infinite &&
|
||||||
|
"setSize" in $q && (
|
||||||
<Footer
|
<Footer
|
||||||
items={_initialItems.length}
|
items={_initialItems.length}
|
||||||
length={$q._data?.[0]?.body.meta.count ?? 0}
|
length={Math.min(
|
||||||
|
$q._data?.[0]?.body.meta.count ?? 0,
|
||||||
|
_initialItems.length + pageSize,
|
||||||
|
)}
|
||||||
onFirstVisible={() => $q.setSize($q.size + 1)}
|
onFirstVisible={() => $q.setSize($q.size + 1)}
|
||||||
/>
|
/>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
@@ -142,14 +154,14 @@ const Footer = ({ items = 0, length = 0, onFirstVisible }) => {
|
|||||||
const _len = length - items;
|
const _len = length - items;
|
||||||
if (_len <= 0) return null;
|
if (_len <= 0) return null;
|
||||||
|
|
||||||
return new Array(Math.max(length - items, 0)).fill(0).map((_, i) => (
|
return new Array(Math.max(length - items, 0))
|
||||||
|
.fill(0)
|
||||||
|
.map((_, i) => (
|
||||||
<div
|
<div
|
||||||
key={i}
|
key={i}
|
||||||
ref={i === 0 ? ref : undefined}
|
ref={i === 0 ? ref : undefined}
|
||||||
className="w-[49%] md:w-60 bg-muted aspect-square"
|
className="w-[49%] md:w-60 bg-muted aspect-square"
|
||||||
>
|
/>
|
||||||
{i === 0 ? (inViewport ? `load ${visible}` : "first") : "other"}
|
|
||||||
</div>
|
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export function MediaIndex() {
|
|||||||
return (
|
return (
|
||||||
<AppShell.Scrollable>
|
<AppShell.Scrollable>
|
||||||
<div className="flex flex-1 p-3">
|
<div className="flex flex-1 p-3">
|
||||||
<Media.Dropzone onClick={onClick} />
|
<Media.Dropzone onClick={onClick} infinite />
|
||||||
</div>
|
</div>
|
||||||
</AppShell.Scrollable>
|
</AppShell.Scrollable>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -66,7 +66,9 @@ export default {
|
|||||||
},
|
},
|
||||||
"sync",
|
"sync",
|
||||||
);
|
);
|
||||||
await app.build();
|
await app.build({
|
||||||
|
sync: !!(firstStart && example),
|
||||||
|
});
|
||||||
|
|
||||||
// log routes
|
// log routes
|
||||||
if (firstStart) {
|
if (firstStart) {
|
||||||
|
|||||||
Reference in New Issue
Block a user