Skip to content

Commit

Permalink
Merge pull request #66 from tonymtz/next
Browse files Browse the repository at this point in the history
Tomatoro: Next updates
  • Loading branch information
tonymtz authored Jul 4, 2023
2 parents 9e412b5 + 2182896 commit cca9da4
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 74 deletions.
5 changes: 0 additions & 5 deletions components/organisms/timer/timer.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Flex, Text } from 'theme-ui'
import { useTimerContext } from '~/contexts/timer'
import { useTimerStore } from '~/stores/time'
import { formatTime } from '~/utils/timer.utils'
import { track } from '~/utils/tracking.utils'

import { Button, Controls, Donut } from './timer.styles'

Expand All @@ -17,19 +16,15 @@ export const Timer: FC = () => {
const onToggleClick = () => {
if (!isStarted) {
onStartTimer()
track('$start')
} else if (isRunning) {
onStopTimer()
track('$pause')
} else {
onStartTimer()
track('$start')
}
}

const onStopClick = () => {
onResetTimer()
track('$done', { time: formatTime(time) })
}

return (
Expand Down
22 changes: 13 additions & 9 deletions contexts/timer/timer-context.provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useNotificationsContext } from '~/contexts/notifications'
import { useSettingsStore } from '~/stores/settings'
import { useTimerStore } from '~/stores/time'
import { NOTIFICATION } from '~/utils/config'
import { track } from '~/utils/tracking.utils'

export const TimerContext = React.createContext<{
onStartTimer(): void;
Expand Down Expand Up @@ -43,38 +44,41 @@ export const TimerProvider: React.FC<{ children: ReactNode }> = ({ children }) =
}
start()
workerRef.current?.postMessage('start')
}, [reset, start, time])
track('$timer_start', { segment: currentSegment, time })
}, [currentSegment, reset, start, time])

const onStopTimer = useCallback(() => {
stop()
workerRef.current?.postMessage('stop')
}, [stop])
track('$timer_stop', { segment: currentSegment, time })
}, [currentSegment, stop, time])

const onResetTimer = useCallback(() => {
reset()
workerRef.current?.postMessage('stop')
}, [reset])
track('$timer_reset', { segment: currentSegment, time })
}, [currentSegment, reset, time])

useEffect(() => {
if (time < 1) {
onStopTimer()
notify(NOTIFICATION)
track('$timer_end', { segment: currentSegment, time })
}
}, [notify, onStopTimer, time])
}, [currentSegment, notify, onStopTimer, time])

const onSegmentChange = useCallback((totalTime: number) => {
setTotalTime(totalTime)
onResetTimer()
}, [onResetTimer, setTotalTime])
track('$segment_change', { segment: currentSegment, time })
}, [currentSegment, onResetTimer, setTotalTime, time])

useEffect(() => {
if (currentSegment === 'WORK') {
onSegmentChange(workLength)
}
if (currentSegment === 'SHORT') {
} else if (currentSegment === 'SHORT') {
onSegmentChange(shortLength)
}
if (currentSegment === 'LONG') {
} else if (currentSegment === 'LONG') {
onSegmentChange(longLength)
}
}, [currentSegment, longLength, onSegmentChange, shortLength, workLength])
Expand Down
108 changes: 54 additions & 54 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tomatoro",
"version": "3.0.152",
"version": "3.0.154",
"private": true,
"scripts": {
"dev": "next dev",
Expand All @@ -21,9 +21,9 @@
"axios": "1.4.0",
"date-fns": "2.30.0",
"eslint": "8.44.0",
"eslint-config-next": "13.4.7",
"eslint-config-next": "13.4.8",
"framer-motion": "10.12.18",
"next": "13.4.7",
"next": "13.4.8",
"next-translate": "~2.4.4",
"next-translate-plugin": "~2.4.4",
"posthog-js": "1.68.5",
Expand Down
8 changes: 5 additions & 3 deletions utils/tracking.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ type TrackingEvent =
| 'legacy_worker_uninstalled'
| '$pageview'
| '$language_changed'
| '$start'
| '$pause'
| '$done'
| '$timer_start'
| '$timer_stop'
| '$timer_reset'
| '$timer_end'
| '$segment_change'
| '$settings_opened'
| '$settings_closed'
| '$settings_changed'
Expand Down

0 comments on commit cca9da4

Please sign in to comment.