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

fix: chat navigation #175

Merged
merged 2 commits into from
Apr 13, 2024
Merged

fix: chat navigation #175

merged 2 commits into from
Apr 13, 2024

Conversation

gaboesquivel
Copy link
Member

@gaboesquivel gaboesquivel commented Apr 13, 2024

Summary by CodeRabbit

  • New Features

    • Added automatic redirection to the sign-in page for non-logged-in users to enhance security and user experience.
  • Bug Fixes

    • Refined user redirection logic based on email presence and token expiration to improve reliability.
    • Enhanced handling of potential null values in sidebar links to prevent errors.
  • Style

    • Improved the visual and functional aspects of the ThreadList component, including better handling of scenarios where no threads are found.

Copy link

vercel bot commented Apr 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
masterbots 🔄 Building (Inspect) Visit Preview Apr 13, 2024 8:07pm

Copy link
Contributor

coderabbitai bot commented Apr 13, 2024

Walkthrough

The recent updates enhance user experience by refining redirection and login checks across the application. Changes include improved handling of user authentication states, enhanced loading mechanisms for thread lists, and adjustments in navigation components to better manage null values and user interface consistency.

Changes

File Path Change Summary
.../app/c/layout.tsx & .../app/c/page.tsx Updated user authentication checks and refined redirection logic.
.../routes/c/sidebar/sidebar-link.tsx Improved null handling in navigation links.
.../shared/thread-list.tsx Enhanced thread loading logic and added UI feedback for empty lists.

🐇✨
In the land of code, where logic plays,
A rabbit hopped through the maze.
With tweaks and turns in the script's plot,
Ensured that users are forgot not.
Cheers to changes, small and big,
To make our app dance a lively jig! 🎉🐰


Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between cddb186 and f4235a1.
Files selected for processing (4)
  • apps/masterbots.ai/app/c/layout.tsx (1 hunks)
  • apps/masterbots.ai/app/c/page.tsx (3 hunks)
  • apps/masterbots.ai/components/routes/c/sidebar/sidebar-link.tsx (4 hunks)
  • apps/masterbots.ai/components/shared/thread-list.tsx (2 hunks)

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@gaboesquivel gaboesquivel merged commit 392cfe3 into alpha Apr 13, 2024
3 of 4 checks passed
@gaboesquivel gaboesquivel deleted the fix-chat branch April 13, 2024 20:07
Copy link
Contributor

@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

Comment on lines +11 to +18
const supabase = await createSupabaseServerClient()
const {
data: { user }
} = await supabase.auth.getUser()

// only logged in users can chat
// we most redirect here to prevent layout flickering
if (!user?.email) redirect(`/auth/sign-in`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper error handling for asynchronous operations in ChatLayout.

- const supabase = await createSupabaseServerClient()
- const {
-   data: { user }
- } = await supabase.auth.getUser()
+ try {
+   const supabase = await createSupabaseServerClient()
+   const {
+     data: { user }
+   } = await supabase.auth.getUser()
+   if (!user?.email) redirect(`/auth/sign-in`)
+ } catch (error) {
+   console.error('Failed to authenticate user:', error);
+   redirect(`/error`);
+ }

The original code does not handle potential errors from asynchronous operations, which could lead to unhandled promise rejections. It's crucial to wrap these operations in a try-catch block to handle errors gracefully and redirect the user to an error page if necessary.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const supabase = await createSupabaseServerClient()
const {
data: { user }
} = await supabase.auth.getUser()
// only logged in users can chat
// we most redirect here to prevent layout flickering
if (!user?.email) redirect(`/auth/sign-in`)
try {
const supabase = await createSupabaseServerClient()
const {
data: { user }
} = await supabase.auth.getUser()
// only logged in users can chat
// we most redirect here to prevent layout flickering
if (!user?.email) redirect(`/auth/sign-in`)
} catch (error) {
console.error('Failed to authenticate user:', error);
redirect(`/error`);
}

@@ -10,7 +10,8 @@ export default async function IndexPage() {
const {
data: { user }
} = await supabase.auth.getUser()
if (!user.email) redirect(`/auth/sign-in`)

if (!user?.email) redirect(`/auth/sign-in`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Refine redirection logic to handle potential null values more robustly.

- if (!user?.email) redirect(`/auth/sign-in`)
+ if (!user || !user.email) redirect(`/auth/sign-in`)

Using optional chaining (user?.email) is concise but may not explicitly handle cases where user is null or undefined. It's safer to check both user and user.email explicitly to avoid any potential issues with falsy values.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if (!user?.email) redirect(`/auth/sign-in`)
if (!user || !user.email) redirect(`/auth/sign-in`)

@@ -22,7 +23,7 @@ export default async function IndexPage() {
const jwt = cookies().get('hasuraJwt').value || ''

// NOTE: maybe we should use same expiration time
if (!jwt || isTokenExpired(jwt) || !user) redirect(`/auth/sign-in`)
if (!jwt || isTokenExpired(jwt)) redirect(`/auth/sign-in`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding logging for debugging and monitoring token expiration handling.

Adding logging before redirecting due to token expiration can help in debugging and monitoring the application, especially in production environments. This could be as simple as:

console.log(`Redirecting because token expired or is missing: ${jwt}`);

Comment on lines +47 to +49
// if no initial threads passed dont try to load more
// TODO: get thread count from server db query
if (!loadMoreRef.current || !initialThreads?.length) return
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper cleanup of IntersectionObserver to prevent memory leaks.

- observer.unobserve(entry.target)
+ observer.disconnect()

It's important to ensure that the IntersectionObserver is properly cleaned up when the component unmounts to prevent memory leaks. The current implementation only unobserves the target, but it's safer to disconnect the observer entirely.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// if no initial threads passed dont try to load more
// TODO: get thread count from server db query
if (!loadMoreRef.current || !initialThreads?.length) return
// if no initial threads passed dont try to load more
// TODO: get thread count from server db query
if (!loadMoreRef.current || !initialThreads?.length) return
observer.disconnect()

@@ -91,6 +93,7 @@ export function ThreadList({

return (
<div className="flex flex-col w-full gap-8 py-5" key={queryKey[0]}>
{!threads.length ? <div>No threads founds</div> : null}
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve user feedback by providing more detailed messages when no threads are found.

Consider enhancing the user experience by providing a more detailed message when no threads are found, such as:

<div>No threads found. Please try again later or contact support if the issue persists.</div>

This provides clearer communication and potential next steps for the user.

@@ -40,7 +41,7 @@ export default function SidebarLink({ category }: { category: Category }) {
if (
category.chatbots.length &&
category.chatbots.filter(
c => c.chatbot.name.toLowerCase().trim() === chatbot.trim()
c => c.chatbot.name.toLowerCase().trim() === chatbot?.trim()
Copy link
Contributor

Choose a reason for hiding this comment

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

Validate the presence of chatbot before accessing its properties to prevent runtime errors.

- c => c.chatbot.name.toLowerCase().trim() === chatbot?.trim()
+ c => c.chatbot && c.chatbot.name.toLowerCase().trim() === chatbot?.trim()

It's important to check that c.chatbot is not null or undefined before accessing c.chatbot.name to prevent potential runtime errors. This change ensures that the code is more robust and can handle cases where c.chatbot might be null.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
c => c.chatbot.name.toLowerCase().trim() === chatbot?.trim()
c => c.chatbot && c.chatbot.name.toLowerCase().trim() === chatbot?.trim()

Copy link

⚡️ Lighthouse report

Page: https://masterbots-pjlo8agwx-bitcash.vercel.app/
Report https://storage.googleapis.com/lighthouse-infrastructure.appspot.com/reports/1713039337620-14729.report.html

Category Score
🟠 Performance 53
🟠 Accessibility 59
🟠 Best practices 74
🔴 SEO 42
🔴 PWA 13

Page: https://masterbots-pjlo8agwx-bitcash.vercel.app/b/moneybot
Report https://storage.googleapis.com/lighthouse-infrastructure.appspot.com/reports/1713039337974-84182.report.html

Category Score
🟠 Performance 57
🟠 Accessibility 59
🟠 Best practices 74
🔴 SEO 42
🔴 PWA 13

Page: https://masterbots-pjlo8agwx-bitcash.vercel.app/u/slug-1
Report https://storage.googleapis.com/lighthouse-infrastructure.appspot.com/reports/1713039338276-6065.report.html

Category Score
🟠 Performance 58
🟢 Accessibility 94
🟠 Best practices 78
🟠 SEO 83
🔴 PWA 38

Page: https://masterbots-pjlo8agwx-bitcash.vercel.app/p
Report https://storage.googleapis.com/lighthouse-infrastructure.appspot.com/reports/1713039338598-20299.report.html

Category Score
🟠 Performance 87
🟢 Accessibility 92
🟠 Best practices 78
🟠 SEO 76
🔴 PWA 38

Page: https://masterbots-pjlo8agwx-bitcash.vercel.app/health
Report https://storage.googleapis.com/lighthouse-infrastructure.appspot.com/reports/1713039338896-51980.report.html

Category Score
🟠 Performance 89
🟠 Accessibility 59
🟠 Best practices 74
🔴 SEO 42
🔴 PWA 13

Page: https://masterbots-pjlo8agwx-bitcash.vercel.app/health/a8103808-14a3-48ed-aa5a-9e490cfdcf0e
Report https://storage.googleapis.com/lighthouse-infrastructure.appspot.com/reports/1713039339187-56171.report.html

Category Score
🟠 Performance 86
🟠 Accessibility 59
🟠 Best practices 74
🔴 SEO 42
🔴 PWA 13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant