import React, { useEffect } from "react";
import { formatRelative } from "date-fns";
import { Tooltip as ReactTooltip } from "react-tooltip";
import { AtuinState, useStore } from "@/state/store";
import { useToast } from "@/components/ui/use-toast";
import { ToastAction } from "@/components/ui/toast";
import { invoke } from "@tauri-apps/api/core";
import {
Card,
CardHeader,
CardBody,
Listbox,
ListboxItem,
} from "@nextui-org/react";
import {
Bar,
BarChart,
CartesianGrid,
LabelList,
XAxis,
YAxis,
} from "recharts";
import { ChartConfig, ChartContainer } from "@/components/ui/chart";
import { Clock, Terminal } from "lucide-react";
import ActivityCalendar from "react-activity-calendar";
import HistoryRow from "@/components/history/HistoryRow";
import { ShellHistory } from "@/state/models";
function StatCard({ name, stat }: any) {
return (
{name}
{stat}
);
}
function TopChart({ chartData }: any) {
const chartConfig = {
command: {
label: "Command",
color: "#c4edde",
},
} satisfies ChartConfig;
return (
value.slice(0, 3)}
hide
/>
);
}
function Header({ name }: any) {
let greeting = name && name.length > 0 ? "Hey, " + name + "!" : "Hey!";
return (
{greeting}
Welcome to{" "}
Atuin
.
);
}
const explicitTheme = {
light: ["#f0f0f0", "#c4edde", "#7ac7c4", "#f73859", "#384259"],
dark: ["#f0f0f0", "#c4edde", "#7ac7c4", "#f73859", "#384259"],
};
export default function Home() {
const homeInfo = useStore((state: AtuinState) => state.homeInfo);
const user = useStore((state: AtuinState) => state.user);
const calendar = useStore((state: AtuinState) => state.calendar);
const runbooks = useStore((state: AtuinState) => state.runbooks);
const weekStart = useStore((state: AtuinState) => state.weekStart);
const refreshHomeInfo = useStore(
(state: AtuinState) => state.refreshHomeInfo,
);
const refreshUser = useStore((state: AtuinState) => state.refreshUser);
const refreshCalendar = useStore(
(state: AtuinState) => state.refreshCalendar,
);
const refreshRunbooks = useStore(
(state: AtuinState) => state.refreshRunbooks,
);
const { toast } = useToast();
useEffect(() => {
refreshHomeInfo();
refreshUser();
refreshCalendar();
refreshRunbooks();
console.log(homeInfo);
let setup = async () => {
let installed = await invoke("is_cli_installed");
console.log("CLI installation status:", installed);
if (!installed) {
toast({
title: "Atuin CLI",
description: "CLI not detected - install?",
action: (
{
let install = async () => {
toast({
title: "Atuin CLI",
description: "Install in progress...",
});
console.log("Installing CLI...");
await invoke("install_cli");
console.log("Setting up plugin...");
await invoke("setup_cli");
toast({
title: "Atuin CLI",
description: "Installation complete",
});
};
install();
}}
>
Install
),
});
}
};
setup();
}, []);
if (!homeInfo) {
return Loading...
;
}
return (
Activity graph
React.cloneElement(block, {
"data-tooltip-id": "react-tooltip",
"data-tooltip-html": `${activity.count} commands on ${activity.date}`,
})
}
/>
Quick actions
}
>
New runbook
}
>
Shell History
Recent commands
{homeInfo.recentCommands?.map((i: ShellHistory) => {
return ;
})}
Top commands
);
}