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

11/30 event/select page update #127

Merged
merged 15 commits into from
Jan 20, 2025
Merged

11/30 event/select page update #127

merged 15 commits into from
Jan 20, 2025

Conversation

xCk27x
Copy link
Contributor

@xCk27x xCk27x commented Nov 30, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a multi-step event selection process with interactive buttons for various activities.
    • Added components for selecting activity types, scales, and affiliations, enhancing user interaction.
    • Implemented a step indicator to visually guide users through the selection process.
  • Bug Fixes

    • Improved navigation flow between steps to ensure a seamless user experience.

Copy link
Contributor

coderabbitai bot commented Nov 30, 2024

Warning

Rate limit exceeded

@1989ONCE has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 4 minutes and 24 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 283edbd and 5cc3d0b.

📒 Files selected for processing (2)
  • src/components/pages/select/belong.tsx (1 hunks)
  • src/routes/events/select.tsx (1 hunks)

Walkthrough

The changes introduce a multi-step event selection process in a React application. Three new components (BelongContent, ScaleContent, and TypeContent) are created, each with a prop onNext that triggers navigation to the next step. A new route component, SelectContent, is added to manage the selection process, rendering the appropriate content based on the current step and facilitating navigation through the steps. Additionally, routing definitions are updated to incorporate the new routes.

Changes

File Path Change Summary
src/components/pages/select/belong.tsx Added belongOptions, BelongContentProps, and SelectionContent component for event options.
src/components/pages/select/scale.tsx Added ScaleContentProps interface and ScaleContent component with buttons for navigation.
src/components/pages/select/type.tsx Added TypeContentProps interface and TypeContent component with buttons for navigation.
src/routes/events/select.tsx Added SelectContent component to manage multi-step selection and routing logic.
src/routeTree.gen.ts Introduced new route definitions for /events/select and updated routing interfaces.
tsconfig.json Updated include array to include src/routes/events/select/type.tsx for TypeScript compilation.

Possibly related PRs

  • detailPage #128: The changes in the main PR introduce a new component for event selection, which is part of the same event management context as the modifications in the detailPage PR, specifically related to event registration and navigation.

Suggested reviewers

  • yeahlowflicker
  • 1989ONCE

Poem

In a garden of choices, we hop and play,
With buttons to press, we brighten the day.
"校園活動" and "我要揪人!" we cheer,
Each step we take, brings the fun near!
So click on the buttons, let joy take flight,
In our event journey, everything feels right! 🐇✨


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.

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

🧹 Outside diff range and nitpick comments (6)
src/components/pages/select/scale.tsx (1)

8-8: Remove empty div

This empty div serves no purpose and should be removed.

src/components/pages/select/type.tsx (1)

11-30: Extract common button styles and improve accessibility

The buttons share identical styles and need accessibility improvements. Consider extracting a reusable component.

interface SelectButtonProps {
  onClick: () => void;
  label: string;
  ariaLabel: string;
}

const SelectButton: React.FC<SelectButtonProps> = ({onClick, label, ariaLabel}) => (
  <button
    className="card bg-neutral-content rounded-box grid h-20 place-items-center text-gray-800 font-bold text-2xl mb-8 hover:scale-105 transition-transform"
    onClick={onClick}
    aria-label={ariaLabel}
    role="button"
  >
    {label}
  </button>
);

Usage example:

-<button
-  className="card bg-neutral-content rounded-box grid h-20 place-items-center text-gray-800 font-bold text-2xl mb-8 hover:scale-105 transition-transform"
-  onClick={onNext}
->
-  揪人共乘
-</button>
+<SelectButton
+  onClick={() => onNext(EventType.Carpool)}
+  label="揪人共乘"
+  ariaLabel="Select carpool event"
+/>
src/components/pages/select/belong.tsx (1)

1-35: Add keyboard navigation support

Consider adding keyboard navigation support for better accessibility.

const SelectionContent: React.FC<SelectionContentProps> = ({options, onSelect}) => {
  const handleKeyDown = (e: React.KeyboardEvent, value: string) => {
    if (e.key === 'Enter' || e.key === ' ') {
      e.preventDefault();
      onSelect(value);
    }
  };

  return (
    <div className="flex items-center justify-center">
      <div className="flex w-full flex-col" role="listbox">
        {options.map(({value, label, ariaLabel}) => (
          <div
            key={value}
            role="option"
            tabIndex={0}
            onKeyDown={(e) => handleKeyDown(e, value)}
            onClick={() => onSelect(value)}
            className="card bg-neutral-content rounded-box grid h-20 place-items-center text-gray-800 font-bold text-2xl mb-8 hover:scale-105 transition-transform"
            aria-label={ariaLabel}
          >
            {label}
          </div>
        ))}
      </div>
    </div>
  );
};
src/routes/events/select.tsx (3)

15-15: Extract magic number into a named constant

The maximum step value (3) should be defined as a named constant for better maintainability and clarity.

+const MAX_STEPS = 3;
 const [step, setStep] = useState(0)

 const handleNextStep = () => {
-  setStep((prevStep) => Math.min(prevStep + 1, 3))
+  setStep((prevStep) => Math.min(prevStep + 1, MAX_STEPS))
 }

Also applies to: 17-19


31-32: Externalize hardcoded strings for internationalization

Consider moving the Chinese text strings into a localization file for better maintainability and future internationalization support.

+const TRANSLATIONS = {
+  cancel: '取消',
+  add: '新增',
+  scale: '規模',
+  type: '類型',
+  nature: '性質',
+};

-<button className="absolute left-2 btn btn-ghost"><Link to='/events'>取消</Link></button>
-<h1 className="text-xl">新增</h1>
+<button className="absolute left-2 btn btn-ghost"><Link to='/events'>{TRANSLATIONS.cancel}</Link></button>
+<h1 className="text-xl">{TRANSLATIONS.add}</h1>

-<li className={`step ${step >= 0 ? 'step-primary' : ''}`}>規模</li>
-<li className={`step ${step >= 1 ? 'step-primary' : ''}`}>類型</li>
-<li className={`step ${step >= 2 ? 'step-primary' : ''}`}>性質</li>
+<li className={`step ${step >= 0 ? 'step-primary' : ''}`}>{TRANSLATIONS.scale}</li>
+<li className={`step ${step >= 1 ? 'step-primary' : ''}`}>{TRANSLATIONS.type}</li>
+<li className={`step ${step >= 2 ? 'step-primary' : ''}`}>{TRANSLATIONS.nature}</li>

Also applies to: 48-50


31-31: Improve cancel button accessibility

The cancel button should have an aria-label for better accessibility.

-<button className="absolute left-2 btn btn-ghost"><Link to='/events'>取消</Link></button>
+<button className="absolute left-2 btn btn-ghost" aria-label="Cancel and return to events"><Link to='/events'>取消</Link></button>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f00464a and d739a85.

📒 Files selected for processing (4)
  • src/components/pages/select/belong.tsx (1 hunks)
  • src/components/pages/select/scale.tsx (1 hunks)
  • src/components/pages/select/type.tsx (1 hunks)
  • src/routes/events/select.tsx (1 hunks)
🔇 Additional comments (1)
src/routes/events/select.tsx (1)

4-6: Verify type definitions for imported content components

Ensure that the imported content components implement their respective interfaces with the onNext prop.

✅ Verification successful

All content components properly implement the onNext prop interface

All three components (ScaleContent, TypeContent, and BelongContent) correctly implement their respective interfaces with properly typed onNext props as () => void. Each component:

  • Has a properly defined interface (ScaleContentProps, TypeContentProps, BelongContentProps)
  • Correctly types the onNext prop as a function with no parameters and no return value
  • Properly uses the onNext prop in button click handlers
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the content components properly implement their interfaces
# Expected: Each component should have a properly typed onNext prop

# Check ScaleContent
ast-grep --pattern 'interface ScaleContentProps {
  onNext: $type
}'

# Check TypeContent
ast-grep --pattern 'interface TypeContentProps {
  onNext: $type
}'

# Check BelongContent
ast-grep --pattern 'interface BelongContentProps {
  onNext: $type
}'

Length of output: 212


Script:

#!/bin/bash
# Let's try a different approach to check the component definitions and their props

# Check ScaleContent implementation
ast-grep --pattern 'const ScaleContent = ({ onNext }: $_) => {
  $$$
}'

# Check TypeContent implementation
ast-grep --pattern 'const TypeContent = ({ onNext }: $_) => {
  $$$
}'

# Check BelongContent implementation
ast-grep --pattern 'const BelongContent = ({ onNext }: $_) => {
  $$$
}'

# Also search for type definitions with a more flexible pattern
ast-grep --pattern 'type $name = {
  onNext: $type
}'

# And interface definitions with a more flexible pattern
ast-grep --pattern 'interface $name {
  onNext: $type
}'

# Let's also check the actual files
fd "scale|type|belong" --type f src/components/pages/select/

Length of output: 513


Script:

#!/bin/bash
# Let's examine the content of these files directly

# Check scale.tsx content
echo "=== scale.tsx ==="
cat src/components/pages/select/scale.tsx

# Check type.tsx content
echo "=== type.tsx ==="
cat src/components/pages/select/type.tsx

# Check belong.tsx content
echo "=== belong.tsx ==="
cat src/components/pages/select/belong.tsx

Length of output: 3889

src/components/pages/select/scale.tsx Outdated Show resolved Hide resolved
src/components/pages/select/scale.tsx Outdated Show resolved Hide resolved
src/components/pages/select/type.tsx Show resolved Hide resolved
src/components/pages/select/belong.tsx Outdated Show resolved Hide resolved
src/routes/events/select.tsx Outdated Show resolved Hide resolved
src/routes/events/select.tsx Outdated Show resolved Hide resolved
@1989ONCE 1989ONCE assigned 1989ONCE and xCk27x and unassigned 1989ONCE Nov 30, 2024
@1989ONCE 1989ONCE added the enhancement New feature or request label Dec 2, 2024
@1989ONCE 1989ONCE self-requested a review December 3, 2024 12:06
Copy link
Member

@1989ONCE 1989ONCE left a comment

Choose a reason for hiding this comment

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

Please make sure to pass the type check, thx

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

🧹 Nitpick comments (4)
src/components/pages/select/scale.tsx (2)

1-3: Update the comment to match the current implementation

The Chinese comment describes onNext as a function without parameters, but the type signature shows it accepts a scale parameter.

-  onNext: (scale: 'small' | 'formal') => void; // 定义 onNext 是一个无参数、无返回值的函数
+  onNext: (scale: 'small' | 'formal') => void; // 定义 onNext 是一个接收 scale 参数的函数

8-8: Remove empty div

This empty div serves no purpose and should be removed.

-      <div></div>
src/components/pages/select/belong.tsx (2)

22-39: Leverage the 'ariaLabel' for accessibility.

Although each option has an ariaLabel field, it’s not currently used in the rendered . To enhance screen reader accessibility, apply it with the button’s aria-label attribute.

Below is a small diff to incorporate it:

{options.map(({ value, label, ariaLabel }) => (
  <button
+   aria-label={ariaLabel}
    className="card bg-neutral-content rounded-box grid h-20 place-items-center text-gray-800 font-bold text-2xl mb-8 hover:scale-105 transition-transform"
    key={value}
    onClick={() => onSelect(value)}
  >
    { label }
  </button>
))}

24-24: Check necessity of empty

.

There is an empty

on line 24. If it’s used for spacing or styling, consider adding a comment to clarify intent or substituting with CSS margin/padding. Otherwise, remove it to keep the markup minimal.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d739a85 and 5f9a4c3.

📒 Files selected for processing (4)
  • src/components/pages/select/belong.tsx (1 hunks)
  • src/components/pages/select/scale.tsx (1 hunks)
  • src/routeTree.gen.ts (13 hunks)
  • src/routes/events/select.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/routes/events/select.tsx
🔇 Additional comments (4)
src/components/pages/select/scale.tsx (1)

5-32: Implementation looks good!

The component is well-structured with:

  • Proper TypeScript typing
  • Clear button labels and descriptions
  • Accessibility attributes
  • Consistent styling
src/components/pages/select/belong.tsx (1)

1-5: No major issues, but ensure uniqueness of 'value' keys if expanded.

The approach of defining your options in a constant array is valid. However, make sure each option's 'value' is guaranteed unique, especially as you expand "// ... other options." Otherwise, React will raise warning about duplicate keys.

src/routeTree.gen.ts (2)

77-85: Verify the navigation flow between selection steps

The AI summary mentions a multi-step event selection process. Please ensure that the navigation between SelectContent, ScaleContent, TypeContent, and BelongContent components is properly handled.

Let's check the component implementations:

✅ Verification successful

Navigation flow between selection steps is properly implemented

The code shows a well-structured multi-step event selection process:

  • Uses local state management with useState to track the current step
  • Implements handleNextStep function that properly limits progression to max 3 steps
  • Correctly passes onNext handler to all step components (ScaleContent, TypeContent, BelongContent)
  • Components are properly imported and rendered conditionally based on the current step
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for navigation handlers in the selection components
rg -A 3 "onNext|handleNextStep" src/routes/events/select.tsx

# Check for proper component imports
rg -A 3 "import.*(?:Scale|Type|Belong)Content" src/routes/events/select.tsx

Length of output: 798


Script:

#!/bin/bash
# Check the implementation of the selection components to verify proper prop handling
ast-grep --pattern 'export $_ function $_Content({ onNext }: { onNext: $_}) {
  $$$
}'

# Check for any navigation state management
rg -A 5 "const.*step.*=.*useState" src/routes/events/select.tsx

# Check the main SelectContent component structure
ast-grep --pattern 'export function SelectContent() {
  $$$
}'

Length of output: 349


Line range hint 1-7: ⚠️ Warning: This is an auto-generated file

The file header explicitly states that this file should not be manually modified as it will be overwritten. Any changes should be made through the TanStack Router configuration instead of direct edits to this file.

Let's verify if these changes were auto-generated:

src/components/pages/select/belong.tsx Outdated Show resolved Hide resolved
src/routeTree.gen.ts Outdated Show resolved Hide resolved
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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5f9a4c3 and 65e027f.

📒 Files selected for processing (4)
  • src/components/pages/select/belong.tsx (1 hunks)
  • src/routeTree.gen.ts (14 hunks)
  • src/routes/events/select.tsx (1 hunks)
  • tsconfig.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/routes/events/select.tsx
  • src/components/pages/select/belong.tsx
🔇 Additional comments (5)
src/routeTree.gen.ts (5)

115-121: LGTM: FileRoutesByPath interface update is consistent

The new route entry follows the established pattern and includes all required properties.


174-174: LGTM: Interface updates are comprehensive and consistent

The new route has been properly integrated into all necessary interfaces and objects, maintaining consistency throughout the routing configuration.

Also applies to: 188-188, 203-203, 219-219, 232-232, 245-245, 260-260, 274-274


320-322: LGTM: Route manifest entry is properly configured

The manifest entry for the new route is correctly structured and consistent with other route definitions.


22-22: Verify route implementation file exists

The route configuration looks consistent with the existing pattern. Let's verify the implementation file exists at the expected location.

Also applies to: 68-71

✅ Verification successful

Route implementation verified successfully

The route implementation at src/routes/events/select.tsx exists and follows the expected structure:

  • Uses createFileRoute with correct path '/events/select'
  • Exports the required Route constant
  • Implements the component with proper navigation and content structure
  • Follows the same pattern as other route files in the events directory
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the select route implementation exists and follows the expected structure

# Check if the implementation file exists
fd -t f "select.tsx" src/routes/events

# Verify the route component structure
ast-grep --pattern 'export const Route = new FileRoute({
  $$$
})' src/routes/events/select.tsx

Length of output: 165


Script:

#!/bin/bash
# Let's verify the route component structure in more detail
# to ensure it follows the expected pattern with path and component

ast-grep --pattern 'export const Route = new FileRoute({
  path: $_,
  component: $_,
  $$$
})' src/routes/events/select.tsx

# Also check if the file exports the expected component
ast-grep --pattern 'export function Select() {
  $$$
}' src/routes/events/select.tsx

Length of output: 213


Script:

#!/bin/bash
# Let's check the actual content of the file to understand its structure
cat src/routes/events/select.tsx

# Also verify if this is the only route file in events directory
fd -t f ".tsx" src/routes/events

Length of output: 1926


22-24: Verify consistency of events routing structure

Let's ensure all event-related routes are properly implemented and consistent with the configuration.

✅ Verification successful

Let me gather more information about the $eventId route since it's imported in the route tree but wasn't found in the initial search.


Let me verify the route component structure in the $eventId.tsx file since we confirmed its existence but haven't checked its implementation.


Route configuration is consistent and properly implemented

The events routing structure is correctly implemented with all necessary components in place:

  • /events/select route is properly imported and configured
  • /events/create route is properly imported and configured
  • /events/$eventId dynamic route exists and is properly implemented with correct loader and component structure
  • /events/index route is present as the index route
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all event-related route implementations

# Check all event-related route files
echo "Checking event-related route files..."
fd -e tsx "^(\$eventId|select|create|index)\.tsx$" src/routes/events

# Verify route component structure in each file
echo "Verifying route component structure..."
for file in $(fd -e tsx "^(\$eventId|select|create|index)\.tsx$" src/routes/events); do
  echo "Checking $file..."
  ast-grep --pattern 'export const Route = new FileRoute({
    $$$
  })' "$file"
done

Length of output: 1232


Script:

#!/bin/bash
# Check for $eventId route implementation
echo "Checking for \$eventId route implementation..."
fd -t f "eventId" src/routes/events

# Check the content of routeTree.gen.ts for event routes configuration
echo "\nChecking route tree configuration..."
cat src/routeTree.gen.ts

# Look for any potential dynamic route patterns
echo "\nChecking for dynamic route patterns..."
rg -l "\[eventId\]" src/routes/events

Length of output: 9199


Script:

#!/bin/bash
# Check the implementation of $eventId route
echo "Checking $eventId route implementation..."
cat "src/routes/events/\$eventId.tsx"

# Verify FileRoute structure
echo "\nVerifying FileRoute structure..."
ast-grep --pattern 'export const Route = new FileRoute({
    $$$
  })' "src/routes/events/\$eventId.tsx"

Length of output: 15136

tsconfig.json Outdated Show resolved Hide resolved
@1989ONCE 1989ONCE self-requested a review December 21, 2024 13:25
tsconfig.json Outdated Show resolved Hide resolved
@1989ONCE 1989ONCE merged commit 8ee7c0a into NCUAppTeam:main Jan 20, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

3 participants