1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
import React, { useEffect } from "react";
import { formatRelative } from "date-fns";
import { Tooltip as ReactTooltip } from "react-tooltip";
import { 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 ActivityCalendar from "react-activity-calendar";
function Stats({ stats }: any) {
return (
<div>
<dl className="mt-5 grid grid-cols-1 gap-5 sm:grid-cols-3">
{stats.map((item: any) => (
<div
key={item.name}
className="overflow-hidden rounded-lg bg-white px-4 py-5 shadow sm:p-6"
>
<dt className="truncate text-sm font-medium text-gray-500">
{item.name}
</dt>
<dd className="mt-1 text-xl font-semibold tracking-tight text-gray-900">
{item.stat}
</dd>
</div>
))}
</dl>
</div>
);
}
function Header({ name }: any) {
let greeting = name && name.length > 0 ? "Hey, " + name + "!" : "Hey!";
return (
<div className="md:flex md:items-center md:justify-between">
<div className="min-w-0 flex-1">
<h2 className="text-2xl font-bold leading-7 text-gray-900 sm:truncate sm:text-3xl sm:tracking-tight">
{greeting}
</h2>
<h3 className="text-xl leading-7 text-gray-900 pt-4">
Welcome to{" "}
<a
href="https://atuin.sh"
target="_blank"
rel="noopener noreferrer nofollow"
>
Atuin
</a>
.
</h3>
</div>
</div>
);
}
const explicitTheme = {
light: ["#f0f0f0", "#c4edde", "#7ac7c4", "#f73859", "#384259"],
dark: ["#f0f0f0", "#c4edde", "#7ac7c4", "#f73859", "#384259"],
};
export default function Home() {
const homeInfo = useStore((state) => state.homeInfo);
const user = useStore((state) => state.user);
const calendar = useStore((state) => state.calendar);
const weekStart = useStore((state) => state.weekStart);
const refreshHomeInfo = useStore((state) => state.refreshHomeInfo);
const refreshUser = useStore((state) => state.refreshUser);
const refreshCalendar = useStore((state) => state.refreshCalendar);
const { toast } = useToast();
useEffect(() => {
refreshHomeInfo();
refreshUser();
refreshCalendar();
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: (
<ToastAction
altText="Install"
onClick={() => {
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
</ToastAction>
),
});
}
};
setup();
}, []);
if (!homeInfo) {
return <div>Loading...</div>;
}
return (
<div className="pl-60">
<div className="p-10">
<Header name={user.username} />
<div className="pt-10">
<Stats
stats={[
{
name: "Last Sync",
stat:
(homeInfo.lastSyncTime &&
formatRelative(homeInfo.lastSyncTime, new Date())) ||
"Never",
},
{
name: "Total history records",
stat: homeInfo.historyCount.toLocaleString(),
},
{
name: "Other records",
stat: homeInfo.recordCount - homeInfo.historyCount,
},
]}
/>
</div>
<div className="pt-10 flex justify-around">
<ActivityCalendar
theme={explicitTheme}
data={calendar}
weekStart={weekStart as any}
renderBlock={(block, activity) =>
React.cloneElement(block, {
"data-tooltip-id": "react-tooltip",
"data-tooltip-html": `${activity.count} commands on ${activity.date}`,
})
}
labels={{
totalCount: "{{count}} history records in the last year",
}}
/>
<ReactTooltip id="react-tooltip" />
</div>
</div>
</div>
);
}
|