-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathindex.tsx
More file actions
95 lines (82 loc) · 2.66 KB
/
Copy pathindex.tsx
File metadata and controls
95 lines (82 loc) · 2.66 KB
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
import { useEffect, useState } from 'react';
import { Popover } from 'antd';
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
import { MouseIcon } from 'lucide-react';
import { menuConfigAtom } from '@/jotai/device';
import {
mouseJigglerModeAtom,
mouseModeAtom,
mouseStyleAtom,
scrollDirectionAtom,
scrollIntervalAtom
} from '@/jotai/mouse.ts';
import type { MouseSubItemId } from '@/libs/menu-config';
import { mouseJiggler } from '@/libs/mouse-jiggler';
import * as storage from '@/libs/storage';
import { Direction } from './direction.tsx';
import { Jiggler } from './jiggler.tsx';
import { Mode } from './mode.tsx';
import { Speed } from './speed.tsx';
import { Style } from './style.tsx';
const MOUSE_SUB_COMPONENTS: Record<MouseSubItemId, React.FC> = {
'mouse.style': Style,
'mouse.mode': Mode,
'mouse.direction': Direction,
'mouse.speed': Speed,
'mouse.jiggler': Jiggler,
};
export const Mouse = () => {
const menuConfig = useAtomValue(menuConfigAtom);
const [mouseStyle, setMouseStyle] = useAtom(mouseStyleAtom);
const [mouseMode, setMouseMode] = useAtom(mouseModeAtom);
const setScrollDirection = useSetAtom(scrollDirectionAtom);
const setScrollInterval = useSetAtom(scrollIntervalAtom);
const setMouseJigglerMode = useSetAtom(mouseJigglerModeAtom);
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
useEffect(() => {
initMouse();
}, []);
function initMouse() {
const style = storage.getMouseStyle();
if (style && style !== mouseStyle) {
setMouseStyle(style);
}
const mode = storage.getMouseMode();
if (mode && mode !== mouseMode) {
setMouseMode(mode);
}
const direction = storage.getMouseScrollDirection();
if (direction) {
setScrollDirection(direction > 0 ? 1 : -1);
}
const interval = storage.getMouseScrollInterval();
if (interval) {
setScrollInterval(interval);
}
const jiggler = storage.getMouseJigglerMode();
mouseJiggler.setMode(jiggler);
setMouseJigglerMode(jiggler);
}
const content = (
<div className="flex flex-col space-y-0.5">
{menuConfig.subMenus.mouse.map((itemId) => {
const Component = MOUSE_SUB_COMPONENTS[itemId];
return Component ? <Component key={itemId} /> : null;
})}
</div>
);
return (
<Popover
content={content}
placement="bottomLeft"
trigger="click"
arrow={false}
open={isPopoverOpen}
onOpenChange={setIsPopoverOpen}
>
<div className="flex h-[28px] w-[28px] cursor-pointer items-center justify-center rounded text-neutral-300 hover:bg-neutral-700/70 hover:text-white">
<MouseIcon size={18} />
</div>
</Popover>
);
};