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: 마켓 표시 로직 추가 #87

Merged
merged 8 commits into from
Nov 20, 2024
41 changes: 22 additions & 19 deletions src/components/feedPage/Market.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,28 @@ const Market = ({market, onPress}: Props) => {
return (
<S.MarketWrapper onPress={() => onPress(market.id)}>
<S.MarketImageContainer>
{market.products.slice(0, 3).map(product => (
<S.MarketImageBox key={product.id}>
<S.MarketImage source={{uri: product.image}} />
<S.MenuGradation
colors={[
'rgba(0, 0, 0, 0.7)',
'rgba(0, 0, 0, 0.28)',
'rgba(0, 0, 0, 0)',
]}
locations={[0, 0.3, 0.7]}
start={{x: 0.5, y: 0}}
end={{x: 0.5, y: 1}}
/>
<S.MenuLabel numberOfLines={1}>{product.name}</S.MenuLabel>
<S.PriceLabel>
{product.discountPrice.toLocaleString()}원
</S.PriceLabel>
</S.MarketImageBox>
))}
{market.products
.filter(p => p.stock)
.slice(0, 3)
.map(product => (
<S.MarketImageBox key={product.id}>
<S.MarketImage source={{uri: product.image}} />
<S.MenuGradation
colors={[
'rgba(0, 0, 0, 0.7)',
'rgba(0, 0, 0, 0.28)',
'rgba(0, 0, 0, 0)',
]}
locations={[0, 0.3, 0.7]}
start={{x: 0.5, y: 0}}
end={{x: 0.5, y: 1}}
/>
<S.MenuLabel numberOfLines={1}>{product.name}</S.MenuLabel>
<S.PriceLabel>
{product.discountPrice.toLocaleString()}원
</S.PriceLabel>
</S.MarketImageBox>
))}
</S.MarketImageContainer>
<S.MarketInfoDiscription>
<S.MarketTitle>{market.name}</S.MarketTitle>
Expand Down
5 changes: 2 additions & 3 deletions src/components/map/MyLocationMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const MyLocationMap = ({
<S.MapWrapper width={windowWidth - 30}>
<S.MapView
center={{
zoom: 10,
zoom: 14,
tilt: 0,
//TODO: 에뮬레이터 확인위해 현재 인덱스1로 설정, 배포시 0으로 수정
latitude: cords[1]?.latitude || 37.582831666666664,
Expand All @@ -42,8 +42,7 @@ const MyLocationMap = ({
latitude: coord.latitude,
longitude: coord.longitude,
}}
//TODO: DB 주소 수정되면 인덱스 0인경우만 green 처리
pinColor={index === (0 || 1) ? 'green' : 'blue'}
pinColor={index === 0 ? 'green' : 'blue'}
caption={{
text: coord.marketName,
textSize: 12,
Expand Down
2 changes: 1 addition & 1 deletion src/components/orderPage/PaymentSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const PaymentSummary = ({originPrice, discountPrice}: Props) => {
/>
<PaymentSummaryItem
title="할인금액"
price={`-${discountPrice.toLocaleString()}원`}
price={`-${(originPrice - discountPrice).toLocaleString()}원`}
primary
/>
</S.PaymentSummaryItemList>
Expand Down
8 changes: 6 additions & 2 deletions src/screens/FeedScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Props = {

const FeedScreen = ({navigation}: Props) => {
const [marketList, setMarketList] = useState<MarketType[] | null>(null);

const [location, setLocation] = useState<{
userLatitude: number;
userLongitude: number;
Expand All @@ -39,7 +40,8 @@ const FeedScreen = ({navigation}: Props) => {
Alert.alert('가게내역받아오기실패.');
return;
}
setMarketList(res.markets);
// TODO: 필터링 로직 추가
setMarketList(res.markets.filter(market => market.products.length));
}, [location]);

// const getCurrentLocation = useCallback(() => {
Expand Down Expand Up @@ -138,7 +140,9 @@ const FeedScreen = ({navigation}: Props) => {
market.latitude >= -90 &&
market.latitude <= 90 &&
market.longitude >= -180 &&
market.longitude <= 180,
market.longitude <= 180 &&
market.products.length &&
market.products.some(p => p.stock),
)
.map(market => ({
marketName: market.name,
Expand Down
10 changes: 10 additions & 0 deletions src/screens/MarketDetailScreen/MarketDetailPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,17 @@ const MarketDetailPage = ({
}
});
};

const productsByTags = products.reduce(
(acc: {[key: string]: ProductType[]}, product) => {
if (product.tags.length === 0) {
if (!acc['메뉴']) {
acc['메뉴'] = [];
}
acc['메뉴'].push(product);
return acc;
}

product.tags.forEach(tagObj => {
const tag = tagObj.tagName;
if (!acc[tag]) {
Expand All @@ -90,6 +99,7 @@ const MarketDetailPage = ({
},
{},
);

const sortedProductsByTags = Object.entries(productsByTags)
.sort(([tagA, productsA], [tagB, productsB]) => {
if (tagA === '추천메뉴') return -1;
Expand Down
4 changes: 3 additions & 1 deletion src/screens/MarketDetailScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ const MarketDetailScreen = ({navigation, route}: Props) => {
pickupStartAt={marketDetail.pickupStartAt}
pickupEndAt={marketDetail.pickupEndAt}
address={marketDetail.address}
products={marketDetail.products}
products={marketDetail.products.filter(
product => product.productStatus !== 'HIDDEN',
)}
id={marketDetail.id}
specificAddress={marketDetail.specificAddress}
summary={marketDetail.summary}
Expand Down
14 changes: 0 additions & 14 deletions src/screens/MyPageScreen/UserMyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,6 @@ const UserMyPage = ({profile, refreshing, onRefresh}: UserMyPageProps) => {
isNotice={false}
/>
</S.ButtonContainer>
<S.ButtonContainer>
<NavigationTextButton
text="공지사항"
fontSize="20px"
onPress={handlePress}
isNotice={false}
/>
<NavigationTextButton
text="약관 및 정책"
fontSize="20px"
onPress={handlePress}
isNotice={false}
/>
</S.ButtonContainer>
</S.NoticeSection>
<S.BottomSectionContainer>
<S.BottomSection>
Expand Down
5 changes: 4 additions & 1 deletion src/types/Bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export type BucketType = {
products: ({count: number} & ProductType)[];
};

export type BucketProductType = Omit<ProductType, 'tags'> & {
export type BucketProductType = Omit<
ProductType,
'tags' | 'productStatus' | 'stock'
> & {
count: number;
};
2 changes: 2 additions & 0 deletions src/types/ProductType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export type ProductType = {
originPrice: number;
discountPrice: number;
tags: TagType[];
productStatus: 'IN_STOCK' | 'OUT_OF_STOCK' | 'HIDDEN';
stock: number;
};

export type TagType = {
Expand Down
Loading