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

[REFACTOR] CSS for PostCard.tsx #3006

Conversation

hustlernik
Copy link
Contributor

@hustlernik hustlernik commented Dec 28, 2024

What kind of change does this PR introduce?

Streamlined all CSS for PostCard.tsx into a single global file, fixed UI bugs on the PostCard.tsx , and ensured no conflicts with other pages.

Issue Number:

Fixes #2895

Did you add tests for your changes?

No

Does this PR introduce a breaking change?

No

Have you read the contributing guide?

Yes

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced new CSS classes for post card components, enhancing layout and interactivity.
  • Styling Updates

    • Removed the dedicated CSS module for post cards and migrated styles to a centralized stylesheet.
    • Updated class names for improved styling consistency and organization.
  • Refactor

    • Consolidated styling approach by centralizing post card styles.

These changes aim to improve the visual presentation and maintainability of the post card interface.

Copy link
Contributor

coderabbitai bot commented Dec 28, 2024

Walkthrough

This pull request focuses on refactoring the CSS for the PostCard component by removing the PostCard.module.css file and consolidating its styles into the global app.module.css. The changes involve updating the import statements in the PostCard.tsx component and modifying class names to reference the new global CSS file. This approach aims to streamline the application's styling and improve maintainability by centralizing CSS definitions.

Changes

File Change Summary
src/components/UserPortal/PostCard/PostCard.module.css Removed entirely
src/components/UserPortal/PostCard/PostCard.tsx Updated CSS import to use app.module.css and modified class names with PostCard suffix
src/style/app.module.css Added new CSS classes for PostCard component: .cardStyles, .cardHeaderPostCard, .creator, .customToggle, .cardBodyPostCard, .cardTitlePostCard, .inputArea

Assessment against linked issues

Objective Addressed Explanation
Refactor CSS in PostCard component [#2895]
Move CSS to global file src/style/app.module.css [#2895]
Remove embedded CSS references [#2895]

Possibly related issues

Possibly related PRs

Suggested reviewers

  • palisadoes

Poem

🐰 Hop, hop, CSS styles merge!
From scattered files to one grand surge
PostCard's style, now clean and bright
Global CSS takes flight with might
A rabbit's dance of code delight! 🎨


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.

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

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

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

🧹 Nitpick comments (5)
src/style/app.module.css (5)

3528-3534: Consider making the card width responsive.

The fixed width of 20rem might cause layout issues on smaller screens. Consider using:

  • Fluid units like percentage or viewport units
  • Media queries to adjust width based on screen size
  • min/max width constraints for better control
.cardStyles {
-  width: 20rem;
+  width: 100%;
+  max-width: 20rem;
  background-color: var(--bs-white);
  padding: 0;
  border: none !important;
  outline: none !important;
}

3548-3565: Use relative units for SVG dimensions.

The hardcoded SVG dimensions might not scale well across different screen sizes.

.creator svg {
-  width: 2rem;
-  height: 2rem;
+  width: 1.5em;
+  height: 1.5em;
}

3585-3619: Improve text readability.

Text justification (text-align: justify) can create uneven word spacing and affect readability. Consider using left alignment instead.

.cardText {
  --max-lines: 2;
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: var(--max-lines);
  padding-top: 0;
  font-weight: 300;
  margin-top: 0.7rem !important;
-  text-align: justify;
+  text-align: left;
}

3620-3652: Add transition effect for outline.

The outline appears abruptly on focus. Consider adding a smooth transition.

.cardActionBtn {
  background-color: rgba(0, 0, 0, 0);
  padding: 0;
  border: none;
  color: black;
-  transition: background-color 0.2s ease;
+  transition: all 0.2s ease;
}

3701-3704: Improve image handling.

The fixed height for post images might cause aspect ratio distortion. Consider using aspect-ratio property or maintaining aspect ratio through padding technique.

.postImage {
-  height: 300px;
+  width: 100%;
+  aspect-ratio: 16/9;
  object-fit: cover;
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a99b146 and a096484.

📒 Files selected for processing (3)
  • src/components/UserPortal/PostCard/PostCard.module.css (0 hunks)
  • src/components/UserPortal/PostCard/PostCard.tsx (4 hunks)
  • src/style/app.module.css (2 hunks)
💤 Files with no reviewable changes (1)
  • src/components/UserPortal/PostCard/PostCard.module.css
✅ Files skipped from review due to trivial changes (1)
  • src/components/UserPortal/PostCard/PostCard.tsx
🔇 Additional comments (2)
src/style/app.module.css (2)

3536-3546: LGTM! Well-structured header styles.

The header styles follow best practices with proper use of flexbox, CSS variables, and consistent spacing.


3566-3584: LGTM! Accessible toggle button styles.

The toggle button styles follow accessibility best practices with proper hover and focus states.

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 28, 2024
Copy link

codecov bot commented Dec 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.92%. Comparing base (0973ad2) to head (505fbaf).
Report is 2 commits behind head on develop-postgres.

Additional details and impacted files
@@                  Coverage Diff                  @@
##           develop-postgres    #3006       +/-   ##
=====================================================
+ Coverage             29.27%   88.92%   +59.65%     
=====================================================
  Files                   300      321       +21     
  Lines                  7546     8408      +862     
  Branches               1646     1893      +247     
=====================================================
+ Hits                   2209     7477     +5268     
+ Misses                 5154      688     -4466     
- Partials                183      243       +60     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@palisadoes
Copy link
Contributor

  1. Merge your local branch with the latest upstream
  2. Commit and push to your origin
  3. It should fix some of the PR check failures
  4. We merged some recent updates that may have been after you initially submitted your PR

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

🧹 Nitpick comments (4)
src/style/app.module.css (4)

3610-3617: Consider improving card responsiveness and avoiding !important.

The card structure could be enhanced:

  1. Consider using media queries for responsive max-width on smaller screens.
  2. Avoid using !important for border/outline - try increasing specificity instead.
 .cardStyles {
   width: 100%;
-  max-width: 20rem;
+  max-width: min(20rem, 100%);
   background-color: var(--bs-white);
   padding: 0;
-  border: none !important;
-  outline: none !important;
+  border: 0;
+  outline: 0;
 }

+@media (max-width: 480px) {
+  .cardStyles {
+    max-width: 100%;
+  }
+}

3619-3667: Enhance header interactivity and maintainability.

Consider these improvements:

  1. Add hover state for creator name to improve interactivity.
  2. Use CSS variables for colors to maintain consistency.
 .creator p {
   margin-bottom: 0;
   font-weight: 500;
+  cursor: pointer;
+  transition: color 0.2s ease;
 }
+.creator p:hover {
+  color: var(--subtle-blue-grey);
+}

 .customToggle svg {
-  color: var(--bs-black);
+  color: var(--brown-color);
 }

3668-3701: Add fallbacks and loading states.

Consider these improvements:

  1. Add fallback for browsers that don't support line clamping.
  2. Add loading state for images.
 .cardTitlePostCard {
   --max-lines: 1;
   display: -webkit-box;
   overflow: hidden;
   -webkit-box-orient: vertical;
   -webkit-line-clamp: var(--max-lines);
+  /* Fallback for browsers that don't support line clamping */
+  @supports not (-webkit-line-clamp: var(--max-lines)) {
+    white-space: nowrap;
+    text-overflow: ellipsis;
+  }
 }

 .imageContainerPostCard {
   max-width: 100%;
+  position: relative;
+  min-height: 200px; /* Placeholder height while loading */
+  background-color: var(--grey-bg-color);
 }

3736-3787: Enhance modal scrolling experience.

The modal styles could be improved:

  1. Use dynamic height for comment container based on viewport.
  2. Add custom scrollbar styles for better UX.
 .commentContainer {
   overflow: auto;
-  max-height: 18rem;
+  max-height: min(18rem, 50vh);
   padding-bottom: 1rem;
+  scrollbar-width: thin;
+  scrollbar-color: var(--subtle-blue-grey) transparent;
 }
+
+.commentContainer::-webkit-scrollbar {
+  width: 6px;
+}
+
+.commentContainer::-webkit-scrollbar-track {
+  background: transparent;
+}
+
+.commentContainer::-webkit-scrollbar-thumb {
+  background-color: var(--subtle-blue-grey);
+  border-radius: 3px;
+}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a096484 and 7b06db6.

📒 Files selected for processing (2)
  • src/components/UserPortal/PostCard/PostCard.tsx (6 hunks)
  • src/style/app.module.css (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/UserPortal/PostCard/PostCard.tsx

src/style/app.module.css Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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: 0

🧹 Nitpick comments (5)
src/style/app.module.css (5)

3610-3617: Improve card responsiveness and accessibility

Consider these improvements:

  1. Make the width more responsive for smaller screens
  2. Preserve focus styles for keyboard navigation
 .cardStyles {
-  width: 100%;
-  max-width: 20rem;
+  width: clamp(15rem, 100%, 20rem);
   background-color: var(--bs-white);
   padding: 0;
-  border: none !important;
-  outline: none !important;
+  border: none;
+  outline: none;
 }

+.cardStyles:focus-visible {
+  outline: 2px solid var(--subtle-blue-grey);
+  outline-offset: 2px;
+}

3631-3648: Use CSS variables for consistent icon sizing

Consider extracting icon dimensions into CSS variables for better maintainability.

+:root {
+  --icon-size-md: 1.5rem;
+}

 .creator svg {
-  width: 1.5rem;
-  height: 1.5rem;
+  width: var(--icon-size-md);
+  height: var(--icon-size-md);
 }

3668-3671: Use CSS variables for consistent spacing

Consider using CSS variables for padding to maintain consistent spacing throughout the component.

+:root {
+  --spacing-sm: 0.5rem;
+}

 .cardBodyPostCard div {
-  padding: 0.5rem;
+  padding: var(--spacing-sm);
 }

3672-3675: Enhance image container styles

Consider adding styles to handle image aspect ratio and loading behavior.

 .imageContainerPostCard {
   max-width: 100%;
+  position: relative;
+  aspect-ratio: 16/9;
+  background-color: var(--grey-bg-color);
 }

3740-3792: Use CSS variables for modal dimensions

Consider extracting modal dimensions into CSS variables for better maintainability.

+:root {
+  --modal-comment-max-height: 18rem;
+  --modal-footer-padding: 0.5rem;
+}

 .commentContainer {
   overflow: auto;
-  max-height: 18rem;
+  max-height: var(--modal-comment-max-height);
   padding-bottom: 1rem;
 }

 .modalFooter {
   background-color: var(--bs-white);
   width: 100%;
-  padding-block: 0.5rem;
+  padding-block: var(--modal-footer-padding);
   display: flex;
   flex-direction: column;
   border-top: 1px solid var(--input-shadow-color);
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7b06db6 and 505fbaf.

📒 Files selected for processing (1)
  • src/style/app.module.css (2 hunks)
🔇 Additional comments (4)
src/style/app.module.css (4)

3619-3629: LGTM!

The card header implementation uses flexbox effectively with proper spacing and alignment.


3649-3667: LGTM!

The toggle button implementation properly handles default styles and interaction states.


3676-3685: LGTM!

The card title implementation properly handles text truncation using line clamping.


3686-3739: Button accessibility and interaction states were previously addressed

The implementation of button interaction states matches the previous review comment.

@palisadoes palisadoes merged commit 2e2e8ef into PalisadoesFoundation:develop-postgres Dec 29, 2024
15 checks passed
@hustlernik
Copy link
Contributor Author

@palisadoes May you please assign me a issue to work on, something in your mind that to be done next, because almost all the issues created are assigned. Thankyou.

@palisadoes
Copy link
Contributor

palisadoes commented Dec 29, 2024

Check slack

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.

2 participants