mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-26 23:56:02 +08:00
779fefd86d
- Add SyncMethod enum (Auto/Symlink/Copy) in Rust backend - Implement sync_to_app_dir with symlink support (cross-platform) - Add SkillSyncMethodSettings UI component (simplified 2-button selector) - Add i18n support for zh/en/ja - Replace copy_to_app with configurable sync_to_app_dir - Add skill_sync_method field to AppSettings User can now choose between symlink (disk space saving) or copy (best compatibility) in Settings > General.
79 lines
2.0 KiB
TypeScript
79 lines
2.0 KiB
TypeScript
import { useTranslation } from "react-i18next";
|
|
import { Button } from "@/components/ui/button";
|
|
import { cn } from "@/lib/utils";
|
|
import type { SkillSyncMethod } from "@/types";
|
|
|
|
export interface SkillSyncMethodSettingsProps {
|
|
value: SkillSyncMethod;
|
|
onChange: (value: SkillSyncMethod) => void;
|
|
}
|
|
|
|
export function SkillSyncMethodSettings({
|
|
value,
|
|
onChange,
|
|
}: SkillSyncMethodSettingsProps) {
|
|
const { t } = useTranslation();
|
|
|
|
// Handle default values: undefined or "auto" defaults to symlink display
|
|
const displayValue = value === "copy" ? "copy" : "symlink";
|
|
|
|
return (
|
|
<section className="space-y-2">
|
|
<header className="space-y-1">
|
|
<h3 className="text-sm font-medium">{t("settings.skillSync.title")}</h3>
|
|
<p className="text-xs text-muted-foreground">
|
|
{t("settings.skillSync.description")}
|
|
</p>
|
|
</header>
|
|
<div className="inline-flex gap-1 rounded-md border border-border-default bg-background p-1">
|
|
<SyncMethodButton
|
|
active={displayValue === "symlink"}
|
|
onClick={() => onChange("symlink")}
|
|
>
|
|
{t("settings.skillSync.symlink")}
|
|
</SyncMethodButton>
|
|
<SyncMethodButton
|
|
active={displayValue === "copy"}
|
|
onClick={() => onChange("copy")}
|
|
>
|
|
{t("settings.skillSync.copy")}
|
|
</SyncMethodButton>
|
|
</div>
|
|
{displayValue === "symlink" && (
|
|
<p className="text-xs text-muted-foreground">
|
|
{t("settings.skillSync.symlinkHint")}
|
|
</p>
|
|
)}
|
|
</section>
|
|
);
|
|
}
|
|
|
|
interface SyncMethodButtonProps {
|
|
active: boolean;
|
|
onClick: () => void;
|
|
children: React.ReactNode;
|
|
}
|
|
|
|
function SyncMethodButton({
|
|
active,
|
|
onClick,
|
|
children,
|
|
}: SyncMethodButtonProps) {
|
|
return (
|
|
<Button
|
|
type="button"
|
|
onClick={onClick}
|
|
size="sm"
|
|
variant={active ? "default" : "ghost"}
|
|
className={cn(
|
|
"min-w-[96px]",
|
|
active
|
|
? "shadow-sm"
|
|
: "text-muted-foreground hover:text-foreground hover:bg-muted",
|
|
)}
|
|
>
|
|
{children}
|
|
</Button>
|
|
);
|
|
}
|