ui: fix dnd

This commit is contained in:
undefined committed 2022-04-06 14:14:03 +08:00
1 parent 406e45975f
commit ce5a16914c
5 files changed
+9 -9

No files matched your search

@@ -11,7 +11,7 @@ const Component = React.forwardRef<any, any>((props, ref) => {
<ProblemSelectAutoCompleteFC <ProblemSelectAutoCompleteFC
ref={ref as any} ref={ref as any}
height="34px" height="34px"
selectedKeys={value.split(',').map((i) => i.trim())} selectedKeys={value.split(',').map((i) => i.trim()).filter((i) => i)}
onChange={(v) => { onChange={(v) => {
setValue(v); setValue(v);
props.onChange(v); props.onChange(v);
@@ -11,7 +11,7 @@ const Component = React.forwardRef<any, any>((props, ref) => {
<UserSelectAutoCompleteFC <UserSelectAutoCompleteFC
ref={ref as any} ref={ref as any}
height="34px" height="34px"
selectedKeys={value.split(',').map((i) => i.trim())} selectedKeys={value.split(',').map((i) => i.trim()).filter((i) => i)}
onChange={(v) => { onChange={(v) => {
setValue(v); setValue(v);
props.onChange(v); props.onChange(v);
@@ -58,16 +58,16 @@ function DraggableSelection({
type, id, move, children, ...props type, id, move, children, ...props
}) { }) {
const ref = useRef<HTMLDivElement>(null); const ref = useRef<HTMLDivElement>(null);
const [isDragging, drag] = useDrag<string, any, boolean>(() => ({ const [isDragging, drag] = useDrag<{ id: string }, any, boolean>(() => ({
type, type,
item: id, item: { id },
collect: (m) => m.isDragging(), collect: (m) => m.isDragging(),
})); }));
const [, drop] = useDrop({ const [, drop] = useDrop({
accept: type, accept: type,
hover: (item: string) => { hover: (item: { id: string }) => {
if (!ref.current) return; if (!ref.current) return;
move(item, id); move(item.id, id);
}, },
}); });
drag(drop(ref)); drag(drop(ref));
@@ -10,8 +10,8 @@ const ProblemSelectAutoComplete = forwardRef<AutoCompleteHandle<ProblemDoc>, Aut
cacheKey={`problem-${UiContext.domainId}`} cacheKey={`problem-${UiContext.domainId}`}
queryItems={(query) => request.get(`/d/${UiContext.domainId}/problem/list`, { prefix: query })} queryItems={(query) => request.get(`/d/${UiContext.domainId}/problem/list`, { prefix: query })}
// FIXME fetch items // FIXME fetch items
fetchItems={() => []} fetchItems={(ids) => ids.map((id) => ({ docId: id, pid: id, title: id }) as any)}
itemText={(pdoc) => `${pdoc.docId || pdoc}`} itemText={(pdoc) => `${`${pdoc.docId} ${pdoc.title}`}`}
itemKey={(pdoc) => `${pdoc.docId || pdoc}`} itemKey={(pdoc) => `${pdoc.docId || pdoc}`}
renderItem={(pdoc) => ( renderItem={(pdoc) => (
<div className="media"> <div className="media">
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/ui-default", "name": "@hydrooj/ui-default",
"version": "4.34.36", "version": "4.34.37",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"main": "hydro.js", "main": "hydro.js",