feat: add active indicators

This commit is contained in:
MAZE 2024-02-25 21:42:40 +03:30
parent 665e2173f4
commit 240fd9c6e0
7 changed files with 55 additions and 5 deletions

View File

@ -33,4 +33,11 @@
& .icon {
color: var(--color-foreground);
}
& .active {
width: 4px;
height: 4px;
background: var(--color-neutral-950);
border-radius: 50%;
}
}

View File

@ -1,6 +1,7 @@
import styles from './item.module.css';
interface ItemProps {
active?: boolean;
disabled?: boolean;
href?: string;
icon: React.ReactElement;
@ -9,6 +10,7 @@ interface ItemProps {
}
export function Item({
active,
disabled = false,
href,
icon,
@ -25,6 +27,7 @@ export function Item({
{...(href ? { href, target: '_blank' } : {})}
>
<span className={styles.icon}>{icon}</span> {label}
{active && <div className={styles.active} />}
</Comp>
);
}

View File

@ -2,10 +2,21 @@ import { MdNotes } from 'react-icons/md/index';
import { Item } from '../item';
import { useNoteStore } from '@/store';
interface NotepadProps {
open: () => void;
}
export function Notepad({ open }: NotepadProps) {
return <Item icon={<MdNotes />} label="Notepad" onClick={open} />;
const note = useNoteStore(state => state.note);
return (
<Item
active={!!note.length}
icon={<MdNotes />}
label="Notepad"
onClick={open}
/>
);
}

View File

@ -2,10 +2,21 @@ import { MdOutlineAvTimer } from 'react-icons/md/index';
import { Item } from '../item';
import { usePomodoroStore } from '@/store';
interface PomodoroProps {
open: () => void;
}
export function Pomodoro({ open }: PomodoroProps) {
return <Item icon={<MdOutlineAvTimer />} label="Pomodoro" onClick={open} />;
const running = usePomodoroStore(state => state.running);
return (
<Item
active={running}
icon={<MdOutlineAvTimer />}
label="Pomodoro"
onClick={open}
/>
);
}

View File

@ -9,6 +9,7 @@ import { Button } from './button';
import { Setting } from './setting';
import { useLocalStorage } from '@/hooks/use-local-storage';
import { usePomodoroStore } from '@/store';
import styles from './pomodoro.module.css';
@ -21,7 +22,10 @@ export function Pomodoro({ onClose, show }: PomodoroProps) {
const [showSetting, setShowSetting] = useState(false);
const [selectedTab, setSelectedTab] = useState('pomodoro');
const [running, setRunning] = useState(false);
const running = usePomodoroStore(state => state.running);
const setRunning = usePomodoroStore(state => state.setRunning);
const [timer, setTimer] = useState(0);
const interval = useRef<ReturnType<typeof setInterval> | null>(null);
@ -76,7 +80,7 @@ export function Pomodoro({ onClose, show }: PomodoroProps) {
[selectedTab]: prev[selectedTab] + 1,
}));
}
}, [timer, selectedTab, running]);
}, [timer, selectedTab, running, setRunning]);
useEffect(() => {
const time = times[selectedTab] || 10;
@ -85,7 +89,7 @@ export function Pomodoro({ onClose, show }: PomodoroProps) {
setRunning(false);
setTimer(time);
}, [selectedTab, times]);
}, [selectedTab, times, setRunning]);
const toggleRunning = () => {
if (running) setRunning(false);

View File

@ -1,3 +1,4 @@
export { useSoundStore } from './sound';
export { useLoadingStore } from './loading';
export { useNoteStore } from './note';
export { usePomodoroStore } from './pomodoro';

View File

@ -0,0 +1,13 @@
import { create } from 'zustand';
interface PomodoroStore {
running: boolean;
setRunning: (value: boolean) => void;
}
export const usePomodoroStore = create<PomodoroStore>()(set => ({
running: false,
setRunning(value: boolean) {
set({ running: value });
},
}));