diff --git a/ivette/src/dome/misc/system.ts b/ivette/src/dome/misc/system.ts index ca044d7402321f8bf66222e3ae5703ef42b32db6..82e0aefc1c0e8a10f2752df1fdf9b26c6d171451 100644 --- a/ivette/src/dome/misc/system.ts +++ b/ivette/src/dome/misc/system.ts @@ -658,27 +658,3 @@ export default { }; // -------------------------------------------------------------------------- -// --- Get filecontent -// -------------------------------------------------------------------------- - -export function getFileContent( - path: string, - callback: (val: string) => void -): void { - fetch(path) - .then((response) => { - if (!response.ok) { - // Statut HTTP 404 ou autre erreur - throw new Error(`HTTP error! status: ${response.status}`); - } - return response.text(); - }) - .then(callback) - .catch((error) => { - // eslint-disable-next-line no-console - console.error('Error while loading the file :', error); - } - ); -} - -// -------------------------------------------------------------------------- diff --git a/ivette/src/dome/renderer/dome.tsx b/ivette/src/dome/renderer/dome.tsx index 1e03e03aba57821328ca78f0609d2de0e931998e..b2d3354f0e0db8d66ff75b3e8fd9b88c4c1aac82 100644 --- a/ivette/src/dome/renderer/dome.tsx +++ b/ivette/src/dome/renderer/dome.tsx @@ -43,6 +43,7 @@ import React from 'react'; import Emitter from 'events'; import { createRoot } from 'react-dom/client'; import { ipcRenderer } from 'electron'; +import { join } from 'path'; import SYS, * as System from 'dome/system'; import { State, GlobalState, useGlobalState } from './data/states'; @@ -830,10 +831,26 @@ export function useFileContent( ): string { const [ fileContent, setFileContent ] = React.useState(""); const callback = useProtected(setFileContent); - System.getFileContent(path, callback); + System.readFile(path) + .then((response) => callback(response.toString())) + .catch((error) => { + // eslint-disable-next-line no-console + console.error('Error while loading the file :', error); + }); return fileContent; } +/** + * A hook to retrieve text from a doc file. + * @param path Path from ivette's 'doc' directory + */ +export function useDocContent( + path: string, +): string { + return useFileContent(join(process.cwd(), 'ivette/doc/', path)); +} + + /** Debounced callback (waiting time in milliseconds). The returned callback will be only fired when the component is mounted.