mirror of
https://github.com/langgenius/dify.git
synced 2026-02-19 07:01:42 -05:00
Split SkillSaveContext and useSkillSaveManager into a separate file to fix react-refresh/only-export-components lint error. Destructure mutateAsync from useUpdateAppAssetFileContent for a stable callback reference, preventing unnecessary useCallback cascade rebuilds. Extract shared patchFileContentCache helper to unify setQueryData logic between updateCachedContent and the collaboration event handler.
28 lines
529 B
TypeScript
28 lines
529 B
TypeScript
import { useEventListener, useUnmount } from 'ahooks'
|
|
import { useSkillSaveManager } from './skill-save-context'
|
|
|
|
export function useSkillAutoSave(): void {
|
|
const { saveAllDirty } = useSkillSaveManager()
|
|
|
|
useUnmount(() => {
|
|
saveAllDirty()
|
|
})
|
|
|
|
useEventListener(
|
|
'visibilitychange',
|
|
() => {
|
|
if (document.visibilityState === 'hidden')
|
|
saveAllDirty()
|
|
},
|
|
{ target: document },
|
|
)
|
|
|
|
useEventListener(
|
|
'beforeunload',
|
|
() => {
|
|
saveAllDirty()
|
|
},
|
|
{ target: window },
|
|
)
|
|
}
|