Browse Source
Reviewed-on: #25 Co-authored-by: YaroslavBerkuta <yaroslavberkuta@gmail.com> Co-committed-by: YaroslavBerkuta <yaroslavberkuta@gmail.com>change/chat-conversation
11 changed files with 120 additions and 47 deletions
@ -1 +1 @@
@@ -1 +1 @@
|
||||
export class UnknownException extends Error { } |
||||
export class UnknownException extends Error {} |
||||
|
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
export const htmlContent = (content: string) => { |
||||
return ` |
||||
<!DOCTYPE html> |
||||
<html lang="en"> |
||||
<head> |
||||
<meta charset="UTF-8"> |
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||
<title>Text File Viewer</title> |
||||
</head> |
||||
<body> |
||||
<p> |
||||
${content} |
||||
</p> |
||||
</body> |
||||
</html> |
||||
` |
||||
} |
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
import { useEffect, useState } from 'react' |
||||
|
||||
export const useFileContent = (url: string) => { |
||||
const [fileContent, setFileContent] = useState('') |
||||
|
||||
const fetchFileContent = async () => { |
||||
try { |
||||
const res = await fetch(url) |
||||
if (res.status !== 200) { |
||||
setFileContent('Помилка завантаження файлу!') |
||||
} else { |
||||
const content = await res.text() |
||||
setFileContent(content) |
||||
} |
||||
} catch (error) { |
||||
console.error('Error fetching file content:', error) |
||||
} |
||||
} |
||||
|
||||
useEffect(() => { |
||||
fetchFileContent() |
||||
}, [url]) |
||||
|
||||
return { |
||||
fileContent, |
||||
} |
||||
} |
Loading…
Reference in new issue