From cb19925011d889c513e1bbedc446e399597e38a0 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Wed, 17 Apr 2024 14:06:05 +0100 Subject: feat(gui): work on home page, sort state (#1956) 1. Start on a home page, can sort onboarding/etc from there 2. Introduce zustand for state management. It's nice! Did a production build and clicked around for a while. Memory usage seems nice and chill. --- ui/src/pages/Dotfiles.tsx | 7 ---- ui/src/pages/History.tsx | 45 +++++-------------------- ui/src/pages/Home.tsx | 84 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 44 deletions(-) create mode 100644 ui/src/pages/Home.tsx (limited to 'ui/src/pages') diff --git a/ui/src/pages/Dotfiles.tsx b/ui/src/pages/Dotfiles.tsx index bd209062..6b0870b3 100644 --- a/ui/src/pages/Dotfiles.tsx +++ b/ui/src/pages/Dotfiles.tsx @@ -1,12 +1,5 @@ -import { useState } from "react"; - -import { Cog6ToothIcon } from "@heroicons/react/24/outline"; - import Aliases from "@/components/dotfiles/Aliases"; -import { Drawer } from "@/components/drawer"; -import { invoke } from "@tauri-apps/api/core"; - function Header() { return (
diff --git a/ui/src/pages/History.tsx b/ui/src/pages/History.tsx index f74c16ac..91ed9824 100644 --- a/ui/src/pages/History.tsx +++ b/ui/src/pages/History.tsx @@ -1,40 +1,10 @@ -import { Fragment, useState, useEffect } from "react"; -import { Dialog, Transition } from "@headlessui/react"; -import { - Bars3Icon, - ChartPieIcon, - Cog6ToothIcon, - HomeIcon, - XMarkIcon, -} from "@heroicons/react/24/outline"; - -import Logo from "../assets/logo-light.svg"; - -import { invoke } from "@tauri-apps/api/core"; +import { useEffect } from "react"; import HistoryList from "@/components/HistoryList.tsx"; import HistorySearch from "@/components/HistorySearch.tsx"; import Stats from "@/components/history/Stats.tsx"; import Drawer from "@/components/Drawer.tsx"; - -function refreshHistory( - setHistory: React.Dispatch>, - query: String | null, -) { - if (query) { - invoke("search", { query: query }) - .then((res: any[]) => { - setHistory(res); - }) - .catch((e) => { - console.log(e); - }); - } else { - invoke("list").then((h: any[]) => { - setHistory(h); - }); - } -} +import { useStore } from "@/state/store"; function Header() { return ( @@ -44,7 +14,7 @@ function Header() { Shell History
-
+
state.shellHistory); + const refreshHistory = useStore((state) => state.refreshShellHistory); useEffect(() => { - refreshHistory(setHistory, null); + refreshHistory(); }, []); return ( @@ -93,8 +64,8 @@ export default function Search() {
{ - refreshHistory(setHistory, query); + refresh={(query?: string) => { + refreshHistory(query); }} />
diff --git a/ui/src/pages/Home.tsx b/ui/src/pages/Home.tsx new file mode 100644 index 00000000..c0f8fbc5 --- /dev/null +++ b/ui/src/pages/Home.tsx @@ -0,0 +1,84 @@ +import { useEffect } from "react"; +import { formatRelative } from "date-fns"; + +import { useStore } from "@/state/store"; + +function Stats({ stats }: any) { + return ( +
+
+ {stats.map((item: any) => ( +
+
+ {item.name} +
+
+ {item.stat} +
+
+ ))} +
+
+ ); +} + +function Header({ name }: any) { + let greeting = name && name.length > 0 ? "Hey, " + name + "!" : "Hey!"; + + return ( +
+
+

+ {greeting} +

+

+ Welcome to Atuin. +

+
+
+ ); +} + +export default function Home() { + const homeInfo = useStore((state) => state.homeInfo); + const refreshHomeInfo = useStore((state) => state.refreshHomeInfo); + + useEffect(() => { + refreshHomeInfo(); + }, []); + + if (!homeInfo) { + return
Loading...
; + } + + return ( +
+
+
+ +
+

Sync

+ +
+
+
+ ); +} -- cgit v1.3.1