mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: bug fix
This commit is contained in:
1 parent
03a6e79946
commit
fcd81fbcc9
2 files changed
+25
-6
No files matched your search
+24
-5
@@ -6,17 +6,31 @@ import PropTypes from 'prop-types';
|
|||||||
import api, { gql } from 'vj/utils/api';
|
import api, { gql } from 'vj/utils/api';
|
||||||
import AutoComplete from './AutoComplete';
|
import AutoComplete from './AutoComplete';
|
||||||
|
|
||||||
|
interface UserSelectAutoCompleteProps {
|
||||||
|
multi?: boolean;
|
||||||
|
defaultItems?: string;
|
||||||
|
width: string,
|
||||||
|
height: string,
|
||||||
|
listStyle: any,
|
||||||
|
onChange: (value) => any,
|
||||||
|
allowEmptyQuery: boolean,
|
||||||
|
freeSolo: boolean,
|
||||||
|
freeSoloConverter: any,
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line prefer-arrow-callback
|
// eslint-disable-next-line prefer-arrow-callback
|
||||||
const UserSelectAutoComplete = forwardRef(function UserSelectAutoComplete(props, ref) {
|
const UserSelectAutoComplete = forwardRef(function UserSelectAutoComplete(
|
||||||
|
props: UserSelectAutoCompleteProps, ref: React.Ref<AutoComplete>,
|
||||||
|
) {
|
||||||
const multi = props.multi ?? false;
|
const multi = props.multi ?? false;
|
||||||
const rawDefaultItems = props.defaultItems ?? '';
|
const rawDefaultItems = props.defaultItems ?? '';
|
||||||
const defaultItems = multi ? rawDefaultItems
|
const defaultItems = multi ? rawDefaultItems
|
||||||
.split(',')
|
.split(',')
|
||||||
.map((i) => i.trim())
|
.map((i) => i.trim())
|
||||||
.filter((i) => i.length > 0)
|
.filter((i) => i.length)
|
||||||
.map((i) => +i) : rawDefaultItems;
|
.map((i) => +i) : rawDefaultItems;
|
||||||
|
|
||||||
const comRef = createRef();
|
const comRef = createRef<AutoComplete>();
|
||||||
const itemsBox = useRef([]);
|
const itemsBox = useRef([]);
|
||||||
const { isLoading } = useQuery(['default_user', defaultItems], async () => {
|
const { isLoading } = useQuery(['default_user', defaultItems], async () => {
|
||||||
if (!multi || defaultItems.length === 0) return;
|
if (!multi || defaultItems.length === 0) return;
|
||||||
@@ -35,8 +49,13 @@ const UserSelectAutoComplete = forwardRef(function UserSelectAutoComplete(props,
|
|||||||
}
|
}
|
||||||
}, [itemsBox.current]);
|
}, [itemsBox.current]);
|
||||||
|
|
||||||
useImperativeHandle(ref, () => ({
|
useImperativeHandle(ref, () => new Proxy(comRef, {
|
||||||
...comRef.current,
|
get(target, propKey) {
|
||||||
|
if (typeof target.current?.[propKey] === 'function') {
|
||||||
|
return (...args: any[]) => target.current[propKey](...args);
|
||||||
|
}
|
||||||
|
return target.current?.[propKey];
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const itemsFn = (query) => api(gql`
|
const itemsFn = (query) => api(gql`
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/ui-default",
|
"name": "@hydrooj/ui-default",
|
||||||
"version": "4.29.3",
|
"version": "4.29.4",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"main": "hydro.js",
|
"main": "hydro.js",
|
||||||
|
|||||||
Reference in new issue
Block a user