Skip to content

Commit

Permalink
feat(calendar): add missing selected value to habits select (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
domhhv authored Dec 27, 2024
1 parent 2bada25 commit 030b6fa
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/components/calendar/AddOccurrenceDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Select,
SelectItem,
SelectSection,
type Selection,
} from '@nextui-org/react';
import { ArrowsClockwise } from '@phosphor-icons/react';
import { useHabitsStore, useNotesStore, useOccurrencesStore } from '@stores';
Expand All @@ -33,7 +34,9 @@ const AddOccurrenceDialog = ({
const { habits } = useHabitsStore();
const user = useUser();
const { addOccurrence, addingOccurrence } = useOccurrencesStore();
const [selectedHabitId, setSelectedHabitId] = React.useState('');
const [selectedHabitId, setSelectedHabitId] = React.useState<Selection>(
new Set<number>([])
);
const [note, setNote] = React.useState('');
const { addNote, addingNote } = useNotesStore();

Expand Down Expand Up @@ -74,15 +77,11 @@ const AddOccurrenceDialog = ({
};

const handleClose = () => {
setSelectedHabitId('');
setSelectedHabitId(new Set([]));
setNote('');
onClose();
};

const handleHabitSelect = (habitId: string) => {
setSelectedHabitId(habitId);
};

return (
<Modal
role="add-occurrence-modal"
Expand All @@ -99,6 +98,7 @@ const AddOccurrenceDialog = ({
disableSelectorIconRotation
variant="faded"
selectedKeys={selectedHabitId}
onSelectionChange={setSelectedHabitId}
label={
hasHabits
? 'Habits'
Expand All @@ -115,11 +115,7 @@ const AddOccurrenceDialog = ({
const iconUrl = getHabitIconUrl(habit.iconPath);

return (
<SelectItem
key={habit.id.toString()}
textValue={habit.name}
onClick={() => handleHabitSelect(habit.id.toString())}
>
<SelectItem key={habit.id} textValue={habit.name}>
<div className="flex items-center gap-2">
<img
src={iconUrl}
Expand Down

0 comments on commit 030b6fa

Please sign in to comment.