mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-12 18:26:36 +08:00
ui 优化
This commit is contained in:
@@ -16,7 +16,6 @@ import {
|
|||||||
} from '@/components/ui/alert-dialog';
|
} from '@/components/ui/alert-dialog';
|
||||||
import {Badge} from '@/components/ui/badge';
|
import {Badge} from '@/components/ui/badge';
|
||||||
import {Button} from '@/components/ui/button';
|
import {Button} from '@/components/ui/button';
|
||||||
import {DiffDialog} from '@/app/(main)/config-versions/components/diff-dialog';
|
|
||||||
import type {ConfigDiffResult, ProxyRouteItem} from '@/lib/services/openflare';
|
import type {ConfigDiffResult, ProxyRouteItem} from '@/lib/services/openflare';
|
||||||
import {ConfigVersionService} from '@/lib/services/openflare';
|
import {ConfigVersionService} from '@/lib/services/openflare';
|
||||||
|
|
||||||
@@ -39,23 +38,20 @@ interface RouteHeaderProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function RouteHeader({ route }: RouteHeaderProps) {
|
export function RouteHeader({ route }: RouteHeaderProps) {
|
||||||
const [diffOpen, setDiffOpen] = useState(false);
|
|
||||||
const [publishConfirmOpen, setPublishConfirmOpen] = useState(false);
|
const [publishConfirmOpen, setPublishConfirmOpen] = useState(false);
|
||||||
const [diff, setDiff] = useState<ConfigDiffResult | null>(null);
|
const [diff, setDiff] = useState<ConfigDiffResult | null>(null);
|
||||||
const [diffLoading, setDiffLoading] = useState(false);
|
const [diffLoading, setDiffLoading] = useState(false);
|
||||||
const [diffError, setDiffError] = useState<string | null>(null);
|
|
||||||
const [publishing, setPublishing] = useState(false);
|
const [publishing, setPublishing] = useState(false);
|
||||||
|
|
||||||
const loadDiff = useCallback(async () => {
|
const loadDiff = useCallback(async () => {
|
||||||
setDiffLoading(true);
|
setDiffLoading(true);
|
||||||
setDiffError(null);
|
|
||||||
try {
|
try {
|
||||||
const diffData = await ConfigVersionService.diff();
|
const diffData = await ConfigVersionService.diff();
|
||||||
setDiff(diffData);
|
setDiff(diffData);
|
||||||
return diffData;
|
return diffData;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = getErrorMessage(error);
|
const message = getErrorMessage(error);
|
||||||
setDiffError(message);
|
toast.error('获取配置差异失败', { description: message });
|
||||||
return null;
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
setDiffLoading(false);
|
setDiffLoading(false);
|
||||||
@@ -63,7 +59,6 @@ export function RouteHeader({ route }: RouteHeaderProps) {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handlePublishClick = useCallback(async () => {
|
const handlePublishClick = useCallback(async () => {
|
||||||
setDiffOpen(true);
|
|
||||||
const diffData = diff ?? (await loadDiff());
|
const diffData = diff ?? (await loadDiff());
|
||||||
if (!diffData) {
|
if (!diffData) {
|
||||||
return;
|
return;
|
||||||
@@ -81,7 +76,6 @@ export function RouteHeader({ route }: RouteHeaderProps) {
|
|||||||
const version = await ConfigVersionService.publish();
|
const version = await ConfigVersionService.publish();
|
||||||
toast.success('发布成功', { description: `版本 ${version.version}` });
|
toast.success('发布成功', { description: `版本 ${version.version}` });
|
||||||
setPublishConfirmOpen(false);
|
setPublishConfirmOpen(false);
|
||||||
setDiffOpen(false);
|
|
||||||
setDiff(null);
|
setDiff(null);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error('发布失败', { description: getErrorMessage(error) });
|
toast.error('发布失败', { description: getErrorMessage(error) });
|
||||||
@@ -129,19 +123,6 @@ export function RouteHeader({ route }: RouteHeaderProps) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DiffDialog
|
|
||||||
open={diffOpen}
|
|
||||||
onOpenChange={(open) => {
|
|
||||||
setDiffOpen(open);
|
|
||||||
if (!open) {
|
|
||||||
setPublishConfirmOpen(false);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
diff={diff}
|
|
||||||
loading={diffLoading}
|
|
||||||
error={diffError}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<AlertDialog open={publishConfirmOpen} onOpenChange={setPublishConfirmOpen}>
|
<AlertDialog open={publishConfirmOpen} onOpenChange={setPublishConfirmOpen}>
|
||||||
<AlertDialogContent>
|
<AlertDialogContent>
|
||||||
<AlertDialogHeader>
|
<AlertDialogHeader>
|
||||||
|
|||||||
Reference in New Issue
Block a user