-
Notifications
You must be signed in to change notification settings - Fork 1
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(KL-178/좋아요 버튼 MutateAsync 적용): apply mutate async #52
Conversation
- kyInstance를 useKyQuery, useKyMutate로 변경하였습니다. - LikeButton의 UI 구성을 정리하였습니다. - IconTextButton을 재구성하였습니다.
- ShowHideButton의 이름을 CollapseButton으로 변경하였습니다. - 변경된 LikeButton, IconTextButton에 맞게 수정되었습니다.
Caution Review failedThe pull request is closed. WalkthroughThis pull request introduces a new Changes
Possibly related PRs
Suggested reviewers
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 7
Outside diff range and nitpick comments (4)
src/components/Button/IconTextButton.jsx (2)
6-15
: Approve changes with a suggestion for clarity.The updated function signature and props align well with Ant Design's Button component API. The removal of 'iconValue' and 'Icon' is consistent with the new approach.
However, the 'value' prop might be confusing as it's not a standard Button prop. Consider renaming it to something more descriptive, such as 'iconStyle' or 'iconConfig', to clarify its purpose.
Consider renaming the 'value' prop:
function IconTextButton({ - value = null, + iconStyle = null, type = 'text', // ... other props }) { // ... component logic }
31-37
: Approve PropTypes with a suggestion for improvement.The PropTypes have been correctly updated to reflect the new props and their possible values. The use of PropTypes.oneOf for enum-like props is a good practice.
However, the PropType for 'value' (PropTypes.shape({})) might be too permissive. Consider defining a more specific shape based on the expected structure of the icon style object.
Consider defining a more specific PropType for the 'value' prop:
IconTextButton.propTypes = { - value: PropTypes.shape({}), + value: PropTypes.shape({ + color: PropTypes.string, + size: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), + // Add other expected properties + }), // ... other propTypes }src/components/PreviewContent/PreviewContent.jsx (1)
Line range hint
1-91
: Summary of changes and suggestions for next stepsThe changes in this file appear to be part of a larger refactoring effort related to the Like button functionality, which aligns with the PR objective of applying MutateAsync. Here's a summary of the key points:
- The
LikeButton
component'siconSize
has been slightly adjusted.- The
likeContent
prop andisLiked
prop type have been commented out, suggesting a change in how the like status is managed.To ensure these changes are complete and consistent, please consider the following next steps:
- Verify that the removal of the
isLiked
prop is intentional and doesn't introduce any inconsistencies in the component's logic or its usage elsewhere.- If the commented-out code is no longer needed, remove it entirely to keep the codebase clean.
- Ensure that these changes are properly documented, especially if they affect the component's API or usage.
- Consider adding or updating unit tests to reflect these changes and maintain code coverage.
src/components/Button/LikeButton.jsx (1)
88-94
: Enhance accessibility by adding aria-label to the buttonTo improve accessibility, consider adding an
aria-label
to theIconTextButton
component to describe the action of the like button.Example:
<IconTextButton value={iconValue} icon={isLiked ? <FaHeart /> : <FaRegHeart />} handleClick={handleLike} + aria-label={isLiked ? 'Unlike product' : 'Like product'} />
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (6)
- src/components/Button/CollapseButton.jsx (1 hunks)
- src/components/Button/IconTextButton.jsx (1 hunks)
- src/components/Button/LikeButton.jsx (2 hunks)
- src/components/Button/ShowHideButton.jsx (0 hunks)
- src/components/PreviewContent/PreviewContent.jsx (2 hunks)
- src/pages/FeedPage/components/BasicFilter/CountrySection.jsx (2 hunks)
Files not reviewed due to no reviewable changes (1)
- src/components/Button/ShowHideButton.jsx
Additional comments not posted (12)
src/components/Button/CollapseButton.jsx (4)
1-10
: LGTM: Imports and component declaration look good.The imports are appropriate, and the component is well-structured with default prop values. The naming convention follows React best practices.
28-32
: LGTM: PropTypes are well-defined.The PropTypes are correctly specified for all props, with appropriate type checks and requirements. The flexibility allowed for
iconSize
is a good choice.
34-34
: LGTM: Export statement is correct.The component is properly exported as default, which is appropriate for a single component file.
1-34
: Overall, great job on the CollapseButton component!The component is well-structured, implements the collapse functionality correctly, and follows React best practices. The minor suggestions provided for optimization (memoization and DOM structure) can further improve its performance and maintainability.
src/components/Button/IconTextButton.jsx (2)
2-2
: LGTM: Ant Design Button import added.The addition of the Button import from 'antd' is appropriate for the refactoring of this component to use Ant Design's Button component.
17-26
: LGTM: Rendering logic updated correctly.The rendering logic has been successfully updated to use Ant Design's Button component. The props are correctly passed, and the use of IconContext.Provider for the icon is a good practice. The text rendering as a child of the Button is also correct.
src/components/PreviewContent/PreviewContent.jsx (2)
78-78
: Verify removal ofisLiked
propThe
isLiked
prop type has been commented out. This change raises several points:
- Does this mean the
PreviewContent
component no longer uses theisLiked
prop?- If so, have all instances where this prop was used been updated accordingly?
- If this prop is truly no longer needed, it would be cleaner to remove the commented-out line entirely.
Please verify that the removal of this prop type doesn't introduce any inconsistencies in the component's logic or its usage elsewhere in the application.
Let's check for any remaining usage of
isLiked
in this component:Verification successful
Removal of
isLiked
prop VerifiedThe
isLiked
prop type has been commented out, and our search confirms that there are no active usages ofisLiked
within thePreviewContent
component.
- Confirmation: The
PreviewContent
component no longer utilizes theisLiked
prop.- Recommendation: Remove the commented-out line
// isLiked: PropTypes.bool.isRequired,
to clean up the codebase.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for any remaining usage of isLiked in PreviewContent # Test: Search for isLiked within the PreviewContent component rg --type jsx 'isLiked' src/components/PreviewContent/PreviewContent.jsxLength of output: 100
Script:
#!/bin/bash # Description: Check for any remaining usage of isLiked in PreviewContent # Test: Search for isLiked within the PreviewContent component without specifying file type rg 'isLiked' src/components/PreviewContent/PreviewContent.jsxLength of output: 151
31-32
: Clarify the status of thelikeContent
propThe change in
iconSize
from "1.3rem" to "1.2rem" is noted and appears to be a minor design adjustment.However, the commented-out
likeContent
prop raises questions:
- Is this change related to the PR objective of applying MutateAsync to the Like button functionality?
- If so, why is it commented out? Is the implementation incomplete?
- If not needed, should this line be removed entirely?
Please provide clarification on the status and intent of this commented-out prop.
To understand the context better, let's check the
LikeButton
component:src/pages/FeedPage/components/BasicFilter/CountrySection.jsx (2)
6-6
: LGTM: Import statement for CollapseButton added correctly.The import statement for
CollapseButton
is correctly added and aligns with the component's usage inRegionCollapse
.
77-79
: Great improvement: Simplified state management with CollapseButton.The replacement of
ShowHideButton
withCollapseButton
and the removal of thetoggleRegion
function have resulted in cleaner, more declarative code. The state management is now more straightforward, withisOpen
andsetIsOpen
being passed directly toCollapseButton
. This change maintains the same functionality while improving code readability and maintainability.src/components/Button/LikeButton.jsx (2)
8-10
: Confirm the necessity of importingmethod
fromkyInstance
The
method
is imported from'../../hooks/kyInstance'
(line 8) but ensure that it aligns with the application's conventions and that all HTTP methods are standardized across the codebase.Please check if
method
is consistently used throughout the project or if it should be imported from a common constants file.
43-52
: Review necessity of manual fetching inuseEffect
and update dependenciesIn the
useEffect
hook (lines 43-52),fetchLikeContent()
is called to manually fetch the like status. However:
- The
useKyQuery
hook has theenabled
option set to!!userData
, which should automatically trigger data fetching whenuserData
becomes available.userData
is used withinuseEffect
but is not included in the dependency array.Consider the following:
- Verify if manual fetching is necessary: If
useKyQuery
automatically fetches the data whenuserData
is available, the manual call togetLike()
might be redundant.Run the following script to check if
useKyQuery
fetches data uponuserData
availability:
- Update the dependency array: If you decide to keep the
useEffect
, includeuserData
in the dependency array to ensure it runs whenuserData
changes.}, []) + }, [userData])
- icon의 속성을 정의하는 불필요한 useMemo를 제거하였습니다. - LikeButton의 handleLike 함수를 비동기 함수로 업데이트 하였습니다.
There was a problem hiding this 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
Outside diff range and nitpick comments (3)
src/components/Button/LikeButton.jsx (3)
1-1
: Remove commented-out import for better code clarityThe
useState
import is commented out and no longer used in this component. To improve code readability and maintainability, it's recommended to remove this commented-out import entirely.Apply the following change:
-import React from 'react' // useState, +import React from 'react'
Line range hint
39-63
: Well-implemented async handling and error managementThe refactoring of
handleLike
to an async function with proper error handling for bothpostLikeContent
anddeleteLikeContent
is a good improvement. This aligns well with the use of mutation hooks and ensures robust error management.However, there's still some cleanup to do:
Remove the commented-out
setIsLiked
line as it's no longer needed with the shift to server-side state management:- // setIsLiked((prev) => !prev)
70-77
: Consider removing unnecessary wrapper divThe
LikeButton
component is wrapped in adiv
that doesn't seem to add any styling or functionality. If this wrapper is indeed unnecessary, consider removing it to simplify the component structure.If the
div
is not needed, you can simplify the return statement like this:return ( <IconTextButton value={iconValue} icon={isLiked ? <FaHeart /> : <FaRegHeart />} handleClick={handleLike} /> );
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- src/components/Button/CollapseButton.jsx (1 hunks)
- src/components/Button/LikeButton.jsx (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- src/components/Button/CollapseButton.jsx
Additional comments not posted (5)
src/components/Button/LikeButton.jsx (5)
12-12
: Remove unusedlikeContent
propThe
likeContent
prop is commented out and no longer used in this component. To keep the code clean and maintainable, it's better to remove it entirely from both the component parameters and the PropTypes declaration.
16-37
: Excellent transition to server-side state managementThe replacement of
useState
withuseKyQuery
for managing theisLiked
state, along with the addition ofuseKyMutation
hooks for post and delete operations, is a significant improvement. This approach:
- Ensures data consistency with the server.
- Reduces the need for local state management.
- Simplifies data fetching and mutation logic.
The query configuration with proper key management and initial data is well-implemented.
65-68
: Use consistent color constants for better maintainabilityThe
iconValue
object uses inline color strings. For better maintainability and consistency across the application, consider defining these colors in a constants file or using theme variables.Example refactor:
import { COLORS } from '../../constants/colors'; // ... const iconValue = { color: isLiked ? COLORS.LIKE_ACTIVE : COLORS.LIKE_INACTIVE, size: iconSize, };
82-82
: Remove commented-out PropType for consistencyThe
likeContent
PropType is commented out and no longer used in the component. For consistency with the component parameters and to maintain clean code, it should be removed entirely.
Line range hint
1-87
: Overall excellent refactoring with minor cleanup neededThe
LikeButton
component has been significantly improved:
- Successful transition to server-side state management using
useKyQuery
anduseKyMutation
.- Improved error handling in like/unlike operations.
- Simplified component structure focusing on
IconTextButton
.These changes align well with the PR objectives of applying MutateAsync to the Like button functionality.
For final polish:
- Remove all commented-out code (imports, props, and state updates).
- Consider using color constants for better maintainability.
- Evaluate the necessity of the wrapper
div
in the return statement.Great work on this refactoring!
- 렌더링 시 Like Data를 fetch하지 않는 버그가 발생하여 수정하였습니다.
There was a problem hiding this 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
Outside diff range and nitpick comments (4)
src/components/Button/LikeButton.jsx (4)
1-17
: Clean up unused imports and consider future use of likeContentThe changes align well with the PR objectives of applying MutateAsync. However, there are a few points to consider:
- The
useState
import is commented out but no longer used. Consider removing it entirely.- The
likeContent
prop is commented out in both the function parameters and PropTypes.Remove the unused
useState
import:-import React, { - // useState, - useEffect, -} from 'react' +import React, { useEffect } from 'react'Regarding the
likeContent
prop, I understand from the learnings that it will be used in the future when the like status is fetched together in theProductList
. It's fine to keep it commented out for now, but consider adding a TODO comment to explain its future use.
20-30
: Approve useKyQuery implementation with a minor suggestionThe implementation of
useKyQuery
for fetching the like status is well done and aligns with the PR objectives. It effectively replaces the previoususeState
forisLiked
.The query configuration looks good, especially:
- Enabling the query only when
userData
is available- Setting
refetchOnWindowFocus
to false- Providing initial data
Consider destructuring the
data
property in theselect
function for better readability:- select: (data) => data.data.isLiked, + select: ({ data }) => data.isLiked,
Line range hint
55-78
: Approve handleLike implementation with minor suggestionsThe
handleLike
function has been well refactored to use async/await and properly handle the like/unlike actions. This implementation aligns with the PR objectives and addresses the previous review comment about handling async functions.Key improvements:
- Proper async/await usage
- Separate functions for posting and deleting likes
- User authentication check before proceeding
Consider these minor improvements:
- Remove the commented-out
setIsLiked
call as it's no longer needed with useKyQuery and useKyMutation.- You could simplify the function by removing the separate
postLikeContent
anddeleteLikeContent
functions:const handleLike = async () => { if (!userData) { alert('로그인이 필요합니다.') return } try { if (!isLiked) { await postLike() } else { await deleteLike() } } catch (error) { alert('문제가 발생했습니다. 잠시 후 다시 시도해주세요.') } }This simplification reduces code duplication and makes the function more concise.
Line range hint
96-104
: Acknowledge PropTypes changesThe PropTypes have been updated to reflect the changes in the component's parameters, which is good. The
likeContent
PropType is commented out, matching the learnings about its future use.The PropTypes for
productId
andiconSize
are correctly maintained.Consider adding a TODO comment to explain the future use of
likeContent
:LikeButton.propTypes = { // TODO: Uncomment when like status is fetched in ProductList // likeContent: PropTypes.bool.isRequired, productId: PropTypes.number.isRequired, iconSize: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), }This will help future developers understand why this prop is commented out and when it should be re-enabled.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- src/components/Button/LikeButton.jsx (2 hunks)
Additional context used
Learnings (1)
src/components/Button/LikeButton.jsx (1)
Learnt from: seoulyego PR: taco-official/klkl-client#52 File: src/components/Button/LikeButton.jsx:12-12 Timestamp: 2024-09-24T04:32:50.239Z Learning: In the `LikeButton` component, the `likeContent` prop will be used in the future when the like status is fetched together in the `ProductList`.
Additional comments not posted (1)
src/components/Button/LikeButton.jsx (1)
31-40
: Approve useKyMutation implementationsThe implementation of
useKyMutation
for bothpostLike
anddeleteLike
is well done and aligns perfectly with the PR objectives of applying MutateAsync.Key points:
- Correct use of HTTP methods (POST and DELETE)
- Proper URL construction using the
productId
- Consistent query key usage for cache invalidation
These mutations are set up correctly for optimistic updates, which should provide a smooth user experience when liking or unliking a product.
- like data의 fetching 동작의 의존성 배열에 userData를 추가하였습니다.
- IconTextButton에 div를 이용하여 wrapper를 추가하였습니다.
There was a problem hiding this 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
Outside diff range and nitpick comments (4)
src/components/Button/IconTextButton.jsx (4)
6-15
: LGTM: Updated props align with Ant Design Button APIThe new props and their default values are well-chosen and consistent with Ant Design's Button component API. This update provides more flexibility and customization options for the IconTextButton.
Consider using object destructuring with default values for a more concise prop declaration:
function IconTextButton({ value = null, type = 'text', shape = 'default', size = 'small', icon = null, iconPosition = 'start', handleClick = null, text = null } = {}) { // ... }This approach ensures that the function can be called without arguments, falling back to all default values.
17-28
: LGTM: Correct implementation of Ant Design ButtonThe rendering logic correctly uses the Ant Design Button component and passes all the necessary props. The use of IconContext.Provider for the icon is a good practice.
Consider removing the wrapping
<div>
if it's not necessary for styling or layout purposes. The Button component itself should be sufficient:return ( <Button type={type} shape={shape} size={size} icon={<IconContext.Provider value={value}>{icon}</IconContext.Provider>} onClick={handleClick} > {text} </Button> );This would result in a cleaner DOM structure.
33-39
: LGTM: PropTypes correctly updatedThe PropTypes have been accurately updated to reflect the new props and their allowed values. The use of PropTypes.oneOf() for restricting allowed values is a good practice.
Consider adding isRequired to props that are essential for the component to function correctly. For example, if the 'icon' prop is always expected to be provided, you could update its PropType like this:
icon: PropTypes.element.isRequired,This would help catch potential issues earlier in development if required props are not provided.
Line range hint
1-43
: LGTM: Overall component structure is clean and follows best practicesThe component's structure is well-organized, and the export statement is correctly maintained. The refactoring has successfully updated the component to use Ant Design's Button while preserving its original purpose as an IconTextButton.
As the component now wraps an Ant Design Button with some additional functionality, consider documenting this in a comment at the top of the file. This would help other developers understand the purpose and benefits of this wrapper component over using Ant Design's Button directly.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- src/components/Button/CollapseButton.jsx (1 hunks)
- src/components/Button/IconTextButton.jsx (1 hunks)
- src/components/Button/LikeButton.jsx (2 hunks)
Files skipped from review as they are similar to previous changes (2)
- src/components/Button/CollapseButton.jsx
- src/components/Button/LikeButton.jsx
Additional comments not posted (1)
src/components/Button/IconTextButton.jsx (1)
2-2
: LGTM: Appropriate import added for Ant Design ButtonThe addition of the Button import from 'antd' is correct and aligns with the refactoring to use Ant Design's Button component.
- IconTextButton에서 불필요한 wrapper를 제거하였습니다. - button 태그로 LikeButton의 포지션을 설정합니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋습니당
📌 연관된 이슈
KL-178/좋아요 버튼 MutateAsync 적용
📝 작업 내용
🌳 작업 브랜치명
KL-178/ApplyMutateAsync
📸 스크린샷 (선택)
💬 리뷰 요구사항 (선택)
Summary by CodeRabbit
Release Notes
New Features
CollapseButton
component for improved state management in UI interactions.Modifications
IconTextButton
to utilize Ant Design components, enhancing styling and functionality.LikeButton
to leverage data fetching for like status, improving performance and user experience.ShowHideButton
component to streamline functionality.PreviewContent
to reflect changes inLikeButton
and updated prop types accordingly.ShowHideButton
withCollapseButton
inCountrySection
, enhancing component interaction.PreviewContent
styling for better button positioning.