This is an automated email from the ASF dual-hosted git repository.

robin0716 pushed a commit to branch refactor/render-markdown-codehighlight
in repository https://gitbox.apache.org/repos/asf/incubator-answer-plugins.git

commit e3ff0a602ec9e4a16a4b918ff7f085375a1dd00d
Author: robin <[email protected]>
AuthorDate: Fri Nov 15 12:26:27 2024 +0800

    refactor(render-markdown-codehighlight): Update useHighlightCode hook to 
use custom fetch function
---
 render-markdown-codehighlight/hooks.ts | 13 +++++++++----
 render-markdown-codehighlight/types.ts |  2 +-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/render-markdown-codehighlight/hooks.ts 
b/render-markdown-codehighlight/hooks.ts
index 3ccbeb4..3b5c51c 100644
--- a/render-markdown-codehighlight/hooks.ts
+++ b/render-markdown-codehighlight/hooks.ts
@@ -22,20 +22,25 @@ import hljs from 'highlight.js';
 import { themeStyles } from './themeStyles';
 import { pluginHookProps, Request } from './types';
 
+const get = async (url: string) => {
+  const response = await fetch(url);
+  const { data } = await response.json();
+  return data;
+};
+
 const useHighlightCode: FC<pluginHookProps> = (props: HTMLElement | null | {
   current: HTMLElement | null;
 }, request: Request = {
-  get: fetch,
+  get
 }) => {
   const [selectTheme, setSelectTheme] = useState<string>('default');
 
   // Fetch theme from API
   useEffect(() => {
     request.get('/answer/api/v1/render/config')
-      .then((response) => response.json())
       .then((result) => {
-        console.log('Fetched theme:', result.data.select_theme);
-        setSelectTheme(result.data.select_theme);
+        console.log('Fetched theme:', result.select_theme);
+        setSelectTheme(result.select_theme);
       })
       .catch((error) => {
         console.error('Error fetching theme:', error);
diff --git a/render-markdown-codehighlight/types.ts 
b/render-markdown-codehighlight/types.ts
index 6a034fc..dcb5217 100644
--- a/render-markdown-codehighlight/types.ts
+++ b/render-markdown-codehighlight/types.ts
@@ -22,5 +22,5 @@ import { RefObject } from 'react';
 export type pluginHookProps = HTMLElement | RefObject<HTMLElement> | null;
 
 export interface Request {
-    get: (url: string) => Promise<Response>;
+    get: (url: string) => Promise<any>;
 }

Reply via email to