-
-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wip: poc for playing a sound on time end #1245
base: master
Are you sure you want to change the base?
Conversation
Warning Rate limit exceeded@cpvalente has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 56 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThis pull request introduces a new custom hook, Changes
Possibly related PRs
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Outside diff range and nitpick comments (4)
apps/client/src/common/hooks/useSocket.ts (2)
179-185
: LGTM! Consider adding a type annotation for consistency.The
useTimerPhase
hook is well-implemented and follows the established pattern in the file. It provides a clean way to access the timer phase, which will be useful for the new audio playback feature.For consistency with other hooks in the file, consider adding a type annotation to the
featureSelector
function:export const useTimerPhase = () => { const featureSelector = (state: RuntimeStore) => ({ phase: state.timer.phase, }); return useRuntimeStore(featureSelector); };
179-185
: Consider adding documentation for the new hook.The addition of the
useTimerPhase
hook is well-placed and consistent with the file's structure. It will be useful for components that need to react to timer phase changes, supporting the new audio playback feature mentioned in the PR objectives.To improve maintainability, consider adding a brief JSDoc comment explaining the purpose of the hook and its return value. For example:
/** * Hook to access the current timer phase from the runtime store. * @returns An object containing the current timer phase. */ export const useTimerPhase = () => { // ... (existing implementation) };apps/client/src/features/viewers/timer/Timer.tsx (2)
82-82
: Ensure custom hooks follow React conventionsCalling
usePhaseEvent()
directly inside the component without handling its lifecycle can lead to unexpected side effects during rendering. It's recommended to place the call inside auseEffect
in theTimer
component or adjust the hook to properly manage side effects.Consider this adjustment:
-export default function Timer(props: TimerProps) { +export default function Timer(props: TimerProps) { + usePhaseEvent();Adjusted
usePhaseEvent
:const usePhaseEvent = () => { const { phase } = useTimerPhase(); const previousValue = usePrevious(phase); useEffect(() => { if ( previousValue !== TimerPhase.None && previousValue !== phase && phase === TimerPhase.Overtime ) { const audio = new Audio(sound); audio.play(); } }, [phase, previousValue]); };This adheres to React's best practices by handling side effects appropriately.
65-74
: Handle user interaction for audio playbackModern browsers often restrict autoplay of audio without user interaction. To ensure the sound plays reliably, you may need to handle user gestures or provide a play button.
Consider prompting the user to enable sound or incorporating user interaction before playing audio.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
apps/client/src/assets/sounds/buzzer.mp3
is excluded by!**/*.mp3
and included byapps/client/src/**
📒 Files selected for processing (2)
- apps/client/src/common/hooks/useSocket.ts (1 hunks)
- apps/client/src/features/viewers/timer/Timer.tsx (4 hunks)
🧰 Additional context used
🔇 Additional comments (1)
apps/client/src/common/hooks/useSocket.ts (1)
179-185
: Reminder: Implement activation/deactivation functionality for the sound feature.As mentioned in the PR description, the ability to activate and deactivate the sound feature is still pending. Consider how this functionality will be implemented, possibly through additional hooks or state management.
To help plan the next steps, let's check for any existing audio-related code:
Would you like assistance in designing the activation/deactivation feature for the sound playback?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (1)
apps/client/src/features/viewers/timer/Timer.tsx (1)
Line range hint
1-280
: Summary of review and PR objectivesThis implementation is a good start towards playing a sound when the timer enters the Overtime phase. However, there are a few areas that need attention to fully meet the PR objectives and ensure best practices:
- The sound feature toggle needs to be implemented as mentioned in the PR objectives.
- The
usePhaseEvent
hook should be refactored to useuseEffect
for better integration with React's lifecycle.- The unnecessary
<audio>
element should be removed from the JSX.Regarding the concern about autoplay permissions, you might want to add a user interaction (e.g., a button click) to trigger the initial audio playback. This can help bypass autoplay restrictions in some browsers.
As for the need for a better sound file, consider adding a TODO comment or creating a separate issue to track this requirement.
Overall, with the suggested changes, this implementation will be closer to meeting all the PR objectives and following React best practices.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
apps/client/src/assets/sounds/buzzer.mp3
is excluded by!**/*.mp3
and included byapps/client/src/**
📒 Files selected for processing (2)
- apps/client/src/common/hooks/useSocket.ts (1 hunks)
- apps/client/src/features/viewers/timer/Timer.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- apps/client/src/common/hooks/useSocket.ts
🧰 Additional context used
🔇 Additional comments (2)
apps/client/src/features/viewers/timer/Timer.tsx (2)
1-1
: LGTM: New imports for audio functionalityThe new imports for
useMemo
,usePrevious
, and the sound file are appropriate for implementing the audio playback feature.Also applies to: 3-3, 17-17
195-195
:⚠️ Potential issueRemove unnecessary
<audio>
elementThe
<audio>
element added to the JSX is not required since audio playback is managed programmatically within theusePhaseEvent
hook. Including it may cause redundancy or conflicts in audio playback.You can safely remove this line:
-<audio controls src='../../assets/sounds/buzzer.mp3' />
This will ensure that audio is played only through the programmatic approach implemented in the
usePhaseEvent
hook.Likely invalid or redundant comment.
We would still need to let the users activate and deactivate this
We also need a better sound file
We may run into issues with autoplay permissions and should investigate how to direct users around this
https://developer.chrome.com/blog/autoplay