Skip to content

Commit

Permalink
[SKP-205-fix-bug] 자잘한 스타일 및 버그 수정 (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
yusiny authored Oct 22, 2024
2 parents b1ebf49 + fd1a0ca commit f7607a8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/components/Notification/NotificationItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {NotificationDTO} from '../../hooks/queries/notification/useGetNotificati
import {usePatchNotification} from '../../hooks/mutations/notification/usePatchNotification';
import {useQueryClient} from '@tanstack/react-query';
import {NOTIFICATION_KEYS} from '../../hooks/queries/QueryKeys';
import {formatDate, getCategoryName} from '../../utils/pushUtils';

interface NotificationItemProps {
item: NotificationDTO;
Expand Down Expand Up @@ -46,12 +47,14 @@ export default function NotificationItem({item}: NotificationItemProps) {
]}
onPress={handleOnPress}>
<View style={styles.topBox}>
<Text style={styles.subtitle}>{item.type}</Text>
<Text style={styles.subtitle}>{getCategoryName(item.type)}</Text>
{!item.isChecked && <View style={styles.flag} />}
</View>

<Text style={styles.title}>{item.title}</Text>
<Text style={styles.date}>{item.createdAt}</Text>
<Text style={styles.title}>
{item.title} {item.body}
</Text>
<Text style={styles.date}>{formatDate(item.createdAt)}</Text>
</Pressable>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/components/ResultSwiper/ResultItem/ResultItem.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const styles = StyleSheet.create({
...flexBox('row', 'flex-start', 'center'),
gap: 10,
flex: 1,
paddingEnd: 20,
},
boxItemWSpace: {...flexBox('row', 'space-between'), width: '100%'},
text: {
Expand Down
4 changes: 4 additions & 0 deletions src/screens/Detail/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ export default function Detail({navigation, route}: DetailProps) {
queryClient.invalidateQueries({
queryKey: LOCATION_KEYS.detail(String(id)),
});
queryClient.invalidateQueries({
queryKey: CATEGORY_KEYS.lists(),
});

navigation.pop();
bottomSheetRef.current?.close();
},
onError: e => {
Expand Down
40 changes: 40 additions & 0 deletions src/utils/pushUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,43 @@ export function parseNotificationData(data: string | object | undefined) {
console.error(e);
}
}

/**
* 카테고리 타입 별 이름 변환해 주는 함수
* @param type
*/
export function getCategoryName(type: string) {
if (type === 'userLocation') return '날짜 추천 받고 여행 떠나기';
else if (type === 'category') return '카테고리 리마인드';
else type;
}

/**
* ISO Date를 포맷팅해 주는 함수
* @param isoString
*/
export function formatDate(isoString: string): string {
try {
const date = new Date(isoString);

if (isNaN(date.getTime())) throw new Error('Invalid date');

const today = new Date();
const isToday =
date.getFullYear() === today.getFullYear() &&
date.getMonth() === today.getMonth() &&
date.getDate() === today.getDate();

if (isToday) {
return '오늘';
}

const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');

return `${year}.${month}.${day}`;
} catch (error) {
return isoString;
}
}

0 comments on commit f7607a8

Please sign in to comment.