Skip to content

Commit

Permalink
πŸ”¨ Refactor(#83): νƒ€μž… μˆ˜μ • Key μˆ˜μ •
Browse files Browse the repository at this point in the history
  • Loading branch information
rhehfl committed Dec 8, 2024
1 parent 4c07989 commit 50705cb
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/features/store/ui/CartList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as S from './styles';
import type Item from '@type/Item';
import type CosmeticItem from '@/types/CosmeticItem ';
import StoreItem from './StoreItem';
const testItem: Item[] = [
const testItem: CosmeticItem[] = [
{
id: 1,
name: '해적 베레λͺ¨',
Expand Down Expand Up @@ -37,7 +37,7 @@ export default function CartList() {
<>
<S.StoreCartListWrapper>
{testItem.map(item => (
<StoreItem {...item} />
<StoreItem key={item.id} {...item} />
))}
</S.StoreCartListWrapper>
<S.PlaceLabel>총 1500포인트</S.PlaceLabel>
Expand Down
8 changes: 4 additions & 4 deletions src/features/store/ui/ItemContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as S from './styles';
import { useState } from 'react';
import type Item from '@type/Item';
import type CosmeticItem from '@/types/CosmeticItem ';
import StoreItem from './StoreItem';
const testItem: Item[] = [
const testItem: CosmeticItem[] = [
{
id: 1,
name: '해적 베레λͺ¨',
Expand Down Expand Up @@ -34,7 +34,7 @@ const testItem: Item[] = [
];

interface ItemContainerProps {
query: Item['category'];
query: CosmeticItem['category'];
}
export default function ItemContainer({ query }: ItemContainerProps) {
//μŠ€νƒ€μΌλ§μ„ μœ„ν•¨ μΆ”ν›„ μˆ˜μ • μ˜ˆμ •
Expand All @@ -43,7 +43,7 @@ export default function ItemContainer({ query }: ItemContainerProps) {
<>
<S.ItemContainer $category={query}>
{testItem.map(item => (
<StoreItem {...item} />
<StoreItem key={item.id} {...item} />
))}
</S.ItemContainer>
{/* μΆ”ν›„ ν•˜λ“œμ½”λ”© μˆ˜μ • */}
Expand Down
16 changes: 7 additions & 9 deletions src/features/store/ui/StoreItem.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import type Item from '@type/Item';
import type Item from '@/types/CosmeticItem ';
import * as S from './styles';
import { getImageUrl } from '@utils/getImageUrl';

export default function StoreItem({ id, name, image, category, cost }: Item) {
export default function StoreItem({ name, image, category, cost }: Item) {
return (
<>
<S.StoreItem key={id}>
<S.ItemLabel>{name}</S.ItemLabel>
<S.ItemImage $category={category} src={getImageUrl(image)} />
<S.ItemLabel>{cost} Point</S.ItemLabel>
</S.StoreItem>
</>
<S.StoreItem>
<S.ItemLabel>{name}</S.ItemLabel>
<S.ItemImage $category={category} src={getImageUrl(image)} />
<S.ItemLabel>{cost} Point</S.ItemLabel>
</S.StoreItem>
);
}
2 changes: 1 addition & 1 deletion src/features/store/ui/styles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Item from '@type/Item';
import Item from '@/types/CosmeticItem ';
import styled, { css } from 'styled-components';

export const ItemContainer = styled.ul<{ $category: Item['category'] }>`
Expand Down
9 changes: 5 additions & 4 deletions src/pages/store/Store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import ItemContainer from '@features/store/ui/ItemContainer';
import CartList from '@features/store/ui/CartList';
import MyCharacter from '@features/user/ui/MyCharacter';
import ProfileImage from '@features/user/ui/ProfileImage';
import Item from '@type/Item';
const buttonList: { label: string; name: Item['category'] }[] = [
import CosmeticItem from '@/types/CosmeticItem ';
const buttonList: { label: string; name: CosmeticItem['category'] }[] = [
{
label: 'μ˜μƒ',
name: 'clothes',
Expand All @@ -26,9 +26,10 @@ const buttonList: { label: string; name: Item['category'] }[] = [
label: '색상',
name: 'color',
},
];
] as const;
export default function Store() {
const [itemQuery, setItemQuery] = useState<Item['category']>('clothes');
const [itemQuery, setItemQuery] =
useState<CosmeticItem['category']>('clothes');
return (
<>
<globalS.Wrapper>
Expand Down
4 changes: 2 additions & 2 deletions src/types/Item.ts β†’ src/types/CosmeticItem .ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
interface Item {
interface CosmeticItem {
id: number;
name: string;
cost: number;
image: string;
category: 'clothes' | 'accessories' | 'profile' | 'color';
}
export default Item;
export default CosmeticItem;

0 comments on commit 50705cb

Please sign in to comment.