Skip to content

Conversation

vLuckyyy
Copy link
Member

No description provided.

Signed-off-by: Martin Sulikowski <vLuckyyy.biznes@gmail.com>
Copy link

vercel bot commented Apr 23, 2025

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

Name Status Preview Comments Updated (UTC)
website ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 23, 2025 5:53pm

Copy link

coderabbitai bot commented Apr 23, 2025

Walkthrough

The Team component now manages a loading state to show a message while fetching team members and displays a styled error message if something goes wrong, including the HTTP status code. It fetches data from the API with an explicit JSON header and validates the response format before updating members. Links in TeamMember open in new tabs securely. The Projects component added similar loading and error handling improvements, removed a static export, and validates fetched data. Both the team and project API routes now include error handling, caching headers, and a revalidation setting for better performance and reliability. The public interfaces of these components remain unchanged.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

app/api/team/route.ts

Oops! Something went wrong! :(

ESLint: 9.12.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

app/api/project/route.ts

Oops! Something went wrong! :(

ESLint: 9.12.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

components/projects/Projects.tsx

Oops! Something went wrong! :(

ESLint: 9.12.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

  • 1 others

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 062c605 and d1ec3c5.

📒 Files selected for processing (4)
  • app/api/project/route.ts (1 hunks)
  • app/api/team/route.ts (1 hunks)
  • components/projects/Projects.tsx (2 hunks)
  • components/team/Team.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/team/Team.tsx
🧰 Additional context used
🧬 Code Graph Analysis (2)
app/api/project/route.ts (1)
app/api/team/route.ts (2)
  • revalidate (3-3)
  • GET (5-36)
app/api/team/route.ts (1)
app/api/project/route.ts (2)
  • revalidate (3-3)
  • GET (5-36)
🔇 Additional comments (17)
app/api/team/route.ts (5)

3-4: Good addition of revalidation!

Setting a revalidation period of 1 hour is perfect for team data that doesn't change frequently.


6-15: Nice error handling improvement

Adding a try-catch block and proper fetch options with revalidation makes the API more reliable.


17-20: Good error response handling

Checking if the response is OK and returning the proper status code helps frontend components know what went wrong.


22-28: Great caching implementation

The cache headers are set correctly with a short max-age and longer stale-while-revalidate period.


29-34: Good error logging

Logging errors to the console while returning a friendly message to users is the right approach.

app/api/project/route.ts (5)

3-4: Consistent revalidation approach

Using the same revalidation period as the team API creates consistency across the application.


6-15: Good fetch implementation

The try-catch block and revalidation options match the team API pattern, which is great for consistency.


17-20: Proper error handling

Checking response status and returning appropriate error information follows best practices.


22-28: Good caching setup

The cache headers match the team API for consistent behavior across endpoints.


29-34: Clear error response

The error message is specific to projects and follows the same pattern as the team API.

components/projects/Projects.tsx (7)

23-23: Good loading state addition

Adding a loading state helps improve the user experience while waiting for data.


29-35: Nice fetch improvements

Setting the loading state before fetching and adding proper headers is good practice.


37-39: Better error messages

Including the HTTP status code in error messages helps with debugging issues.


42-47: Good data validation

Checking that the data structure is valid before using it prevents runtime errors.


48-54: Improved error handling

The try-catch-finally block ensures the loading state is reset regardless of success or failure.


60-70: Nice loading UI

The loading message gives users feedback while waiting for projects to load.


72-82: Good error display

The error UI with red text clearly shows users when something went wrong.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

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 (2)
components/team/Team.tsx (2)

62-62: Translate the comment to English

For consistency and better collaboration, please use English comments.

-// Dodanie klucza API jeśli istnieje
+// Add API key if it exists

52-94: Consider adding cleanup for unmounted components

The current implementation doesn't handle the case where the component unmounts during the fetch operation.

  useEffect(() => {
+   let isMounted = true;
    const fetchMembers = async () => {
      try {
        setLoading(true);
        
        const headers: HeadersInit = {
          'Cache-Control': 'no-cache',
          'Pragma': 'no-cache'
        };
        
        // Add API key if it exists
        if (STRAPI_KEY) {
          headers['Authorization'] = `Bearer ${STRAPI_KEY}`;
        }
        
        // Direct request to Strapi using environment variables
        const response = await fetch(`${STRAPI_URL}/api/team-members?populate=team_roles`, {
          method: 'GET',
          headers
        });

        if (!response.ok) {
          throw new Error(`Failed to fetch team members: ${response.status}`);
        }

        const data = await response.json();

        if (data && data.data) {
+         if (isMounted) {
            setMembers(data.data);
+         }
        } else {
          throw new Error("Invalid data structure in API response");
        }
      } catch (error) {
        const err = error as Error;
+       if (isMounted) {
          setError(err.message);
+       }
        console.error("Error fetching team members:", err);
      } finally {
+       if (isMounted) {
          setLoading(false);
+       }
      }
    };

    fetchMembers();
+   return () => {
+     isMounted = false;
+   };
  }, []);
🧰 Tools
🪛 Biome (1.9.4)

[error] 79-79: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cb86fa9 and 0a54a62.

📒 Files selected for processing (1)
  • components/team/Team.tsx (5 hunks)
🔇 Additional comments (5)
components/team/Team.tsx (5)

57-71: Good implementation of fetch with headers

The cache control headers and conditional API key usage look good. This will help with real-time data fetching.


88-90: Good use of finally block

Using a finally block ensures the loading state is properly reset even if an error occurs.


96-106: Nice loading state implementation

The loading state provides good feedback to users while data is being fetched.


109-117: Well-styled error handling

The error state is nicely styled and provides clear feedback to users.


182-183: Good security practice for external links

Adding target="_blank" with rel="noopener noreferrer" is important for security when opening links in new tabs.

Also applies to: 195-196

Signed-off-by: Martin Sulikowski <vLuckyyy.biznes@gmail.com>
Signed-off-by: Martin Sulikowski <vLuckyyy.biznes@gmail.com>
Signed-off-by: Martin Sulikowski <vLuckyyy.biznes@gmail.com>
Signed-off-by: Martin Sulikowski <vLuckyyy.biznes@gmail.com>
@vLuckyyy vLuckyyy changed the title Fix strapi to fetch data in realtime. GH-110 Fix strapi to fetch data in realtime. Apr 23, 2025
@vLuckyyy vLuckyyy merged commit 1dcfb66 into master Apr 23, 2025
3 checks passed
@vLuckyyy vLuckyyy deleted the fix-strapi-realtime branch April 23, 2025 17:55
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