init structure

This commit is contained in:
2025-03-17 00:50:03 +08:00
parent 3c5a354db1
commit ffe351d14f
2 changed files with 99 additions and 35 deletions

View File

@@ -1,50 +1,19 @@
"use client"
import Nav from "@/components/window/Nav"
import { Button } from "@heroui/react"
// import { open } from "@tauri-apps/plugin-dialog"
import { useRouter } from "next/navigation"
import React from "react"
import { Prepare } from "@/components/cstb/Prepare"
const Home = () => {
const router = useRouter()
// const [file, setFile] = React.useState<string | null>("")
// const openFile = async () => {
// const filePath = await open({
// multiple: true,
// directory: false,
// })
// setFile(filePath?.join("\n") || " ")
// }
return (
<>
<Nav />
<main
className="flex flex-col items-center justify-center w-full h-screen gap-6"
data-tauri-drag-region
>
<main className="flex flex-col items-center justify-center w-full h-screen gap-6" data-tauri-drag-region>
<h1 className="text-4xl font-bold tracking-wide">CS </h1>
<Button
onPress={() => router.push("/home")}
variant="solid"
color="primary"
size="sm"
>
</Button>
{/* <button
type="button"
onClick={openFile}
className="px-4 py-1 text-white bg-blue-500 rounded"
>
选择文件
</button>
<p className="text-center bg-zinc-50">{file}</p> */}
<Prepare />
</main>
</>
)
}
export default Home
export default Home

View 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>
)
}