Skip to content

Commit

Permalink
chore(ui): components cleanup
Browse files Browse the repository at this point in the history
- Remove redundant state in navigator.
- Remove unused home component.
  • Loading branch information
skjsjhb committed Jan 23, 2025
1 parent 24b251e commit f90c42d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 42 deletions.
4 changes: 1 addition & 3 deletions src/renderer/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import React, { type FC } from "react";
export const Header: FC = () => {
return <div className="drag shrink-0 grow-0 basis-20">
<div className="flex gap-2 h-full justify-center items-center px-8">
<div className="no-drag">
<TopNavigator/>
</div>
<TopNavigator/>

<CloseButton/>
<MinimizeButton/>
Expand Down
46 changes: 19 additions & 27 deletions src/renderer/components/TopNavigator.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,17 @@
import { Tab, Tabs } from "@heroui/react";
import { type PageInfo, pages } from "@pages/pages";
import React, { type FC, useEffect, useState } from "react";
import { pages } from "@pages/pages";
import React, { type FC } from "react";
import { useTranslation } from "react-i18next";
import { useLocation } from "wouter";

/**
* Sidebar for page selecting.
*/
export const TopNavigator: FC = () => {
const [selected, setSelected] = useState(pages[0].id || "");
const [pathname, navigate] = useLocation();
const { t } = useTranslation("pages");

useEffect(() => {
const sel = pages.find(p => pathname.startsWith(p.href))?.id;
if (sel) setSelected(sel);
}, [pathname]);

/**
* Creates page tab button based on page info.
* This cannot be extracted as a separated component or NextUI will complain.
*/
function createPageTab(info: PageInfo) {
const { icon, title, id } = info;
return <Tab
title={
<div className="flex items-center gap-2">
{React.createElement(icon)}
{t(title)}
</div>
}

key={id}
/>;
}
const currentTabId = pages.find(p => pathname.startsWith(p.href))?.id ?? pages[0].id;

// A workaround for https://github.com/heroui-inc/heroui/issues/4598
function changePage(id: string | number) {
Expand All @@ -45,11 +23,25 @@ export const TopNavigator: FC = () => {

return <div className="flex flex-col w-full h-full items-center justify-center">
<Tabs
className="no-drag"
color="primary"
selectedKey={selected}
selectedKey={currentTabId}
onSelectionChange={changePage}
>
{pages.map(page => createPageTab(page))}
{
pages.map(({ icon, title, id }) =>
<Tab
title={
<div className="flex items-center gap-2">
{React.createElement(icon)}
{t(title)}
</div>
}

key={id}
/>
)
}
</Tabs>
</div>;
};
12 changes: 0 additions & 12 deletions src/renderer/pages/Home.tsx

This file was deleted.

0 comments on commit f90c42d

Please sign in to comment.