-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
refactor: allow aux change direction while playing #1241
Conversation
WalkthroughThe pull request introduces several modifications across multiple files, primarily focusing on timer functionality and configuration. Key changes include the conversion of duration from seconds to milliseconds in the Changes
Possibly related PRs
Suggested reviewers
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: 0
🧹 Outside diff range and nitpick comments (9)
apps/server/src/config/config.ts (1)
1-8
: Request for additional contextThe changes in this file seem to be laying the groundwork for the features mentioned in the PR objectives. However, the full implementation of allowing aux change direction while playing and editing aux input while running is not evident from these changes alone.
Could you provide more context on how these configuration changes fit into the broader implementation of these features? Are there other files that will be using this new
auxTimerDefault
configuration?Additionally, since the PR mentions a work-in-progress feature (editing aux input while running), it would be helpful to understand if this PR is intended to be merged as is, or if more changes are expected before it's ready for final review.
apps/server/src/classes/simple-timer/__tests__/SimpleTimer.test.ts (6)
91-91
: LGTM! Consider adding a comment for clarity.The update to
setDirection
to include an initial time parameter is correct and aligns with the changes mentioned in the summary.Consider adding a brief comment explaining the purpose of the
0
parameter for better readability:// Set direction to count up, starting from 0 const initialState = timer.setDirection(SimpleDirection.CountUp, 0);
117-130
: LGTM! Consider using a constant for consistency.The changes to this test case accurately reflect the new behavior of maintaining the current time when changing direction. The additional setup steps provide a clear and consistent starting state.
For consistency with the rest of the test file, consider using the
initialTime
constant instead of the magic number 1000:timer.setTime(initialTime); // ... expect(initialState.current).toBe(initialTime); // ... duration: initialTime, current: initialTime,
132-146
: LGTM! Minor inconsistency in variable usage.The test correctly verifies the timer's behavior in count-up mode after multiple updates.
For consistency, replace
initialTime
with1000
in line 135:current: 1000 + 100,This aligns with the use of 1000 in the rest of this test case.
148-162
: LGTM! Consider adding a comment for clarity.The test correctly verifies the timer's behavior when changing direction from count-up to count-down, including maintaining the current time and updating the duration.
Consider adding a brief comment explaining the significance of the
600
parameter in thesetDirection
call:// Change direction to count down, passing current time (600ms since start) newState = timer.setDirection(SimpleDirection.CountDown, 600);This helps clarify why 600 is used and how it relates to the timer's state.
164-178
: LGTM! Consider adding a comment for clarity.The test correctly verifies the timer's behavior when changing direction back to count-up, including maintaining the current time, updating the duration, and continuing to count up correctly.
Consider adding a brief comment explaining the significance of the
700
parameter in thesetDirection
call:// Change direction back to count up, passing current time (700ms since last direction change) newState = timer.setDirection(SimpleDirection.CountUp, 700);This helps clarify why 700 is used and how it relates to the timer's state.
Line range hint
1-178
: Overall, the changes look good and thoroughly test the new functionality.The updates to this test file accurately reflect and verify the new behavior of the SimpleTimer class, particularly the ability to change direction while maintaining the current time. The tests provide good coverage of various scenarios, including multiple direction changes and updates.
For future improvements, consider:
- Using constants for all magic numbers (e.g., 100, 500, 1500) to improve readability and maintainability.
- Adding a test case for edge scenarios, such as changing direction at time 0 or at the exact duration time.
apps/server/src/app.ts (1)
191-191
: LGTM: Improved flexibility with configurable aux timer duration.Replacing the hardcoded value with
timerConfig.auxTimerDefault
enhances maintainability and aligns with the PR's objectives.Consider adding a comment explaining the purpose of
auxTimerDefault
for better code documentation.apps/server/src/api-integration/integration.controller.ts (1)
233-235
: Approve changes with a minor suggestion for consistency.The conversion of duration from seconds to milliseconds is correct and aligns with the PR objective of improving aux input functionality. This change ensures consistency in time representation across the application.
For improved consistency with other parts of the codebase, consider using the
MILLIS_PER_SECOND
constant:- const timeInMs = numberOrError(command.duration) * 1000; + const timeInMs = numberOrError(command.duration) * MILLIS_PER_SECOND;This change would make the code more consistent with other time-related operations in the file (e.g., the
addtime
handler).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (6)
- apps/server/src/api-integration/integration.controller.ts (1 hunks)
- apps/server/src/app.ts (3 hunks)
- apps/server/src/classes/simple-timer/SimpleTimer.ts (3 hunks)
- apps/server/src/classes/simple-timer/tests/SimpleTimer.test.ts (2 hunks)
- apps/server/src/config/config.ts (1 hunks)
- apps/server/src/services/aux-timer-service/AuxTimerService.ts (3 hunks)
🔇 Additional comments (17)
apps/server/src/config/config.ts (2)
1-1
: LGTM: Good use of utility constantThe import of
MILLIS_PER_MINUTE
from 'ontime-utils' is a good practice. It promotes code reusability and maintainability by using a centralized constant for time conversion.
8-8
: Approved: New auxTimerDefault propertyThe addition of
auxTimerDefault
is a good improvement. It provides a clear default duration for the auxiliary timer, which enhances the configuration options.However, could you please clarify how this change relates to the PR objective of "allowing aux change direction while playing"? The current implementation sets a default duration, but it's not clear how it enables changing direction during playback.
To ensure this change doesn't conflict with existing code, let's check for any other occurrences of auxiliary timer configuration:
✅ Verification successful
Verified: Auxiliary Timer Configurations
The search for other auxiliary timer configurations did not reveal any conflicts with the addition of
auxTimerDefault
. The property is consistently used across the codebase, and no conflicting configurations were found.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Search for other auxiliary timer configurations rg --type typescript "aux.*timer" --glob '!apps/server/src/config/config.ts'Length of output: 113
Script:
#!/bin/bash # Description: Search for other auxiliary timer configurations in TypeScript files rg --type ts "aux.*timer" --glob '!apps/server/src/config/config.ts'Length of output: 4868
apps/server/src/app.ts (3)
51-51
: LGTM: New import statement added correctly.The new import for
timerConfig
is properly placed and follows the project's naming conventions.
51-51
: Overall, the changes effectively support the PR objectives.The modifications to import
timerConfig
and update theauxtimer1
initialization ineventStore.init
are well-focused and align with the goal of improving aux input functionality. These changes enhance the flexibility of the aux timer feature while minimizing the risk of unintended side effects.To ensure comprehensive testing of the new aux timer behavior, consider adding or updating relevant unit tests for the
eventStore.init
method and any components that interact with the aux timer.Also applies to: 191-192
192-192
: LGTM: Consistent update for aux timer current value.Setting
current
totimerConfig.auxTimerDefault
is consistent with theduration
update and supports the PR's objectives.Please confirm that starting the aux timer at its maximum value (counting down) is the intended behavior. If not, consider initializing
current
to a different value or adding a comment explaining the rationale.To verify the aux timer initialization, you can run the following script:
apps/server/src/api-integration/integration.controller.ts (1)
Line range hint
236-243
: Verify implementation of direction change feature.The PR objectives mention allowing aux change direction while playing. The existing code handles direction changes, but it's not clear if any additional modifications are needed to allow changing direction during playback.
Please confirm if the current implementation fully satisfies the requirement of changing aux direction while playing. If not, consider what additional changes might be necessary to meet this objective.
apps/server/src/services/aux-timer-service/AuxTimerService.ts (7)
5-5
: ImporttimerConfig
Good job importing
timerConfig
; this allows the service to use configurable timer defaults.
34-34
: Pass current time tosetDirection
methodIncluding
this.getTime()
when callingthis.timer.setDirection()
ensures the timer's direction is updated accurately with the current time context.
Line range hint
41-41
: Pass current time tostart
methodProviding
this.getTime()
tothis.timer.start()
ensures the timer starts accurately from the current time, maintaining synchronization.
Line range hint
49-49
: Pass current time topause
methodSupplying
this.getTime()
tothis.timer.pause()
allows the timer to pause precisely at the current time.
Line range hint
62-62
: Pass current time toupdate
methodBy passing
this.getTime()
tothis.timer.update()
, you ensure the timer updates based on the current time, enhancing time accuracy.
34-34
: EnsureSimpleTimer
methods acceptcurrentTime
parameterYou've updated the methods to pass
this.getTime()
tothis.timer
. Please verify that the corresponding methods inSimpleTimer
are designed to accept thecurrentTime
parameter and handle it appropriately.Run the following script to confirm that
SimpleTimer
methods acceptcurrentTime
:#!/bin/bash # Description: Verify that `SimpleTimer` methods accept `currentTime` as a parameter. # Test: Search for method definitions in `SimpleTimer` class. # Expect: Methods have signatures accepting `currentTime` as a parameter. ast-grep --lang typescript --pattern $'class SimpleTimer { $$$ setDirection($_, $_): $_ { $$$ } start($_): $_ { $$$ } pause($_): $_ { $$$ } update($_): $_ { $$$ } $$$ }'Also applies to: 41-41, 49-49, 62-62
17-17
: InitializeSimpleTimer
with default configurationInitializing
this.timer
withtimerConfig.auxTimerDefault
ensures that the timer starts with the appropriate default settings. Please verify thatauxTimerDefault
is properly defined in the configuration and contains the expected initial values.Run the following script to confirm that
auxTimerDefault
is defined:✅ Verification successful
To further verify the definition of
auxTimerDefault
, please run the following script:
auxTimerDefault
is properly defined in the configuration and contains the expected initial values.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that `auxTimerDefault` is defined in `timerConfig`. # Test: Search for the definition of `auxTimerDefault` in configuration files. # Expect: At least one match defining `auxTimerDefault`. rg 'auxTimerDefault' $(fd 'config.js')Length of output: 211
Script:
#!/bin/bash # Description: Verify that `auxTimerDefault` is defined in any configuration files. # Test: Search for the definition of `auxTimerDefault` in various configuration files. # Expect: At least one match defining `auxTimerDefault`. rg 'auxTimerDefault' $(fd 'config*' -e js -e ts -e json)Length of output: 661
apps/server/src/classes/simple-timer/SimpleTimer.ts (4)
12-17
: Proper initialization ofinitialDuration
and state propertiesThe introduction of the
initialDuration
property and its initialization along withstate.duration
andstate.current
in the constructor ensures that the timer maintains its initial settings correctly.
35-35
: UpdateinitialDuration
insetTime
method for consistencyUpdating
initialDuration
whensetTime
is called keeps the initial state consistent with the updated duration.
40-47
: Correctly resetting targets when changing direction during playbackModifying
setDirection
to resetstartedAt
and updatestate.duration
when the timer is playing ensures that the timer adjusts correctly to direction changes on the fly. Callingupdate(timeNow)
reflects the changes immediately.
72-73
: Resetting timer to initial duration instop
methodBy resetting
state.duration
andstate.current
toinitialDuration
upon stopping, the timer correctly returns to its original state.
Small improvements to the aux input