Skip to content

Commit 788deb5

Browse files
committed
feat: support favorite
1 parent 8e03d91 commit 788deb5

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

src/components/PageTabs.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { favoriteAtom } from '@/stores/app';
12
import CloseIcon from '@mui/icons-material/Close';
23
import { TabContext, TabList, TabPanelProps, useTabContext } from '@mui/lab';
34
import { Box, IconButton, Tab, TabProps, styled } from '@mui/material';
45
import { writeText } from '@tauri-apps/plugin-clipboard-manager';
6+
import { useSetAtom } from 'jotai';
57
import {
68
FunctionComponent,
79
PropsWithChildren,
@@ -102,6 +104,7 @@ export function PageTabs({
102104
onRemove,
103105
onRemoveOther,
104106
}: PageTabsProps) {
107+
const setFavorite = useSetAtom(favoriteAtom);
105108
const tabList = useMemo(() => {
106109
return (
107110
<PageTabList
@@ -155,6 +158,16 @@ export function PageTabs({
155158

156159
<ContextMenuSeparator />
157160

161+
<ContextMenuItem
162+
onClick={async () => {
163+
setFavorite((prev) => [...prev, tab]);
164+
}}
165+
>
166+
Favorite
167+
</ContextMenuItem>
168+
169+
<ContextMenuSeparator />
170+
158171
<ContextMenuItem
159172
onClick={async () => {
160173
await writeText(tab.displayName);

src/components/TreeItem.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ export const TreeItemLabel = React.forwardRef(
231231
className="flex items-center p-0 pt-0.5 pb-0.5 text-sm h-6"
232232
ref={ref as React.Ref<HTMLDivElement>}
233233
>
234-
<div className="mr-1 flex items-center h-full [&_svg]:text-base [&_svg]:h-4 [&_svg]:w-4">
234+
<div className="mr-1 flex items-center h-full [&_svg]:text-base [&_svg]:size-4">
235235
{getTypeIcon(icon, expanded)}
236236
</div>
237237
<div className="overflow-hidden text-ellipsis font-mono">

src/pages/sidebar/Favorite.tsx

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
import { favoriteAtom } from '@/stores/app';
2+
import { useAtomValue } from 'jotai';
3+
import { Code2Icon, SearchIcon, TableIcon } from 'lucide-react';
4+
15
export function Favorite() {
6+
const items = useAtomValue(favoriteAtom);
7+
8+
console.log(items);
29
return (
310
<div className="grid min-h-screen w-full">
411
<div className="hidden border-r bg-muted/40 md:block">
@@ -9,7 +16,28 @@ export function Favorite() {
916
</a>
1017
</div>
1118
<div className="flex-1">
12-
<nav className="grid items-start px-1 text-sm font-medium"></nav>
19+
<nav className="grid items-start px-1 text-sm">
20+
{items.map((item, i) => {
21+
const Comp =
22+
item.type == 'search'
23+
? SearchIcon
24+
: item.type == 'editor'
25+
? Code2Icon
26+
: TableIcon;
27+
return (
28+
<a
29+
key={i}
30+
href="#"
31+
className="flex items-center rounded-lg px-2 py-1 text-muted-foreground transition-all hover:text-primary overflow-hidden"
32+
>
33+
<Comp className="size-4 min-w-4 mr-1" />
34+
<div className="overflow-hidden text-ellipsis font-mono font-normal whitespace-nowrap">
35+
{item.displayName}
36+
</div>
37+
</a>
38+
);
39+
})}
40+
</nav>
1341
</div>
1442
</div>
1543
</div>

src/stores/app.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import { TabContextType } from '@/stores/tabs';
2+
3+
import { createSelectors } from '@/stores/utils';
14
import { focusAtom } from 'jotai-optics';
25
import { atomWithStore } from 'jotai-zustand';
6+
import { atomWithStorage } from 'jotai/utils';
7+
import { debounce } from 'radash';
38
import { create } from 'zustand';
49
import { persist } from 'zustand/middleware';
510

6-
import { createSelectors } from '@/stores/utils';
7-
import { debounce } from 'radash';
8-
911
type AppState = {
1012
size: number;
1113
};
@@ -33,3 +35,5 @@ const useAppStore = createSelectors(store);
3335
export const appAtom = atomWithStore(useAppStore);
3436

3537
export const sizeAtom = focusAtom(appAtom, (optic) => optic.prop('size'));
38+
39+
export const favoriteAtom = atomWithStorage<TabContextType[]>('favorite', []);

0 commit comments

Comments
 (0)