init structure
This commit is contained in:
95
src/components/cstb/Prepare.tsx
Normal file
95
src/components/cstb/Prepare.tsx
Normal file
@@ -0,0 +1,95 @@
|
||||
import { Button, Spinner } from "@heroui/react"
|
||||
import { useRouter } from "next/navigation"
|
||||
import React, { useEffect, useState } from "react"
|
||||
import { useSnapshot } from "valtio"
|
||||
import { steamStore } from "@/store/steam"
|
||||
import { open } from "@tauri-apps/plugin-dialog"
|
||||
|
||||
export function Prepare() {
|
||||
const router = useRouter()
|
||||
const steam = useSnapshot(steamStore.state)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [steamDir, setSteamDir] = useState(steam.dir)
|
||||
const [cs2Dir, setCs2Dir] = useState(steam.csDir)
|
||||
|
||||
useEffect(() => {
|
||||
const checkPaths = async () => {
|
||||
if (steam.dir && steam.csDir) {
|
||||
router.push("/home")
|
||||
} else {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
checkPaths()
|
||||
}, [steam.dir, steam.csDir, router])
|
||||
|
||||
const handleSelectSteamDir = async () => {
|
||||
const selected = await open({
|
||||
title: "选择 Steam.exe 文件",
|
||||
filters: [{ name: "Steam", extensions: ["exe"] }],
|
||||
})
|
||||
if (selected) {
|
||||
const dir = selected.replace(/\\[^\\]+$/, "")
|
||||
setSteamDir(dir)
|
||||
steamStore.state.dir = dir
|
||||
}
|
||||
}
|
||||
|
||||
const handleSelectCs2Dir = async () => {
|
||||
const selected = await open({
|
||||
title: "选择 CS2 文件夹",
|
||||
directory: true,
|
||||
})
|
||||
if (selected) {
|
||||
setCs2Dir(selected)
|
||||
steamStore.state.csDir = selected
|
||||
}
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center w-full h-screen gap-6">
|
||||
<Spinner size="lg" />
|
||||
<p>正在检查路径...</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col w-full max-w-3xl gap-2 p-5">
|
||||
<p className="text-center">当前路径等设置有待确认</p>
|
||||
<br />
|
||||
<p>Steam所在文件夹</p>
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
className="flex-grow px-2 py-1 mb-2 rounded-lg"
|
||||
value={steamDir}
|
||||
onChange={(e) => setSteamDir(e.target.value)}
|
||||
/>
|
||||
<Button onPress={handleSelectSteamDir} variant="solid" color="primary" size="sm">
|
||||
选择
|
||||
</Button>
|
||||
</div>
|
||||
<p>CS2所在文件夹</p>
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
className="flex-grow px-2 py-1 mb-2 rounded-lg"
|
||||
value={cs2Dir}
|
||||
onChange={(e) => setCs2Dir(e.target.value)}
|
||||
/>
|
||||
<Button onPress={handleSelectCs2Dir} variant="solid" color="primary" size="sm">
|
||||
选择
|
||||
</Button>
|
||||
</div>
|
||||
<Button
|
||||
onPress={() => router.push("/home")}
|
||||
variant="solid"
|
||||
color="primary"
|
||||
size="sm"
|
||||
isDisabled={!steamDir || !cs2Dir}
|
||||
>
|
||||
进入
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user