Skip to content

Commit 7f8ec26

Browse files
Merge pull request #32 from nerdinary-hackathon-8th/feat/#1
[feat] finalcommit
2 parents 9ba19a8 + f4dd7a5 commit 7f8ec26

2 files changed

Lines changed: 21 additions & 102 deletions

File tree

src/components/MyFridge/MyFridge.tsx

Lines changed: 11 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -37,89 +37,6 @@ const iconMapper = (category: string): JSX.Element => {
3737
return map[category] || <VegetableSVG />;
3838
};
3939

40-
// const mockItems: getFoodResponse[] = [
41-
// {
42-
// foodName: '대파',
43-
// foodCategory: '채소',
44-
// expirationDate: '2025-05-17',
45-
// storageMethod: '실외',
46-
// daysLeft: -3,
47-
// foodRegisterId: 1,
48-
// },
49-
// {
50-
// foodName: '달걀',
51-
// foodCategory: '유제품',
52-
// expirationDate: '2025-06-10',
53-
// storageMethod: '실외',
54-
// daysLeft: 27,
55-
// foodRegisterId: 2,
56-
// },
57-
// {
58-
// foodName: '우유',
59-
// foodCategory: '유제품',
60-
// expirationDate: '2025-05-10',
61-
// storageMethod: '냉장',
62-
// daysLeft: -4,
63-
// foodRegisterId: 3,
64-
// },
65-
// {
66-
// foodName: '만두',
67-
// foodCategory: '가공식품',
68-
// expirationDate: '2025-05-31',
69-
// storageMethod: '냉동',
70-
// daysLeft: 17,
71-
// foodRegisterId: 4,
72-
// },
73-
// {
74-
// foodName: '소고기',
75-
// foodCategory: '육류',
76-
// expirationDate: '2025-05-25',
77-
// storageMethod: '냉동',
78-
// daysLeft: 11,
79-
// foodRegisterId: 5,
80-
// },
81-
// {
82-
// foodName: '연어',
83-
// foodCategory: '해산물',
84-
// expirationDate: '2025-05-19',
85-
// storageMethod: '냉장',
86-
// daysLeft: 5,
87-
// foodRegisterId: 6,
88-
// },
89-
// {
90-
// foodName: '사과',
91-
// foodCategory: '과일',
92-
// expirationDate: '2025-05-21',
93-
// storageMethod: '실외',
94-
// daysLeft: 7,
95-
// foodRegisterId: 7,
96-
// },
97-
// {
98-
// foodName: '케첩',
99-
// foodCategory: '조미료',
100-
// expirationDate: '2026-01-01',
101-
// storageMethod: '실외',
102-
// daysLeft: 229,
103-
// foodRegisterId: 8,
104-
// },
105-
// {
106-
// foodName: '샐러드 밀키트',
107-
// foodCategory: '밀키트',
108-
// expirationDate: '2025-05-15',
109-
// storageMethod: '냉장',
110-
// daysLeft: 1,
111-
// foodRegisterId: 9,
112-
// },
113-
// {
114-
// foodName: '스낵칩',
115-
// foodCategory: '과자',
116-
// expirationDate: '2025-08-10',
117-
// storageMethod: '실외',
118-
// daysLeft: 88,
119-
// foodRegisterId: 10,
120-
// },
121-
// ];
122-
12340
const MyFridge = () => {
12441
const [expanded, setExpanded] = useState(false);
12542
const [selectedTab, setSelectedTab] = useState('전체');
@@ -128,13 +45,13 @@ const MyFridge = () => {
12845
const startYRef = useRef<number | null>(null);
12946
const [items, setItems] = useState<getFoodResponse[]>([]);
13047

48+
const fetchItems = async () => {
49+
const data = await getFoods();
50+
setItems(data);
51+
};
52+
13153
useEffect(() => {
132-
(async () => {
133-
const data = await getFoods();
134-
// const data = await mockItems;
135-
console.log(data);
136-
setItems(data);
137-
})();
54+
fetchItems();
13855
}, []);
13956

14057
const handleTouchStart = (e: React.TouchEvent) => {
@@ -150,9 +67,9 @@ const MyFridge = () => {
15067
startYRef.current = null;
15168
};
15269

153-
const handleConsume = (index: number, foodRegisterId: number) => {
154-
setItems((prev) => prev.filter((_, i) => i !== index));
155-
consumeFood(foodRegisterId);
70+
const handleConsume = async (foodRegisterId: number) => {
71+
await consumeFood(foodRegisterId);
72+
fetchItems();
15673
};
15774

15875
return (
@@ -187,6 +104,7 @@ const MyFridge = () => {
187104
(item) =>
188105
(selectedTab === '전체' || item.storageMethod === selectedTab) &&
189106
item.foodName.includes(searchTerm) &&
107+
item.isCompleted === '보관' &&
190108
(!showOnlyExpiring || item.daysLeft <= 7)
191109
)
192110
.map((item, idx) => {
@@ -200,7 +118,7 @@ const MyFridge = () => {
200118
<TitleContainer>
201119
<Title>{item.foodName}</Title>
202120
</TitleContainer>
203-
<CheckContainer onClick={() => handleConsume(idx, item.foodRegisterId)}>
121+
<CheckContainer onClick={() => handleConsume(item.foodRegisterId)}>
204122
<CheckSVG width={18} />
205123
</CheckContainer>
206124
</CardHeader>

src/controllers/api.Prop.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface getFoodResponse {
2020
storageMethod: string;
2121
daysLeft: number;
2222
foodRegisterId: number;
23+
isCompleted: string;
2324
}
2425

2526
export interface RegisterFoodRequest {
@@ -37,12 +38,12 @@ export interface RegisterFoodResponse {
3738
}
3839

3940
export interface getMyMbtiResponse {
40-
consumptionRate: string;
41-
fridgeComment: string;
42-
nearExpiredCount: number;
43-
level: number;
44-
typeName: string;
45-
foodBTI: string;
46-
foodBTIDetail: string;
47-
description: string;
48-
}
41+
consumptionRate: string;
42+
fridgeComment: string;
43+
nearExpiredCount: number;
44+
level: number;
45+
typeName: string;
46+
foodBTI: string;
47+
foodBTIDetail: string;
48+
description: string;
49+
}

0 commit comments

Comments
 (0)