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

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

commit 74baae3cb7b211da039e2f2047aa2e7ef027a640
Author: robin <[email protected]>
AuthorDate: Wed Sep 25 16:40:48 2024 +0800

    refactor(render-markdown-codehighlight): Update useHighlightCode hook to 
accept a request object
---
 render-markdown-codehighlight/hooks.ts | 10 ++++++----
 render-markdown-codehighlight/types.ts |  7 +++++++
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/render-markdown-codehighlight/hooks.ts 
b/render-markdown-codehighlight/hooks.ts
index 1cec680..3ccbeb4 100644
--- a/render-markdown-codehighlight/hooks.ts
+++ b/render-markdown-codehighlight/hooks.ts
@@ -17,19 +17,21 @@
  * under the License.
  */
 
-import { useEffect, useState } from 'react';
+import { useEffect, useState, FC } from 'react';
 import hljs from 'highlight.js';
 import { themeStyles } from './themeStyles';
+import { pluginHookProps, Request } from './types';
 
-
-const useHighlightCode = (props: HTMLElement | null | {
+const useHighlightCode: FC<pluginHookProps> = (props: HTMLElement | null | {
   current: HTMLElement | null;
+}, request: Request = {
+  get: fetch,
 }) => {
   const [selectTheme, setSelectTheme] = useState<string>('default');
 
   // Fetch theme from API
   useEffect(() => {
-    fetch('/answer/api/v1/render/config')
+    request.get('/answer/api/v1/render/config')
       .then((response) => response.json())
       .then((result) => {
         console.log('Fetched theme:', result.data.select_theme);
diff --git a/render-markdown-codehighlight/types.ts 
b/render-markdown-codehighlight/types.ts
new file mode 100644
index 0000000..ad5aebd
--- /dev/null
+++ b/render-markdown-codehighlight/types.ts
@@ -0,0 +1,7 @@
+import { RefObject } from 'react';
+
+export type pluginHookProps = HTMLElement | RefObject<HTMLElement> | null;
+
+export interface Request {
+    get: (url: string) => Promise<Response>;
+}

Reply via email to