Skip to content
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

Add session timer functionality #2

Merged
merged 5 commits into from
Jan 23, 2025

Conversation

IvanKazakov2352
Copy link
Contributor

@IvanKazakov2352 IvanKazakov2352 commented Jan 20, 2025

Summary by CodeRabbit

Release Notes

  • New Features

    • Added session timer functionality to track connection duration.
    • Integrated session timer display in the UserBar component.
  • Improvements

    • Enhanced connection management with timer tracking.
    • Streamlined logic in the chat component for channel selection and deletion.
    • Added timer styling configuration with a new font size option.
  • Technical Updates

    • Implemented a new Pinia store for session timing.
    • Updated voice and chat components to manage session timer lifecycle, including error handling for timer operations.

Copy link

coderabbitai bot commented Jan 20, 2025

Walkthrough

The pull request introduces a new session timer functionality across multiple components and stores. A new Pinia store useSessionTimer is created to manage session timing, tracking elapsed time with precision. The implementation spans the ChatList, UserBar, and VoiceStore components, integrating session timer management during channel connections, disconnections, and component lifecycle events. A Tailwind configuration update adds a specific font size for timer display.

Changes

File Change Summary
src/components/ChatList.vue Updated channelSelect and channelDelete functions to be async, ensuring proper control flow and error handling; removed commented-out code.
src/components/UserBar.vue Added session timer display in template; imported useSessionTimer and instantiated sessionTimerStore.
src/store/sessionTimer.ts Created new Pinia store managing session timing with reactive state variables and timer functions.
src/store/voiceStore.ts Integrated sessionTimerStore, added timer start/stop calls in connection methods to manage session timing.
tailwind.config.js Added timer font size configuration.

Sequence Diagram

sequenceDiagram
    participant User
    participant VoiceStore
    participant SessionTimerStore
    participant Channel

    User->>VoiceStore: Initiate Channel Connection
    VoiceStore->>SessionTimerStore: stopTimer()
    VoiceStore->>Channel: Connect
    alt Connection Successful
        VoiceStore->>SessionTimerStore: startTimer()
        SessionTimerStore->>SessionTimerStore: Update Session Time
    else Connection Failed
        VoiceStore->>SessionTimerStore: stopTimer()
    end
Loading

Poem

🕰️ A Rabbit's Timely Tale 🐰

Seconds tick, minutes flow,
Our session timer starts to grow,
With Pinia's magic, time takes flight,
Tracking moments, pure delight!
A digital clock, our coding friend 🕒

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@code-maid
Copy link
Contributor

code-maid commented Jan 20, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🧹 Nitpick comments (3)
tailwind.config.js (1)

93-95: LGTM! Consider adding a comment for maintainability.

The font size configuration is well-structured and follows Tailwind's conventions. The size (12px) and line height (15px) are appropriate for a timer display.

Consider adding a brief comment to document the purpose:

       fontSize: {
+        // Custom size for session timer display in UserBar component
         'timer': ['12px', '15px'],
       }
src/store/sessionTimer.ts (1)

18-20: Consider adding days to the session time display.

The sessionTime computed property only shows hours:minutes:seconds. For long sessions, consider including days in the display format.

 const sessionTime = computed(() => 
-  `${pad(hoursSession.value % 24)}:${pad(minutesSession.value % 60)}:${pad(secondsSession.value % 60)}`
+  daysSession.value > 0
+    ? `${daysSession.value}d ${pad(hoursSession.value % 24)}:${pad(minutesSession.value % 60)}:${pad(secondsSession.value % 60)}`
+    : `${pad(hoursSession.value % 24)}:${pad(minutesSession.value % 60)}:${pad(secondsSession.value % 60)}`
 )
src/components/UserBar.vue (1)

52-52: Enhance timer display accessibility and UX.

The timer display could benefit from:

  1. ARIA label for screen readers
  2. Tooltip explaining the session duration
-        <span class="text-timer text-[#a2a6a8]">{{ sessionTimerStore.sessionTime }}</span>
+        <TooltipProvider>
+          <Tooltip>
+            <TooltipTrigger asChild>
+              <span 
+                class="text-timer text-[#a2a6a8]"
+                aria-label="Session duration"
+              >{{ sessionTimerStore.sessionTime }}</span>
+            </TooltipTrigger>
+            <TooltipContent>
+              <p>Current session duration</p>
+            </TooltipContent>
+          </Tooltip>
+        </TooltipProvider>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 33ecfe6 and 9b79a25.

⛔ Files ignored due to path filters (1)
  • bun.lockb is excluded by !**/bun.lockb
📒 Files selected for processing (5)
  • src/components/ChatList.vue (3 hunks)
  • src/components/UserBar.vue (2 hunks)
  • src/store/sessionTimer.ts (1 hunks)
  • src/store/voiceStore.ts (4 hunks)
  • tailwind.config.js (1 hunks)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (5)
src/store/sessionTimer.ts (3)

10-10: Add type annotation for the interval ref.

The interval ref lacks type annotation which could lead to type safety issues.

-  const interval = ref()
+  const interval = ref<number>()

14-16: Add input validation for session date updates.

The updateSessionDate function should validate the input date to prevent invalid dates from being set.

 function updateSessionDate(date: Date): void {
+  if (!(date instanceof Date) || isNaN(date.getTime())) {
+    throw new Error('Invalid date provided to updateSessionDate')
+  }
   sessionStartDate.value = date
 }

58-63: Consider exporting updateSessionDate for testing purposes.

The updateSessionDate function might be useful for testing scenarios to set up specific test cases.

 return { 
   updateSessionTimer,
   sessionTime,
   startTimer,
-  stopTimer
+  stopTimer,
+  updateSessionDate
 };
src/store/voiceStore.ts (2)

137-141: Consider propagating timer start errors.

While the error is logged, failing to start the session timer might indicate a more serious issue that should affect the connection state.

     try {
       sessionTimerStore.startTimer()
     } catch (error) {
       logger.error('Failed to start session timer:', error)
+      currentState.value = "NONE"
+      activeChannel.value = null
+      pool.selectedChannel = null
+      return
     }

168-172: Ensure cleanup continues after timer stop failure.

While the error is logged, the function should continue with the remaining cleanup tasks even if stopping the timer fails.

         try {
           sessionTimerStore.stopTimer()
         } catch (error) {
           logger.error('Failed to stop session timer:', error)
+          // Continue with cleanup despite timer stop failure
         }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9b79a25 and 20869ca.

📒 Files selected for processing (4)
  • src/components/ChatList.vue (3 hunks)
  • src/components/UserBar.vue (2 hunks)
  • src/store/sessionTimer.ts (1 hunks)
  • src/store/voiceStore.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/components/ChatList.vue
  • src/components/UserBar.vue
🧰 Additional context used
🪛 Biome (1.9.4)
src/store/sessionTimer.ts

[error] 24-24: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)

🔇 Additional comments (3)
src/store/sessionTimer.ts (2)

18-20: LGTM! Well-formatted time display.

The computed property correctly formats the time components with proper bounds.


40-56: LGTM! Proper cleanup implemented.

The timer control functions handle cleanup and state reset appropriately.

src/store/voiceStore.ts (1)

20-28: LGTM! Clean integration of session timer.

The session timer store is properly imported and initialized.

@IvanKazakov2352
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

code-maid added a commit that referenced this pull request Jan 22, 2025
Copy link

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (1)
src/store/sessionTimer.ts (1)

12-29: Consider performance optimizations for timer updates.

While the logic is correct, consider these optimizations:

  1. Cache the time calculations to avoid recalculating values
  2. Use template literals only when the format changes
 function updateSessionTimer(): void {
   const now = new Date();
   if (!(sessionStartDate.value instanceof Date) || Number.isNaN(sessionStartDate.value.getTime())) {
     stopTimer();
     return;
   }
   const milliseconds = now.getTime() - sessionStartDate.value.getTime();
   const seconds = Math.floor(milliseconds / 1000);
   const minutes = Math.floor(seconds / 60);
   const hours = Math.floor(minutes / 60);
   const days = Math.floor(hours / 24);
+  const formattedHours = pad(hours % 24);
+  const formattedMinutes = pad(minutes % 60);
+  const formattedSeconds = pad(seconds % 60);
 
   if(days < 1) {
-    sessionTimer.value = `${pad(hours % 24)}:${pad(minutes % 60)}:${pad(seconds % 60)}`;
+    sessionTimer.value = `${formattedHours}:${formattedMinutes}:${formattedSeconds}`;
   } else {
-    sessionTimer.value = `${days}:${pad(hours % 24)}:${pad(minutes % 60)}:${pad(seconds % 60)}`;
+    sessionTimer.value = `${days}:${formattedHours}:${formattedMinutes}:${formattedSeconds}`;
   }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 683b21e and 8160994.

📒 Files selected for processing (4)
  • src/components/ChatList.vue (1 hunks)
  • src/components/UserBar.vue (2 hunks)
  • src/store/sessionTimer.ts (1 hunks)
  • src/store/voiceStore.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/ChatList.vue
🔇 Additional comments (7)
src/store/sessionTimer.ts (2)

1-9: LGTM! Good choice of technologies.

The combination of Pinia for state management and RxJS for interval handling is a solid choice for implementing timer functionality.


31-45: LGTM! Clean implementation of timer controls.

The timer control functions properly manage subscriptions and state cleanup.

src/components/UserBar.vue (2)

52-52: LGTM! Clean integration of the timer display.

The timer is properly integrated with appropriate conditional rendering and styling.


69-69: LGTM! Clean store integration.

The session timer store is properly imported and instantiated following Vue Composition API best practices.

Also applies to: 74-74

src/store/voiceStore.ts (3)

20-20: LGTM! Clean store integration.

The session timer store is properly imported and instantiated following Pinia best practices.

Also applies to: 27-27


63-63: LGTM! Proper timer control during connection.

The timer is correctly stopped before connection attempt and started after successful connection.

Also applies to: 137-137


164-164: LGTM! Proper timer cleanup during disconnection.

The timer is correctly stopped during channel disconnection, with appropriate error protection.

@0xF6 0xF6 merged commit 95b5352 into argon-chat:master Jan 23, 2025
2 checks passed
@argon-chat argon-chat locked and limited conversation to collaborators Jan 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants