From edc2fe050a4b3b7a695f2419bd1578dbe77abb1c Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 8 Nov 2024 15:10:06 +0800 Subject: [PATCH] chore: debug info use query --- .../plugins/plugin-page/debug-info.tsx | 17 +++++++---------- web/service/use-plugins.ts | 9 ++++++++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/web/app/components/plugins/plugin-page/debug-info.tsx b/web/app/components/plugins/plugin-page/debug-info.tsx index de8149fcd2..9c777c5dd9 100644 --- a/web/app/components/plugins/plugin-page/debug-info.tsx +++ b/web/app/components/plugins/plugin-page/debug-info.tsx @@ -1,6 +1,6 @@ 'use client' import type { FC } from 'react' -import React, { useEffect } from 'react' +import React from 'react' import { RiArrowRightUpLine, RiBugLine, @@ -9,19 +9,16 @@ import { useTranslation } from 'react-i18next' import KeyValueItem from '../base/key-value-item' import Tooltip from '@/app/components/base/tooltip' import Button from '@/app/components/base/button' -import type { DebugInfo as DebugInfoTypes } from '../types' -import { fetchDebugKey } from '@/service/plugins' +import { useDebugKey } from '@/service/use-plugins' const i18nPrefix = 'plugin.debugInfo' const DebugInfo: FC = () => { const { t } = useTranslation() - const [info, setInfo] = React.useState(null) - useEffect(() => { - fetchDebugKey().then((res) => { - setInfo(res) - }) - }, []) + const { data: info, isLoading } = useDebugKey() + + if (isLoading) return null + return ( {
{ }) } } + +export const useDebugKey = () => { + return useQuery({ + queryKey: [NAME_SPACE, 'debugKey'], + queryFn: () => get('/workspaces/current/plugin/debugging-key'), + }) +}