初始化模版工程
This commit is contained in:
25
components/html-editor/hooks/useLoadContent.ts
Normal file
25
components/html-editor/hooks/useLoadContent.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useNovaKit } from '@/components/nova-sdk/context/useNovaKit';
|
||||
import type { TaskArtifact } from '@/components/nova-sdk/types';
|
||||
|
||||
export const useLoadContent = (
|
||||
taskArtifact: TaskArtifact
|
||||
) => {
|
||||
const [content, setContent] = useState('');
|
||||
const { api } = useNovaKit();
|
||||
useEffect(() => {
|
||||
if (taskArtifact.path) {
|
||||
api
|
||||
.getArtifactUrl?.(taskArtifact)
|
||||
.then(async (res) => {
|
||||
const url = res?.data || '';
|
||||
if (url) {
|
||||
const content = await fetch(url).then((res) => res.text());
|
||||
setContent(content);
|
||||
}
|
||||
})
|
||||
.catch(() => { });
|
||||
}
|
||||
}, [taskArtifact, api]);
|
||||
return content;
|
||||
};
|
||||
Reference in New Issue
Block a user