From 581b2ebddd9a54634b839c90eadb51260d793dd5 Mon Sep 17 00:00:00 2001 From: Dominik Hryshaiev Date: Sat, 28 Dec 2024 18:25:25 +0200 Subject: [PATCH] feat(calendar): add viewing of occurrence times (#140) * feat(calendar): add viewing of occurrence times * style: remove comments --- src/components/calendar/OccurrenceChip.tsx | 97 +++++++------------ .../habit/habits-page/HabitsPage.tsx | 4 +- src/components/user-account/AccountPage.tsx | 2 +- src/index.css | 11 +++ supabase/database.types.ts | 6 +- ...241228160154_non_nullable_note_content.sql | 1 + tailwind.config.js | 3 - 7 files changed, 54 insertions(+), 70 deletions(-) create mode 100644 supabase/migrations/20241228160154_non_nullable_note_content.sql diff --git a/src/components/calendar/OccurrenceChip.tsx b/src/components/calendar/OccurrenceChip.tsx index 0592e3f..87a2fd5 100644 --- a/src/components/calendar/OccurrenceChip.tsx +++ b/src/components/calendar/OccurrenceChip.tsx @@ -1,15 +1,9 @@ import type { Occurrence } from '@models'; -import { - Badge, - Button, - Popover, - PopoverContent, - PopoverTrigger, - Tooltip, -} from '@nextui-org/react'; -import { Note, Trash } from '@phosphor-icons/react'; +import { Badge, Button, Tooltip } from '@nextui-org/react'; +import { Trash } from '@phosphor-icons/react'; import { useNotesStore } from '@stores'; import { getHabitIconUrl } from '@utils'; +import { format } from 'date-fns'; import React from 'react'; export type OccurrenceChipProps = { @@ -26,57 +20,51 @@ const OccurrenceChip = ({ onDelete, colorOverride, }: OccurrenceChipProps) => { + const occurrenceIds = occurrences.map((o) => o.id); const [occurrence] = occurrences; const { habit } = occurrence; const { notes } = useNotesStore(); const { name: habitName, iconPath, trait } = habit || {}; const { color: traitColor } = trait || {}; const iconUrl = getHabitIconUrl(iconPath); - const occurrenceNote = notes.find( - (note) => note.occurrenceId === occurrences[0].id + const occurrenceTimes = occurrences.map((o) => ({ + occurrenceId: o.id, + time: format(new Date(o.timestamp), 'p'), + })); + const occurrenceNotes = notes.filter( + (n) => n.occurrenceId && occurrenceIds.includes(n.occurrenceId) ); - const [isOccurrenceTooltipOpen, setIsOccurrenceTooltipOpen] = - React.useState(false); - const [isNotePopoverOpen, setIsNotePopoverOpen] = React.useState(false); const chipStyle = { borderColor: colorOverride || traitColor, }; const tooltipContent = ( -
- {habitName} - {occurrenceNote && ( - setIsNotePopoverOpen(open)} +
+
+ {habitName} + - - -

{occurrenceNote.content}

-
- - )} - + + +
+
    + {occurrenceTimes.map((t) => ( +
  • + {t.time}:{' '} + + {occurrenceNotes.find((n) => n.occurrenceId === t.occurrenceId) + ?.content || 'No note'} + +
  • + ))} +
); @@ -84,19 +72,14 @@ const OccurrenceChip = ({ const chip = (
{`${habitName} - {occurrenceNote && ( -
- -
- )}
); @@ -119,14 +102,6 @@ const OccurrenceChip = ({ return ( { - if (isNotePopoverOpen && !open) { - return; - } - - setIsOccurrenceTooltipOpen(open); - }} isDisabled={!habitName} content={tooltipContent} radius="sm" diff --git a/src/components/habit/habits-page/HabitsPage.tsx b/src/components/habit/habits-page/HabitsPage.tsx index 42403d1..471c694 100644 --- a/src/components/habit/habits-page/HabitsPage.tsx +++ b/src/components/habit/habits-page/HabitsPage.tsx @@ -99,7 +99,7 @@ const HabitsPage = () => { return (
-

+

Your habits

@@ -127,7 +127,7 @@ const HabitsPage = () => { -
+
{ return (
-

Your Account Info

+

Your Account Info