diff --git a/src/background/index.ts b/src/background/index.ts index 1a9750f..017b0c7 100644 --- a/src/background/index.ts +++ b/src/background/index.ts @@ -273,7 +273,7 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { html, birthYear, gender, - allergies, + allergies: allergies || [], }), }) .then((res) => { diff --git a/src/components/productComponents/foodComponent.tsx b/src/components/productComponents/foodComponent.tsx index 596a3b8..bbb7291 100644 --- a/src/components/productComponents/foodComponent.tsx +++ b/src/components/productComponents/foodComponent.tsx @@ -42,10 +42,12 @@ export const FoodComponent = () => { useEffect(() => { const fetchData = async (vendorEl: Element) => { try { - const { birthYear, gender } = await chrome.storage.local.get([ - "birthYear", - "gender", - ]); + const { birthYear, gender, Allergies } = + await chrome.storage.local.get([ + "birthYear", + "gender", + "Allergies", + ]); const productId = window.location.href.match(/products\/(\d+)/)?.[1]; @@ -62,9 +64,11 @@ export const FoodComponent = () => { html: rawHtml, birthYear: Number(birthYear), gender: gender.toUpperCase(), - allergies: [], + allergies: Allergies || [], }; + console.log("[voim] FOOD API 요청 payload:", payload); + const res = await sendFoodDataRequest(payload); if (!res) throw new Error("응답 없음"); diff --git a/src/components/productComponents/healthComponent.tsx b/src/components/productComponents/healthComponent.tsx index ffbb67b..e7ec027 100644 --- a/src/components/productComponents/healthComponent.tsx +++ b/src/components/productComponents/healthComponent.tsx @@ -24,11 +24,17 @@ export const HealthComponent = () => { return; } - const { birthYear, gender } = await chrome.storage.local.get([ - "birthYear", - "gender", - ]); - console.log("[health api] 사용자 정보:", { birthYear, gender }); + const { birthYear, gender, Allergies } = + await chrome.storage.local.get([ + "birthYear", + "gender", + "Allergies", + ]); + console.log("[health api] 사용자 정보:", { + birthYear, + gender, + Allergies, + }); const rawHtml = targetEl.outerHTML .replace(/\sonerror=\"[^\"]*\"/g, "") @@ -46,7 +52,7 @@ export const HealthComponent = () => { html: rawHtml, birthYear: Number(birthYear), gender: gender?.toUpperCase() || "UNKNOWN", - allergies: [], + allergies: Allergies || [], }, }, (res) => { diff --git a/src/tabs/myInfo/components/AllergySelectForm.tsx b/src/tabs/myInfo/components/AllergySelectForm.tsx index 5bb1342..10c468a 100644 --- a/src/tabs/myInfo/components/AllergySelectForm.tsx +++ b/src/tabs/myInfo/components/AllergySelectForm.tsx @@ -4,10 +4,31 @@ import { BaseFillButton } from "@src/components/baseFillButton/component"; import { LeftArrowIcon } from "@src/components/icons/LeftArrowIcon"; import { RightArrowIcon } from "@src/components/icons/RightArrowIcon"; import { IconButton } from "@src/components/IconButton"; -import { useTheme } from "@src/contexts/ThemeContext"; import { ContentBox } from "@src/components/contentBox"; import { CloseIcon } from "@src/components/icons/CloseIcon"; +export enum AllergyType { + EGG = "EGG", // 계란 + MILK = "MILK", // 우유 + BUCKWHEAT = "BUCKWHEAT", // 메밀 + PEANUT = "PEANUT", // 땅콩 + SOYBEAN = "SOYBEAN", // 대두 + WHEAT = "WHEAT", // 밀 + PINE_NUT = "PINE_NUT", // 잣 + WALNUT = "WALNUT", // 호두 + CRAB = "CRAB", // 게 + SHRIMP = "SHRIMP", // 새우 + SQUID = "SQUID", // 오징어 + MACKEREL = "MACKEREL", // 고등어 + SHELLFISH = "SHELLFISH", // 조개류 + PEACH = "PEACH", // 복숭아 + TOMATO = "TOMATO", // 토마토 + CHICKEN = "CHICKEN", // 닭고기 + PORK = "PORK", // 돼지고기 + BEEF = "BEEF", // 쇠고기 + SULFITE = "SULFITE", // 아황산류 +} + const allergyData = { 식물성: ["메밀", "대두", "밀", "땅콩", "잣", "호두", "토마토", "복숭아"], 동물성: ["계란", "우유", "닭고기", "돼지고기", "쇠고기"], @@ -19,6 +40,28 @@ type AllergyCategory = keyof typeof allergyData; const ALL_CATEGORY = Object.keys(allergyData) as AllergyCategory[]; +const allergyNameToEnumMap: Record = { + 계란: AllergyType.EGG, + 우유: AllergyType.MILK, + 메밀: AllergyType.BUCKWHEAT, + 땅콩: AllergyType.PEANUT, + 대두: AllergyType.SOYBEAN, + 밀: AllergyType.WHEAT, + 잣: AllergyType.PINE_NUT, + 호두: AllergyType.WALNUT, + 게: AllergyType.CRAB, + 새우: AllergyType.SHRIMP, + 오징어: AllergyType.SQUID, + 고등어: AllergyType.MACKEREL, + 조개류: AllergyType.SHELLFISH, + 복숭아: AllergyType.PEACH, + 토마토: AllergyType.TOMATO, + 닭고기: AllergyType.CHICKEN, + 돼지고기: AllergyType.PORK, + 쇠고기: AllergyType.BEEF, + 아황산류: AllergyType.SULFITE, +}; + export function AllergySelectForm({ onComplete }: { onComplete?: () => void }) { const [selectedCategory, setSelectedCategory] = useState( ALL_CATEGORY[0], @@ -98,9 +141,8 @@ export function AllergySelectForm({ onComplete }: { onComplete?: () => void }) { ) } > -
+
{item} -
@@ -109,6 +151,10 @@ export function AllergySelectForm({ onComplete }: { onComplete?: () => void }) { { + const allergyEnumArray = selectedAllergies + .map((name) => allergyNameToEnumMap[name]) + .filter(Boolean) as AllergyType[]; + const menuButtons = document.querySelectorAll( '[data-testid="menubar-content"] button', ); @@ -124,7 +170,7 @@ export function AllergySelectForm({ onComplete }: { onComplete?: () => void }) { chrome.storage.local.set( { - Allergies: selectedAllergies, + Allergies: allergyEnumArray, }, () => { onComplete?.();