Skip to content

Commit

Permalink
Add a app info drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
HuakunShen committed May 7, 2024
1 parent 6f87f97 commit de5bab2
Show file tree
Hide file tree
Showing 13 changed files with 656 additions and 109 deletions.
Binary file modified devclean-ui/bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions devclean-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-progress": "^1.0.3",
"@radix-ui/react-scroll-area": "^1.0.5",
"@radix-ui/react-separator": "^1.0.3",
Expand All @@ -30,6 +31,7 @@
"react-dom": "^18.2.0",
"tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7",
"vaul": "^0.9.0",
"zod": "^3.23.6"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion devclean-ui/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"package": {
"productName": "devclean-ui",
"version": "0.1.5"
"version": "0.1.6"
},
"tauri": {
"allowlist": {
Expand Down
100 changes: 2 additions & 98 deletions devclean-ui/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,109 +1,13 @@
import "./App.css";
import { useEffect, useState } from "react";
import { Button } from "@/components/ui/button";
import { ThemeProvider } from "@/components/theme-provider";
import { ModeToggle } from "./components/mode-toggle";
import { pathExists, scan } from "@/lib/command";
import { AnalyzeTarget, AnalyzeTargets } from "./lib/model";
import { DisplayTable } from "./components/table/display-table";
import { Toaster } from "@/components/ui/toaster";
import { open } from "@tauri-apps/api/dialog";
import { z } from "zod";
import { useToast } from "./components/ui/use-toast";
import {
ReloadIcon,
FileIcon,
MagnifyingGlassIcon,
} from "@radix-ui/react-icons";
import { HomePage } from "./components/pages/home";

function App() {
const [targets, setTargets] = useState<AnalyzeTarget[]>([]);
const [pickedFolder, setPickedFolder] = useState<string>("");
const [scanning, setScanning] = useState(false);
const { toast } = useToast();

useEffect(() => {
const cacheScanFolder = localStorage.getItem("cache-scan-folder");
if (cacheScanFolder) {
setPickedFolder(cacheScanFolder);
}
}, []);

useEffect(() => {
localStorage.setItem("cache-scan-folder", pickedFolder);
}, [pickedFolder]);

return (
<ThemeProvider defaultTheme="dark" storageKey="vite-ui-theme">
<Toaster />
<div data-tauri-drag-region className="h-8" />
<div className="container bg-background text-foreground flex flex-col max-h-screen py-2 space-y-4">
<div className="flex space-x-2">
<Button
variant="outline"
onClick={() => {
open({ directory: true })
.then((res) => {
setPickedFolder(z.string().parse(res));
})
.catch(console.error);
}}
>
<FileIcon className="mr-2 h-4 w-4" />
Pick Folder
</Button>
<Button
disabled={scanning}
variant="secondary"
className="dark:bg-green-700 dark:hover:bg-green-600 bg-green-600 text-white hover:bg-green-500"
onClick={async () => {
setScanning(true);
const exists = await pathExists(pickedFolder)
.then((exists) => {
if (exists) {
} else {
toast({
variant: "destructive",
title: "Path Not Found",
});
setScanning(false);
}
return exists;
})
.catch((err) => {
toast({
variant: "destructive",
title: "Error",
description: err,
});
});
if (exists) {
await scan(pickedFolder, 10)
.then((res) => {
setTargets(AnalyzeTargets.parse(res));
})
.catch(console.error);
setScanning(false);
}
}}
>
{scanning ? (
<ReloadIcon className="mr-2 h-4 w-4 animate-spin" />
) : (
<MagnifyingGlassIcon className="mr-2 h-4 w-4" />
)}
Scan
</Button>
<ModeToggle />
</div>
{pickedFolder && (
<div>
<strong className="font-bold">Picked Path:</strong>{" "}
<pre className="inline">{pickedFolder}</pre>
</div>
)}
<DisplayTable data={targets} />
</div>
<HomePage />
</ThemeProvider>
);
}
Expand Down
122 changes: 122 additions & 0 deletions devclean-ui/src/components/about-drawer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import * as React from "react";
import { MinusIcon, PlusIcon, InfoCircledIcon } from "@radix-ui/react-icons";
import { Button } from "@/components/ui/button";
import {
Drawer,
DrawerClose,
DrawerContent,
DrawerDescription,
DrawerFooter,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
} from "@/components/ui/drawer";
import { About } from "./about";

const data = [
{
goal: 400,
},
{
goal: 300,
},
{
goal: 200,
},
{
goal: 300,
},
{
goal: 200,
},
{
goal: 278,
},
{
goal: 189,
},
{
goal: 239,
},
{
goal: 300,
},
{
goal: 200,
},
{
goal: 278,
},
{
goal: 189,
},
{
goal: 349,
},
];

export function AboutDrawer() {
const [goal, setGoal] = React.useState(350);

function onClick(adjustment: number) {
setGoal(Math.max(200, Math.min(400, goal + adjustment)));
}

return (
<Drawer>
<DrawerTrigger asChild>
<Button variant="outline">
<InfoCircledIcon className="mr-2" /> Info
</Button>
</DrawerTrigger>
<DrawerContent>
<div className="mx-auto w-full max-w-sm">
<DrawerHeader>
<DrawerTitle>App Info</DrawerTitle>
<DrawerDescription>Clean your project files.</DrawerDescription>
</DrawerHeader>
<About className="mt-2" />
{/* <div className="p-4 pb-0">
<div className="flex items-center justify-center space-x-2">
<Button
variant="outline"
size="icon"
className="h-8 w-8 shrink-0 rounded-full"
onClick={() => onClick(-10)}
disabled={goal <= 200}
>
<MinusIcon className="h-4 w-4" />
<span className="sr-only">Decrease</span>
</Button>
<div className="flex-1 text-center">
<div className="text-7xl font-bold tracking-tighter">
{goal}
</div>
<div className="text-[0.70rem] uppercase text-muted-foreground">
Calories/day
</div>
</div>
<Button
variant="outline"
size="icon"
className="h-8 w-8 shrink-0 rounded-full"
onClick={() => onClick(10)}
disabled={goal >= 400}
>
<PlusIcon className="h-4 w-4" />
<span className="sr-only">Increase</span>
</Button>
</div>
<div className="mt-3 h-[120px]"></div>
</div> */}
<DrawerFooter>
{/* <Button>Submit</Button>
<DrawerClose asChild>
<Button variant="outline">Cancel</Button>
</DrawerClose> */}
</DrawerFooter>
</div>
</DrawerContent>
</Drawer>
);
}
39 changes: 39 additions & 0 deletions devclean-ui/src/components/about-sheet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import {
Sheet,
SheetClose,
SheetContent,
SheetDescription,
SheetFooter,
SheetHeader,
SheetTitle,
SheetTrigger,
} from "@/components/ui/sheet";
import { InfoCircledIcon } from "@radix-ui/react-icons";
import { About } from "./about";

export function AboutSheet({ className }: { className?: string }) {
return (
<Sheet>
<SheetTrigger asChild>
<Button variant="outline">
<InfoCircledIcon className="mr-2" /> info
</Button>
</SheetTrigger>
<SheetContent>
<SheetHeader>
<SheetTitle>App Info</SheetTitle>
<SheetDescription>Clean your projects with ease</SheetDescription>
</SheetHeader>
<About className={className ?? ""} />
{/* <SheetFooter>
<SheetClose asChild>
<Button type="submit">Save changes</Button>
</SheetClose>
</SheetFooter> */}
</SheetContent>
</Sheet>
);
}
62 changes: 62 additions & 0 deletions devclean-ui/src/components/about.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { getVersion } from "@tauri-apps/api/app";
import { useState } from "react";
import { Button } from "./ui/button";
import { open } from "@tauri-apps/api/shell";

function BtnLink({
href,
children,
}: {
href: string;
children: React.ReactNode;
}) {
return (
<Button
variant="link"
onClick={() => {
open(href);
}}
>
{children}
</Button>
);
}

export function About({ className }: { className?: string }) {
const [version, setVersion] = useState<string | null>(null);
getVersion().then((v) => setVersion(v));

return (
<div className={`flex flex-col space-y-3 mt-4 ${className}`}>
<p>
<strong className="font-bold">App Name:{" "}</strong>DevClean-UI
</p>
<p>
<strong className="font-bold">App Version:{" "}</strong>
{version}
</p>
<p>
<strong>Source Code: </strong>
<BtnLink href="https://github.com/HuakunShen/devclean.git">
https://github.com/HuakunShen/devclean.git
</BtnLink>
</p>
<p>
<BtnLink href="https://github.com/HuakunShen/devclean/releases/latest">
Latest Release
</BtnLink>
</p>
<p>
Auto Updater is configured. Every time a new release is published your
app will ask you whether you want to update to the latest release. Auto
update is in just one click.
</p>
<p>
<strong>Author: </strong>
<BtnLink href="https://github.com/HuakunShen">
https://github.com/HuakunShen
</BtnLink>
</p>
</div>
);
}
Loading

0 comments on commit de5bab2

Please sign in to comment.