import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from '@/components/ui/dialog' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { useRepoStore } from '../store' import { useState, useEffect } from 'react' import { get, set } from 'idb-keyval' const SYNC_REPO_STORAGE_KEY = 'sync-repo-mapping' export function SyncRepoDialog() { const { syncDialogOpen, setSyncDialogOpen, selectedSyncRepo, buildSync } = useRepoStore() const [toRepo, setToRepo] = useState('') useEffect(() => { const loadSavedMapping = async () => { if (syncDialogOpen && selectedSyncRepo) { const currentPath = selectedSyncRepo.path || '' // 从 idb-keyval 获取存储的映射 const mapping = await get>(SYNC_REPO_STORAGE_KEY) // 如果有存储的值,使用存储的值,否则使用当前仓库路径 setToRepo(mapping?.[currentPath] || currentPath) } } loadSavedMapping() }, [syncDialogOpen, selectedSyncRepo]) const handleSync = async () => { if (!selectedSyncRepo || !toRepo.trim()) { return } // 保存映射到 idb-keyval const currentPath = selectedSyncRepo.path || '' const mapping = await get>(SYNC_REPO_STORAGE_KEY) || {} mapping[currentPath] = toRepo await set(SYNC_REPO_STORAGE_KEY, mapping) await buildSync(selectedSyncRepo, { toRepo }) setSyncDialogOpen(false) } return ( 同步仓库到 Gitea 将仓库 {selectedSyncRepo?.path} 同步到目标仓库
setToRepo(e.target.value)} />

格式: owner/repo-name

) }