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

feat(gamescreen): add infoBloc, rebrand ui and refactor progressBar #323

Merged
merged 3 commits into from
Nov 10, 2024

Conversation

caxewsh
Copy link
Owner

@caxewsh caxewsh commented Nov 9, 2024

Pull Request Template

Description

Please include a summary of the change and which issue is fixed. Also, include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

  • Test A
  • Test B

Screenshots

If applicable, add screenshots to help explain your changes or demonstrate the UI/UX impact.

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new InfoBloc component to display loading messages and instructions for questions.
    • Updated data fetching to include additional information in the game questions.
  • Bug Fixes

    • Enhanced error handling for data fetching to ensure issues are logged appropriately.
  • Style

    • Adjusted margins and padding in the GameCard and ProgressBar components for a cleaner appearance.
    • Streamlined the ProgressBar by removing the text label.
    • Updated the styling of the SuggestionModal and its button for improved usability.
  • Chores

    • Updated the expo-dev-client dependency to the latest version.

Copy link

coderabbitai bot commented Nov 9, 2024

Walkthrough

The pull request introduces several changes across multiple components in the game interface. The GameCard component's outer margin is reduced, while a new InfoBloc component is added to display information and instructions. The ProgressBar component has its padding adjusted and a label removed. Additionally, the Gamescreen.js file updates the Supabase query to include new data fields and incorporates the InfoBloc for enhanced user information. The package.json file reflects a minor dependency version update.

Changes

File Change Summary
components/gamescreen/GameCard.jsx Adjusted outer margin from m-10 to m-6. No other changes to logic or structure.
components/gamescreen/InfoBloc.jsx Added new InfoBloc component to display information with an icon and styled text.
components/gamescreen/ProgressBar.jsx Removed style prop, changed padding from p-4 to p-2, and removed the "Progression" label.
package.json Updated expo-dev-client version from ~4.0.28 to ~4.0.29.
screens/Gamescreen.js Updated Supabase query to questionsV4, added InfoBloc for displaying instructions, and adjusted error handling.
components/settingscreen/SuggestionModal.jsx Added isSubmitting state variable, updated modal background color, and enhanced button styling.

Possibly related PRs

Poem

In the game where bunnies play,
New changes hop in bright array.
Margins trimmed, a bloc to share,
Progress shown with style and flair.
With each question, joy will bloom,
In our screens, there's more room! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a19a3c9 and b177cd2.

📒 Files selected for processing (1)
  • components/settingscreen/SuggestionModal.jsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/settingscreen/SuggestionModal.jsx

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 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

🧹 Outside diff range and nitpick comments (5)
components/gamescreen/ProgressBar.jsx (2)

8-8: LGTM! Consider extracting magic numbers.

The padding and margin adjustments align with the UI rebranding objectives. However, the Progress.Bar component has hardcoded values that could be made configurable.

Consider extracting the hardcoded values into constants or props:

 const ProgressBar = ({ currentQuestionIndex, questions }) => {
+  const PROGRESS_WIDTH = 300;
+  const PROGRESS_HEIGHT = 10;
+  const PROGRESS_COLOR = '#62C0CC';
   return (
     <View
       className="flex justify-center items-center m-4 p-2 rounded-lg"
     >
       <Progress.Bar
         progress={(currentQuestionIndex + 1) / questions.length}
-        width={300}
-        height={10}
-        color="#62C0CC"
+        width={PROGRESS_WIDTH}
+        height={PROGRESS_HEIGHT}
+        color={PROGRESS_COLOR}
       />
     </View>
   );
 };

Line range hint 1-19: Consider adding PropTypes and documentation.

The component looks clean and focused, but could benefit from proper prop validation and documentation.

Add PropTypes and JSDoc:

 import React from "react";
 import { View, Text } from "react-native";
 import * as Progress from "react-native-progress";
+import PropTypes from 'prop-types';

+/**
+ * ProgressBar component that shows the current progress in a quiz/game
+ * @param {number} currentQuestionIndex - Zero-based index of the current question
+ * @param {Array} questions - Array of all questions
+ * @returns {React.Component} A progress bar showing completion status
+ */
 const ProgressBar = ({ currentQuestionIndex, questions }) => {
   // ... existing code ...
 };

+ProgressBar.propTypes = {
+  currentQuestionIndex: PropTypes.number.isRequired,
+  questions: PropTypes.array.isRequired,
+};

 export default ProgressBar;
screens/Gamescreen.js (3)

42-44: Document the question limit rationale

The hard-coded limit of 45 questions should be explained with a comment, and consider making it a named constant.

+// Maximum number of questions per game session to maintain optimal gameplay duration
+const MAX_QUESTIONS = 45;
-const limitedQuestions = shuffledQuestions.slice(0, 45);
+const limitedQuestions = shuffledQuestions.slice(0, MAX_QUESTIONS);

49-54: Enhance player score initialization

The score initialization could be more robust by ensuring non-negative values and considering additional player stats.

 parsedPlayers = parsedPlayers.map(player => ({
   ...player,
-  score: player.score || 0
+  score: Math.max(0, parseInt(player.score) || 0),
+  gamesPlayed: player.gamesPlayed || 0,
 }));

Line range hint 113-121: Improve loading state handling

Consider disabling user interactions during loading state and showing a loading indicator in the GameCard component.

 <GameCard
   item={questions[currentQuestionIndex]}
   currentPlayer={players[currentQuestionIndex % players.length]}
   isLoading={isLoading}
+  disabled={isLoading}
   players={players}
   questions={questions}
   currentQuestionIndex={currentQuestionIndex}
 />
-<NextRoundButton onPress={handleNextRound} isLoading={isLoading} />
+<NextRoundButton 
+  onPress={handleNextRound} 
+  isLoading={isLoading}
+  disabled={isLoading} 
+/>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 22f2473 and 9a6a9c5.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (5)
  • components/gamescreen/GameCard.jsx (1 hunks)
  • components/gamescreen/InfoBloc.jsx (1 hunks)
  • components/gamescreen/ProgressBar.jsx (1 hunks)
  • package.json (1 hunks)
  • screens/Gamescreen.js (4 hunks)
✅ Files skipped from review due to trivial changes (3)
  • components/gamescreen/GameCard.jsx
  • components/gamescreen/InfoBloc.jsx
  • package.json
🔇 Additional comments (3)
components/gamescreen/ProgressBar.jsx (1)

Line range hint 1-19: Verify error handling for edge cases.

The progress calculation assumes valid inputs but doesn't handle edge cases.

Let's check if there are any error boundaries or error handling in parent components:

Consider adding input validation:

 const ProgressBar = ({ currentQuestionIndex, questions }) => {
+  if (!Array.isArray(questions) || questions.length === 0) {
+    return null;
+  }
+  
+  const progress = Math.min(
+    Math.max((currentQuestionIndex + 1) / questions.length, 0),
+    1
+  );
+
   return (
     <View
       className="flex justify-center items-center m-4 p-2 rounded-lg"
     >
       <Progress.Bar
-        progress={(currentQuestionIndex + 1) / questions.length}
+        progress={progress}
         width={300}
         height={10}
         color="#62C0CC"
       />
     </View>
   );
 };
screens/Gamescreen.js (2)

16-16: LGTM: Clean import addition

The InfoBloc component import is properly placed with other component imports.


33-34: Verify database migration from V3 to V4

The query has been updated from questionsV3 to questionsV4. This version change might affect other parts of the application.

✅ Verification successful

No migration concerns found for questionsV4 table

The codebase scan shows that questionsV4 is the only version of the questions table being used, with no remaining references to questionsV3. This suggests a clean implementation without version conflicts.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining references to questionsV3
rg "questionsV3" --type js

Length of output: 26


Script:

#!/bin/bash
# Search for any Supabase table queries to understand the database structure
rg "supabase.*from\(" --type js -A 2

Length of output: 263

@@ -86,7 +90,7 @@ export default function Gamescreen() {
}

if (currentQuestionIndex + 1 >= questions.length) {
// No more questions, navigate to Endscreen or reset for a new game
<InfoBloc info={isLoading ? "Loading..." : questions[currentQuestionIndex]?.Instructions || "No instructions available."} />
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consolidate duplicate InfoBloc usage

The InfoBloc component is rendered twice with identical props. Consider consolidating this into a single component or creating a custom hook for the info message.

+const getInfoMessage = (isLoading, currentQuestion) => 
+  isLoading ? "Loading..." : currentQuestion?.Instructions || "No instructions available.";

-<InfoBloc info={isLoading ? "Loading..." : questions[currentQuestionIndex]?.Instructions || "No instructions available."} />
+<InfoBloc info={getInfoMessage(isLoading, questions[currentQuestionIndex])} />

Also applies to: 113-113

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

🧹 Outside diff range and nitpick comments (3)
components/settingscreen/SuggestionModal.jsx (2)

29-29: Consider using consistent styling approach

The modal background style mixes Tailwind classes with inline styles. Consider using Tailwind's opacity utilities and custom colors in your theme config for better maintainability.

-<View className=" p-6 rounded-lg w-11/12" style={{ backgroundColor: "rgba(24, 164, 129, 0.9)" }} >
+<View className="p-6 rounded-lg w-11/12 bg-emerald-500/90">

Line range hint 1-55: Consider adding form validation and error handling

The current implementation lacks:

  1. Input validation
  2. Error handling for submission failures
  3. Feedback to users on successful submission

Would you like me to provide a more robust implementation with proper form validation and error handling?

screens/Gamescreen.js (1)

42-44: Extract magic number to a named constant.

The hardcoded limit of 45 questions should be defined as a named constant at the top of the file for better maintainability and documentation.

+const MAX_QUESTIONS = 45; // Maximum number of questions per game session
+
 export default function Gamescreen() {
   // ... existing code ...
-    const limitedQuestions = shuffledQuestions.slice(0, 45);
+    const limitedQuestions = shuffledQuestions.slice(0, MAX_QUESTIONS);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9a6a9c5 and a19a3c9.

📒 Files selected for processing (3)
  • components/gamescreen/ProgressBar.jsx (1 hunks)
  • components/settingscreen/SuggestionModal.jsx (2 hunks)
  • screens/Gamescreen.js (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/gamescreen/ProgressBar.jsx
🔇 Additional comments (3)
screens/Gamescreen.js (3)

16-16: LGTM! Import statement is correctly placed.

The InfoBloc component import follows the established pattern of component imports.


112-112: LGTM! InfoBloc implementation is clean and handles all states.

The component correctly handles:

  • Loading state
  • Missing instructions
  • Optional chaining for safe property access

Note: The previous review comment about duplicate InfoBloc usage is no longer applicable as the implementation has been consolidated.


33-33: Verify the impact of questionsV3 to questionsV4 migration.

The change in table version could impact existing deployments. Please ensure:

  1. Data migration from V3 to V4 is completed
  2. Backward compatibility is maintained if needed
  3. Rollback strategy is in place

Comment on lines 48 to 49
<TouchableOpacity onPress={handleSubmit} className="self-end bg-black p-2 rounded-xl">
<Text className="text-white text-lg font-semibold mx-2">Envoyer</Text>
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance button accessibility and user experience

The submit button could benefit from:

  1. A loading state during submission
  2. Proper accessibility labels
  3. Visual feedback on press
-<TouchableOpacity onPress={handleSubmit} className="self-end bg-black p-2 rounded-xl">
-  <Text className="text-white text-lg font-semibold mx-2">Envoyer</Text>
+<TouchableOpacity 
+  onPress={handleSubmit}
+  accessibilityLabel="Submit suggestion"
+  accessibilityRole="button"
+  className="self-end bg-black active:bg-black/80 p-2 rounded-xl"
+>
+  <Text className="text-white text-lg font-semibold mx-2">
+    {isSubmitting ? 'Envoi...' : 'Envoyer'}
+  </Text>
</TouchableOpacity>

Committable suggestion skipped: line range outside the PR's diff.

@caxewsh caxewsh merged commit 0b7ceca into main Nov 10, 2024
4 checks passed
@caxewsh caxewsh deleted the mvp-gamescreenV2 branch November 10, 2024 00:29
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