Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/components/ui/tooltip/clickable-tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface ClickableTooltipProps {
triggerRef: RefObject<HTMLElement | null>
isOpen: boolean
setIsOpen: (isOpen: boolean) => void
toggleOnTriggerClick?: boolean
}

const ClickableTooltip = ({
Expand All @@ -37,6 +38,7 @@ const ClickableTooltip = ({
triggerRef,
isOpen,
setIsOpen,
toggleOnTriggerClick = true,
}: ClickableTooltipProps) => {
const [calculatedPosition, setCalculatedPosition] = useState<Position>(position)
const [tooltipCoords, setTooltipCoords] = useState({ x: 0, y: 0 })
Expand Down Expand Up @@ -151,7 +153,7 @@ const ClickableTooltip = ({
}, [isOpen, closeOnClickOutside])

useEffect(() => {
if (!triggerRef?.current) return
if (!toggleOnTriggerClick || !triggerRef?.current) return

const handleClick = (e: Event) => {
e.preventDefault()
Expand All @@ -165,7 +167,7 @@ const ClickableTooltip = ({
return () => {
element.removeEventListener('click', handleClick, true)
}
}, [triggerRef, isOpen])
}, [triggerRef, isOpen, toggleOnTriggerClick])

const variants = {
top: {
Expand Down
66 changes: 38 additions & 28 deletions src/context/date.context.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type React from 'react'
import { createContext, useContext, useEffect, useState } from 'react'
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react'
import {
convertShamsiToHijri,
getCurrentDate,
Expand Down Expand Up @@ -44,44 +44,54 @@ export const DateProvider: React.FC<{ children: React.ReactNode }> = ({ children
setSelectedDate(newToday.clone())
}, [timezone])

const goToToday = () => {
const goToToday = useCallback(() => {
const newToday = getCurrentDate(timezone.value)
setCurrentDate(newToday.clone())
setSelectedDate(newToday.clone())
}
}, [timezone])

const isToday = (date: WidgetifyDate): boolean => {
return (
date.jDate() === today.jDate() &&
date.jMonth() === today.jMonth() &&
date.jYear() === today.jYear()
)
}
const isToday = useCallback(
(date: WidgetifyDate): boolean => {
return (
date.jDate() === today.jDate() &&
date.jMonth() === today.jMonth() &&
date.jYear() === today.jYear()
)
},
[today]
)

const getHijriDate = (date: WidgetifyDate): string => {
const getHijriDate = useCallback((date: WidgetifyDate): string => {
const hijriDate = convertShamsiToHijri(date)
return `${hijriDate.iYear()}/${hijriDate.iMonth() + 1}/${hijriDate.iDate()}`
}
}, [])

const todayIsHoliday = activeDate.day() === 5

return (
<DateContext.Provider
value={{
currentDate,
selectedDate,
todayIsHoliday,
today,
setCurrentDate,
setSelectedDate,
goToToday,
isToday,
getHijriDate,
}}
>
{children}
</DateContext.Provider>
const value = useMemo(
() => ({
currentDate,
selectedDate,
todayIsHoliday,
today,
setCurrentDate,
setSelectedDate,
goToToday,
isToday,
getHijriDate,
}),
[
currentDate,
selectedDate,
todayIsHoliday,
today,
goToToday,
isToday,
getHijriDate,
]
)

return <DateContext.Provider value={value}>{children}</DateContext.Provider>
}

export const useDate = (): DateContextType => {
Expand Down
8 changes: 6 additions & 2 deletions src/context/widget-visibility.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import {
import Analytics from '@/analytics'
import { getFromStorage, setToStorage } from '@/common/storage'
import { showToast } from '@/common/toast'
import CalendarLayout from '@/layouts/widgets/calendar/calendar'
import { ComboWidget } from '@/layouts/widgets/combo-widget/combo-widget.layout'
import { HabitsLayout } from '@/layouts/widgets/habit/habits.layout'
import { WidgetKeys as RegistryWidgetKeys } from '@/layouts/widgets/layout-engine/types'
import { NetworkLayout } from '@/layouts/widgets/network/network.layout'
import { NewsLayout } from '@/layouts/widgets/news/news.layout'
import { ToolsLayout } from '@/layouts/widgets/tools/tools.layout'
import { WeatherLayout } from '@/layouts/widgets/weather/weather.layout'
import { WIDGET_DEFINITIONS } from '@/layouts/widgets/widget-registry'
import { WigiArzLayout } from '@/layouts/widgets/wigi-arz/wigi_arz.layout'
import { YadkarWidget } from '@/layouts/widgets/yadkar/yadkar'
import {
Expand Down Expand Up @@ -67,7 +68,10 @@ export const widgetItems: WidgetItem[] = [
emoji: '📅',
label: 'تقویم',
order: 0,
node: <CalendarLayout size={{ w: 2, h: 3 }} />,
node: WIDGET_DEFINITIONS[RegistryWidgetKeys.calendar].node('calendar', {
w: 2,
h: 3,
}),
canToggle: true,
popular: true,
},
Expand Down
7 changes: 5 additions & 2 deletions src/layouts/widgets/calendar/components/calendar-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useAuth } from '@/context/auth.context'
import { useGeneralSetting } from '@/context/general-setting.context'
import { useGetEvents } from '@/services/hooks/date/get-events.hook'
import type React from 'react'
import { useState } from 'react'
import { useMemo, useState } from 'react'
import { type WidgetifyDate, formatDateStr } from '../utils'
import { DayItem } from './day/day'
import { ClickableTooltip } from '@/components/ui'
Expand Down Expand Up @@ -53,6 +53,7 @@ export const CalendarGrid: React.FC<CalendarGridProps> = ({
const nextMonthDays = totalCells - daysInMonth - emptyDays

const selectedDateStr = formatDateStr(selectedDate)
const triggerRef = useMemo(() => ({ current: clickedElement }), [clickedElement])

return (
<>
Expand Down Expand Up @@ -109,9 +110,11 @@ export const CalendarGrid: React.FC<CalendarGridProps> = ({

{clickedElement && (
<ClickableTooltip
triggerRef={{ current: clickedElement }}
triggerRef={triggerRef}
toggleOnTriggerClick={false}
content={
<CalendarDayDetails
selectedDate={selectedDate}
events={eventsForCalendar}
moods={calendarData?.moods ?? []}
onMoodChange={() => refetch()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getHijriEvents,
getShamsiEvents,
hijriMonthNames,
type WidgetifyDate,
} from '../../utils'
import { useDate } from '@/context/date.context'
import type React from 'react'
Expand All @@ -23,18 +24,20 @@ import { moodOptions } from '@/common/constant/moods'
import { Icon } from '@/src/icons'

interface CalendarDayDetailsProps {
selectedDate: WidgetifyDate
events: FetchedAllEvents
eventIcon?: string
moods: MoodEntry[]
onMoodChange?: (mood: MoodType) => void
}

export const CalendarDayDetails: React.FC<CalendarDayDetailsProps> = ({
selectedDate,
events,
moods,
onMoodChange,
}) => {
const { selectedDate, today, getHijriDate } = useDate()
const { today, getHijriDate } = useDate()
const { isAuthenticated } = useAuth()
const { mutateAsync: upsertMoodLog } = useUpsertMoodLog()

Expand Down
Loading