This commit is contained in:
Archer
2023-10-22 23:54:04 +08:00
committed by GitHub
parent 3091a90df6
commit a3534407bf
365 changed files with 7266 additions and 6055 deletions

View File

@@ -0,0 +1,16 @@
import { useState } from 'react';
export const useDrag = () => {
const [moveDataId, setMoveDataId] = useState<string>();
const [dragStartId, setDragStartId] = useState<string>();
const [dragTargetId, setDragTargetId] = useState<string>();
return {
moveDataId,
setMoveDataId,
dragStartId,
setDragStartId,
dragTargetId,
setDragTargetId
};
};

View File

@@ -1,12 +1,14 @@
import React, { useCallback, useRef } from 'react';
import { ModalFooter, ModalBody, Input, useDisclosure, Button } from '@chakra-ui/react';
import { ModalFooter, ModalBody, Input, useDisclosure, Button, Box } from '@chakra-ui/react';
import MyModal from '@/components/MyModal';
export const useEditTitle = ({
title,
tip,
placeholder = ''
}: {
title: string;
tip?: string;
placeholder?: string;
}) => {
const { isOpen, onOpen, onClose } = useDisclosure();
@@ -51,6 +53,12 @@ export const useEditTitle = ({
() => (
<MyModal isOpen={isOpen} onClose={onClose} title={title}>
<ModalBody>
{!!tip && (
<Box mb={2} color={'myGray.500'} fontSize={'sm'}>
{tip}
</Box>
)}
<Input
ref={inputRef}
defaultValue={defaultValue.current}
@@ -67,7 +75,7 @@ export const useEditTitle = ({
</ModalFooter>
</MyModal>
),
[isOpen, onClose, onclickConfirm, placeholder, title]
[isOpen, onClose, onclickConfirm, placeholder, tip, title]
);
return {

View File

@@ -1,7 +1,7 @@
import { useToast } from '@/web/common/hooks/useToast';
import { useMutation } from '@tanstack/react-query';
import type { UseMutationOptions } from '@tanstack/react-query';
import { getErrText } from '@/utils/tools';
import { getErrText } from '@fastgpt/global/common/error/utils';
import { useTranslation } from 'react-i18next';
interface Props extends UseMutationOptions<any, any, any, any> {

View File

@@ -1,44 +0,0 @@
import React, { useRef, useCallback } from 'react';
import { Box } from '@chakra-ui/react';
import { useToast } from './useToast';
import { useTranslation } from 'react-i18next';
export const useSelectFile = (props?: { fileType?: string; multiple?: boolean }) => {
const { t } = useTranslation();
const { fileType = '*', multiple = false } = props || {};
const { toast } = useToast();
const SelectFileDom = useRef<HTMLInputElement>(null);
const File = useCallback(
({ onSelect }: { onSelect: (e: File[]) => void }) => (
<Box position={'absolute'} w={0} h={0} overflow={'hidden'}>
<input
ref={SelectFileDom}
type="file"
accept={fileType}
multiple={multiple}
onChange={(e) => {
if (!e.target.files || e.target.files?.length === 0) return;
if (e.target.files.length > 10) {
return toast({
status: 'warning',
title: t('file.Select a maximum of 10 files')
});
}
onSelect(Array.from(e.target.files));
}}
/>
</Box>
),
[fileType, multiple, t, toast]
);
const onOpen = useCallback(() => {
SelectFileDom.current && SelectFileDom.current.click();
}, []);
return {
File,
onOpen
};
};