mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
fix: config首次加载
This commit is contained in:
@@ -1,12 +1,14 @@
|
|||||||
import { Tab, Tabs } from '@heroui/tabs'
|
import { Tab, Tabs } from '@heroui/tabs'
|
||||||
import { useLocalStorage } from '@uidotdev/usehooks'
|
import { useLocalStorage } from '@uidotdev/usehooks'
|
||||||
import { useEffect } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { useForm } from 'react-hook-form'
|
import { useForm } from 'react-hook-form'
|
||||||
import toast from 'react-hot-toast'
|
import toast from 'react-hot-toast'
|
||||||
import { useMediaQuery } from 'react-responsive'
|
import { useMediaQuery } from 'react-responsive'
|
||||||
|
|
||||||
import key from '@/const/key'
|
import key from '@/const/key'
|
||||||
|
|
||||||
|
import PageLoading from '@/components/page_loading'
|
||||||
|
|
||||||
import useConfig from '@/hooks/use-config'
|
import useConfig from '@/hooks/use-config'
|
||||||
import useMusic from '@/hooks/use-music'
|
import useMusic from '@/hooks/use-music'
|
||||||
|
|
||||||
@@ -15,6 +17,7 @@ import WebUIConfigCard from './webui'
|
|||||||
|
|
||||||
export default function ConfigPage() {
|
export default function ConfigPage() {
|
||||||
const { config, saveConfigWithoutNetwork, refreshConfig } = useConfig()
|
const { config, saveConfigWithoutNetwork, refreshConfig } = useConfig()
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
const {
|
const {
|
||||||
control: onebotControl,
|
control: onebotControl,
|
||||||
handleSubmit: handleOnebotSubmit,
|
handleSubmit: handleOnebotSubmit,
|
||||||
@@ -82,13 +85,16 @@ export default function ConfigPage() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const onRefresh = async () => {
|
const onRefresh = async (shotTip = true) => {
|
||||||
try {
|
try {
|
||||||
|
setLoading(true)
|
||||||
await refreshConfig()
|
await refreshConfig()
|
||||||
toast.success('刷新成功')
|
if (shotTip) toast.success('刷新成功')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const msg = (error as Error).message
|
const msg = (error as Error).message
|
||||||
toast.error(`刷新失败: ${msg}`)
|
toast.error(`刷新失败: ${msg}`)
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,6 +103,10 @@ export default function ConfigPage() {
|
|||||||
resetWebUI()
|
resetWebUI()
|
||||||
}, [config])
|
}, [config])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
onRefresh(false)
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="w-[1000px] max-w-full md:mx-auto gap-4 py-8 px-2 md:py-10">
|
<section className="w-[1000px] max-w-full md:mx-auto gap-4 py-8 px-2 md:py-10">
|
||||||
<Tabs
|
<Tabs
|
||||||
@@ -106,12 +116,13 @@ export default function ConfigPage() {
|
|||||||
isVertical={isMediumUp}
|
isVertical={isMediumUp}
|
||||||
classNames={{
|
classNames={{
|
||||||
tabList: 'sticky flex top-14 bg-opacity-50 backdrop-blur-sm',
|
tabList: 'sticky flex top-14 bg-opacity-50 backdrop-blur-sm',
|
||||||
panel: 'w-full',
|
panel: 'w-full relative',
|
||||||
base: 'md:!w-auto flex-grow-0 flex-shrink-0 mr-0',
|
base: 'md:!w-auto flex-grow-0 flex-shrink-0 mr-0',
|
||||||
cursor: 'bg-opacity-60 backdrop-blur-sm'
|
cursor: 'bg-opacity-60 backdrop-blur-sm'
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Tab title="OneBot配置" key="onebot">
|
<Tab title="OneBot配置" key="onebot">
|
||||||
|
<PageLoading loading={loading} />
|
||||||
<OneBotConfigCard
|
<OneBotConfigCard
|
||||||
isSubmitting={isOnebotSubmitting}
|
isSubmitting={isOnebotSubmitting}
|
||||||
onRefresh={onRefresh}
|
onRefresh={onRefresh}
|
||||||
|
Reference in New Issue
Block a user