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(Image&Location): swiper, auto update location #13

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 179 additions & 11 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
"@radix-ui/react-toast": "^1.1.5",
"@tanstack/react-query": "^4.36.1",
"@tanstack/react-query-devtools": "^4.35.7",
"@types/swiper": "^6.0.0",
"appwrite": "^13.0.0",
"attr-accept": "^2.2.2",
"axios": "^1.6.8",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"date-fns": "^3.6.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-tailwindcss": "^3.13.0",
"gsap": "^3.12.5",
"lucide-react": "^0.105.0-alpha.4",
"next-auth": "^4.24.7",
"prettier": "^3.0.3",
Expand All @@ -39,13 +42,15 @@
"react-slick": "^0.30.2",
"slick-carousel": "^1.8.1",
"solidjs-dropzone": "^1.0.0",
"styled-components": "^6.1.8",
"swiper": "^11.1.0",
"tailwind-merge": "^1.14.0",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.22.4"
},
"devDependencies": {
"@types/node": "^20.8.0",
"@types/react": "^18.2.15",
"@types/react": "^18.2.74",
"@types/react-dom": "^18.2.7",
"@types/react-slick": "^0.23.13",
"@typescript-eslint/eslint-plugin": "^6.0.0",

Choose a reason for hiding this comment

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

This patch appears to be an update to a project's package.json file, which manages project dependencies. Here are some thoughts on the changes:

  1. Added Dependencies:

    • @types/swiper: This addition is fine if you're planning to use Swiper in your project and need TypeScript type definitions for it.
    • axios: A prominent HTTP client for browsers and Node.js. Since it's being added, make sure that you are indeed going to use it or replace an existing solution with it to avoid unnecessary bloat.
    • gsap: An animation library. It should be added only if there is a necessity for complex animations that cannot be easily accomplished with CSS animations.
    • styled-components: A library used to style React components using tagged template literals. Ensure that this addition aligns with the project's architecture and there is no overlap with other styling solutions like TailwindCSS that might lead to confusion or conflicts.
    • swiper: Necessary for if you're adding carousels and want to use the Swiper library.
  2. Version Updates:

    • The versions of several packages have been updated. This is typically good, assuming that the updates do not introduce breaking changes and the rest of the codebase is compatible with these new versions.
    • Notable major version changes could involve backward-incompatible changes; you'll want to consult the changelog for each of these updates to ensure that they do not affect your implementation.
  3. Potential Risks/Concerns:

    • Mixing Styling Solutions: As mentioned, adding styled-components when you already have TailwindCSS could cause some confusion about how styling is handled throughout the project. You'd want to make sure there's consensus from the team before choosing multiple styling approaches.
    • Unused Dependencies: Adding dependencies that are not used within the project can contribute to longer install times, larger bundle sizes, and potential maintenance overhead. Always verify the need before including a new package.
    • Upgrading Types for React (@types/react): This change indicates an increment in the patch version. Although minor, it’s always best practice to ensure no typing issues were introduced that can affect the build process or develop time experience.
  4. General Suggestions:

    • Verify breaking changes: For every upgraded package, check that there are no breaking changes affecting your project. Have tests or perform manual testing as needed.
    • Consider deduplicating: If there are similar libraries that serve the same purpose (like axios and another HTTP library), consider keeping just one to reduce duplication.
    • Where is react-query-devtools? It was in the original list but not in the modified one, which might be intended, or it might have been removed by mistake.
    • Ensure compatibility: If swiper and styled-components are new to the project, ensure that their versions are compatible with other dependencies and the current codebase.

To wrap it up, reviewing the patch doesn't turn up immediate red flags, but it's important to audit these additions and version bumps in the context of the whole project to ensure compatibility and necessity.

Expand Down
38 changes: 38 additions & 0 deletions frontend/src/components/StorySwiper/StorySwiper.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* .swiper {
width: 30%;
height: 30%;
} */

.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;

/* Center slide text vertically */
display: flex;
justify-content: center;
align-items: center;
}

.swiper-slide img {
display: block;
object-fit: cover;
}

.mySwiper {
width: 500px !important; /* 或者任何具体的宽度值 */
height: 500px !important; /* 根据你的需求调整高度 */
}

.mySwiper img {
width: 100%; /* 图片宽度占满容器 */
height: 100%; /* 图片高度占满容器 */
object-fit: cover; /* 保持宽高比,可能会裁剪图片 */
}

@media (max-width: 600px) {
.mySwiper {
width: 350px !important;
height: 200px !important; /* 在小屏幕上减小高度 */
}
}

Choose a reason for hiding this comment

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

This code patch appears to be CSS intended for styling elements related to a Swiper slider, a popular library used for creating slideshows and carousels on websites. Here's the review covering potential issues and opportunities for improvement:

General Observations:

  1. Commented-out Code: The first block of styles is commented out. If this code is unnecessary, it's usually best to remove it to reduce clutter.

  2. Use of !important: The usage of !important is generally discouraged unless absolutely necessary because it makes debugging and maintaining the code harder by breaking the natural cascading in your style sheets.

  3. Consistency in Language Comments: Comments are written in Chinese which is perfectly fine if the development team uses Chinese. However, if the team is international, it might be better to stick to English to maintain consistency.

  4. Responsive Design Consideration: The media query adjusts the size of .mySwiper based on the screen width, which is good for responsive design. However, depending on the actual layout requirements, more breakpoints or different strategies (like using percentages or vw/vh units) might be needed for better responsiveness across various devices.

Specific Suggestions for Improvement:

  1. Removing !important if possible: Refractor the specificity of your selectors or the order of the CSS to avoid using !important. This will make it easier to understand and overwrite styles when needed without resorting to more !important tags.

  2. Accessibility Considerations: Ensure that text within .swiper-slide elements has sufficient contrast with its background (#fff) for readability. Also, consider including descriptive alt texts for images for screen readers.

  3. Performance: Direct modification of elements' widths and heights can lead to layout shifts, affecting user experience. It’s good practice to optimize images for the web to ensure they load faster without sacrificing quality, especially since object-fit: cover may result in downloading larger images than necessary.

  4. Viewport Units for Responsiveness: Instead of switching to fixed sizes at different breakpoints, consider using viewport units (vw, vh, vmin, vmax) for the dimensions of .mySwiper to make it more fluid and adaptable to various screen sizes without the need for multiple breakpoints.

  5. Verifying object-fit Support: While object-fit is widely supported in modern browsers, verify its compatibility if your audience includes users on older browsers where object-fit may not work as expected.

Conclusion:

Overall, this CSS snippet targets specific styling for a Swiper component. While it has a good base, focusing on avoiding !important when possible, improving responsiveness with more fluid units, ensuring accessibility, and maintaining clean, commented-out-free code could further refine the approach.

Loading