mirror of
https://github.com/langgenius/dify.git
synced 2026-05-02 23:28:51 +08:00
fix: clear uploaded files when clicking clear button in workflow (#29884)
This commit is contained in:
parent
6cf71366ba
commit
f8ccc75cde
@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
createContext,
|
createContext,
|
||||||
useContext,
|
useContext,
|
||||||
|
useEffect,
|
||||||
useRef,
|
useRef,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
import {
|
import {
|
||||||
@ -10,6 +11,7 @@ import {
|
|||||||
import type {
|
import type {
|
||||||
FileEntity,
|
FileEntity,
|
||||||
} from './types'
|
} from './types'
|
||||||
|
import { isEqual } from 'lodash-es'
|
||||||
|
|
||||||
type Shape = {
|
type Shape = {
|
||||||
files: FileEntity[]
|
files: FileEntity[]
|
||||||
@ -55,10 +57,20 @@ export const FileContextProvider = ({
|
|||||||
onChange,
|
onChange,
|
||||||
}: FileProviderProps) => {
|
}: FileProviderProps) => {
|
||||||
const storeRef = useRef<FileStore | undefined>(undefined)
|
const storeRef = useRef<FileStore | undefined>(undefined)
|
||||||
|
|
||||||
if (!storeRef.current)
|
if (!storeRef.current)
|
||||||
storeRef.current = createFileStore(value, onChange)
|
storeRef.current = createFileStore(value, onChange)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!storeRef.current)
|
||||||
|
return
|
||||||
|
if (isEqual(value, storeRef.current.getState().files))
|
||||||
|
return
|
||||||
|
|
||||||
|
storeRef.current.setState({
|
||||||
|
files: value ? [...value] : [],
|
||||||
|
})
|
||||||
|
}, [value])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FileContext.Provider value={storeRef.current}>
|
<FileContext.Provider value={storeRef.current}>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user