diff --git a/.pnp.cjs b/.pnp.cjs index b07631f3..63f762cc 100755 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -31,7 +31,7 @@ const RAW_RUNTIME_STATE = ["@commitlint/cli", "npm:17.8.1"],\ ["@commitlint/config-conventional", "npm:17.8.1"],\ ["@next/eslint-plugin-next", "npm:14.2.13"],\ - ["@nf-team/core", "npm:2.0.3"],\ + ["@nf-team/core", "npm:3.0.1"],\ ["@nf-team/eslint-config", "virtual:e150514bd54e49453645b649d34785934ca8ee0d8d1b97d927fefcfad113b6cfb2743de5a3e60d87e6736690832351f19852f8ead68a73ba54254d666d6243a6#npm:3.3.0"],\ ["@nf-team/react", "virtual:e150514bd54e49453645b649d34785934ca8ee0d8d1b97d927fefcfad113b6cfb2743de5a3e60d87e6736690832351f19852f8ead68a73ba54254d666d6243a6#npm:2.6.0"],\ ["@nf-team/storage", "npm:1.0.1"],\ @@ -4336,10 +4336,10 @@ const RAW_RUNTIME_STATE = }]\ ]],\ ["@nf-team/core", [\ - ["npm:2.0.3", {\ - "packageLocation": "./.yarn/cache/@nf-team-core-npm-2.0.3-529577cd43-36c3bed764.zip/node_modules/@nf-team/core/",\ + ["npm:3.0.1", {\ + "packageLocation": "./.yarn/cache/@nf-team-core-npm-3.0.1-20c4cddc8a-16f0912284.zip/node_modules/@nf-team/core/",\ "packageDependencies": [\ - ["@nf-team/core", "npm:2.0.3"]\ + ["@nf-team/core", "npm:3.0.1"]\ ],\ "linkType": "HARD"\ }]\ @@ -16669,7 +16669,7 @@ const RAW_RUNTIME_STATE = ["@commitlint/cli", "npm:17.8.1"],\ ["@commitlint/config-conventional", "npm:17.8.1"],\ ["@next/eslint-plugin-next", "npm:14.2.13"],\ - ["@nf-team/core", "npm:2.0.3"],\ + ["@nf-team/core", "npm:3.0.1"],\ ["@nf-team/eslint-config", "virtual:e150514bd54e49453645b649d34785934ca8ee0d8d1b97d927fefcfad113b6cfb2743de5a3e60d87e6736690832351f19852f8ead68a73ba54254d666d6243a6#npm:3.3.0"],\ ["@nf-team/react", "virtual:e150514bd54e49453645b649d34785934ca8ee0d8d1b97d927fefcfad113b6cfb2743de5a3e60d87e6736690832351f19852f8ead68a73ba54254d666d6243a6#npm:2.6.0"],\ ["@nf-team/storage", "npm:1.0.1"],\ diff --git a/.yarn/cache/@nf-team-core-npm-2.0.3-529577cd43-36c3bed764.zip b/.yarn/cache/@nf-team-core-npm-2.0.3-529577cd43-36c3bed764.zip deleted file mode 100644 index f1c9ed04..00000000 Binary files a/.yarn/cache/@nf-team-core-npm-2.0.3-529577cd43-36c3bed764.zip and /dev/null differ diff --git a/.yarn/cache/@nf-team-core-npm-3.0.1-20c4cddc8a-16f0912284.zip b/.yarn/cache/@nf-team-core-npm-3.0.1-20c4cddc8a-16f0912284.zip new file mode 100644 index 00000000..7bdc4004 Binary files /dev/null and b/.yarn/cache/@nf-team-core-npm-3.0.1-20c4cddc8a-16f0912284.zip differ diff --git a/package.json b/package.json index 611adb92..a984b900 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ }, "homepage": "https://github.com/mbti-nf-team/unnamed-k-place-frontend#readme", "dependencies": { - "@nf-team/core": "^2.0.3", + "@nf-team/core": "^3.0.1", "@nf-team/react": "^2.6.0", "@nf-team/storage": "^1.0.1", "@react-google-maps/api": "^2.19.3", diff --git a/src/app/api/my/favorite-places/route.ts b/src/app/api/my/favorite-places/route.ts index 6ccce1f3..c9d6c7d7 100644 --- a/src/app/api/my/favorite-places/route.ts +++ b/src/app/api/my/favorite-places/route.ts @@ -1,6 +1,6 @@ import { NextRequest, NextResponse } from 'next/server'; -import { checkEmpty } from '@nf-team/core'; +import { ensureArray } from '@nf-team/core'; import QueryString from 'qs'; import api, { FetchError } from '@/lib/apis'; @@ -46,7 +46,7 @@ export async function GET(request: NextRequest) { const googleDetails = await fetchAllPlaceDetails({ placeIds }); const favoritePlaces = googleDetails.map((detail, index) => { - const placePhotoUrls = checkEmpty(detail.result.photos) + const placePhotoUrls = ensureArray(detail.result.photos) .map((photo) => getPlacePhotoUrl(photo.getUrl(), 500)) .filter((photoUrl) => !!photoUrl); diff --git a/src/app/api/search/nearby/places/route.ts b/src/app/api/search/nearby/places/route.ts index a2cbcfd0..d660feb7 100644 --- a/src/app/api/search/nearby/places/route.ts +++ b/src/app/api/search/nearby/places/route.ts @@ -1,6 +1,6 @@ import { NextRequest, NextResponse } from 'next/server'; -import { checkEmpty } from '@nf-team/core'; +import { ensureArray } from '@nf-team/core'; import { fetchAllSettledSearchNaverBlogs, getGoogleNearbySearch } from '@/app/api/handler'; import { FetchError } from '@/lib/apis'; @@ -35,7 +35,7 @@ export async function GET(request: NextRequest) { location: [lat, lng], }); - const placesResult = filteredPlaces(checkEmpty(places?.results)); + const placesResult = filteredPlaces(ensureArray(places?.results)); const placeName = placesResult.filter((place) => !!place?.name).map((place) => place.name); const searchBlogPosts = await fetchAllSettledSearchNaverBlogs({ placeName }); diff --git a/src/app/api/search/places/[placeId]/route.ts b/src/app/api/search/places/[placeId]/route.ts index 3d18ad81..f23e5f25 100644 --- a/src/app/api/search/places/[placeId]/route.ts +++ b/src/app/api/search/places/[placeId]/route.ts @@ -1,6 +1,6 @@ import { NextRequest, NextResponse } from 'next/server'; -import { checkEmpty } from '@nf-team/core'; +import { ensureArray } from '@nf-team/core'; import { fetchNaverSearchBlog, getGooglePlaceDetails, getPlacePhotoUrl } from '@/app/api/handler'; import { FetchError } from '@/lib/apis'; @@ -62,7 +62,7 @@ export async function GET(request: NextRequest) { const country = address_components ?.find((address) => address.types.includes(PlaceType2.country)); - const placePhotoUrls = checkEmpty(placeDetails.result.photos) + const placePhotoUrls = ensureArray(placeDetails.result.photos) .map((photo) => getPlacePhotoUrl(photo.photo_reference, 500)) .filter((photoUrl) => !!photoUrl); diff --git a/src/app/api/search/places/route.ts b/src/app/api/search/places/route.ts index 73858fe0..96b6cbf6 100644 --- a/src/app/api/search/places/route.ts +++ b/src/app/api/search/places/route.ts @@ -1,6 +1,6 @@ import { NextRequest, NextResponse } from 'next/server'; -import { checkEmpty } from '@nf-team/core'; +import { ensureArray } from '@nf-team/core'; import { FetchError } from '@/lib/apis'; import { filteredPlaces } from '@/utils'; @@ -37,14 +37,14 @@ export async function GET(request: NextRequest) { location: (lat && lng) ? [lat, lng] : undefined, }); - const placesResult = filteredPlaces(checkEmpty(places?.results)); + const placesResult = filteredPlaces(ensureArray(places?.results)); const placeName = placesResult.filter((place) => !!place?.name).map((place) => place.name); const searchBlogPosts = await fetchAllSettledSearchNaverBlogs({ placeName }); const response = placesResult.map((place, index) => ({ ...place, - photoUrls: checkEmpty(place.photos) + photoUrls: ensureArray(place.photos) .map((photo) => getPlacePhotoUrl(photo.photo_reference, 500)) .filter((photoUrl) => !!photoUrl), searchBlogPost: searchBlogPosts[index], diff --git a/src/app/place/[id]/page.tsx b/src/app/place/[id]/page.tsx index 4b6d2d4e..75d95be0 100644 --- a/src/app/place/[id]/page.tsx +++ b/src/app/place/[id]/page.tsx @@ -1,7 +1,7 @@ import { Metadata, ResolvingMetadata } from 'next'; import { cookies } from 'next/headers'; -import { checkEmpty } from '@nf-team/core'; +import { ensureArray } from '@nf-team/core'; import { getGooglePlaceDetails, getPlacePhotoUrl } from '@/app/api/handler'; import { metadata } from '@/app/page'; @@ -52,7 +52,7 @@ export async function generateMetadata( ); const previousParent = await parent; - const previousImages = checkEmpty(previousParent.openGraph?.images); + const previousImages = ensureArray(previousParent.openGraph?.images); const images = thumbnailPhotoUrl ? [ { url: thumbnailPhotoUrl, diff --git a/src/components/common/PlaceItem/index.tsx b/src/components/common/PlaceItem/index.tsx index d53313c8..aa2c7cfe 100644 --- a/src/components/common/PlaceItem/index.tsx +++ b/src/components/common/PlaceItem/index.tsx @@ -4,7 +4,7 @@ import { memo, MouseEvent } from 'react'; import Image from 'next/image'; -import { checkEmpty, checkNumber } from '@nf-team/core'; +import { ensureArray, getNumberOrDefault, isEmpty } from '@nf-team/core'; import { useActionKeyEvent } from '@nf-team/react'; import clsx from 'clsx'; @@ -39,7 +39,7 @@ function PlaceItem({ }: Props) { const onKeyDown = useActionKeyEvent(['Enter', 'NumpadEnter'], (_, id) => onClick?.(id)); - const isOnePhoto = checkEmpty(photoUrls).length === 1; + const isOnePhoto = ensureArray(photoUrls).length === 1; const removeFavoritePlace = (e: MouseEvent) => { e.preventDefault(); @@ -59,7 +59,7 @@ function PlaceItem({ className={styles.placeItem} role="menuitem" > - {!!checkEmpty(photoUrls).length && ( + {!isEmpty(photoUrls) && (
{photoUrls.map((photo, index) => ( ({ )}
-
{checkNumber(rating)}
- -
{`(${checkNumber(userRatingsTotal)})`}
+
{getNumberOrDefault(rating)}
+ +
{`(${getNumberOrDefault(userRatingsTotal)})`}
{!!settledSearchBlogPost && ( -
{`네이버 검색결과 ${numberWithComma(checkNumber(settledSearchBlogPost?.total_count))}개`}
+
{`네이버 검색결과 ${numberWithComma(getNumberOrDefault(settledSearchBlogPost?.total_count))}개`}
)} {isSavedPlace && (
diff --git a/src/components/common/StarRating/index.tsx b/src/components/common/StarRating/index.tsx index dc8f9095..02cae212 100644 --- a/src/components/common/StarRating/index.tsx +++ b/src/components/common/StarRating/index.tsx @@ -1,6 +1,6 @@ import { useMemo } from 'react'; -import { checkNumber, generateArrayOfNumber } from '@nf-team/core'; +import { createNumberArray, getNumberOrDefault } from '@nf-team/core'; import clsx from 'clsx'; import { @@ -20,7 +20,7 @@ type Props = { function StarRating({ rating, maxRating = 5, type, className, size = 'large', }: Props) { - const numberRating = checkNumber(rating); + const numberRating = getNumberOrDefault(rating); const fillStarCount = Math.floor(numberRating); const detailClassName = clsx({ @@ -58,11 +58,11 @@ function StarRating({ return (
- {generateArrayOfNumber(fillStarCount).map((key) => ( + {createNumberArray(fillStarCount).map((key) => ( ))} {fillStarCount < maxRating && extraStar} - {generateArrayOfNumber(maxRating - (fillStarCount + 1)).map((key) => ( + {createNumberArray(maxRating - (fillStarCount + 1)).map((key) => ( ))}
diff --git a/src/components/map/FavoritePlaces/index.tsx b/src/components/map/FavoritePlaces/index.tsx index c4865365..7504bf29 100644 --- a/src/components/map/FavoritePlaces/index.tsx +++ b/src/components/map/FavoritePlaces/index.tsx @@ -2,7 +2,7 @@ import { useCallback } from 'react'; import { useRouter, useSearchParams } from 'next/navigation'; -import { checkNumber } from '@nf-team/core'; +import { getNumberOrDefault } from '@nf-team/core'; import Button from '@/components/common/Button'; import PlaceItem from '@/components/common/PlaceItem'; @@ -33,7 +33,7 @@ function FavoritePlaces({ isMenu }: Props) { }); const { mutate: removeFavoritePlaceMutate } = useRemoveFavoritePlaceMutation(); - const favoritePlaceCount = checkNumber(favoritePlaces?.pages?.[0].total_count); + const favoritePlaceCount = getNumberOrDefault(favoritePlaces?.pages?.[0].total_count); const onClickPlaceItem = useCallback((placeId: string) => { router.push(`/place/${placeId}`); diff --git a/src/components/map/MapContainer/index.tsx b/src/components/map/MapContainer/index.tsx index c2c48ddc..9ce08189 100644 --- a/src/components/map/MapContainer/index.tsx +++ b/src/components/map/MapContainer/index.tsx @@ -6,7 +6,7 @@ import { import { useRouter, useSearchParams } from 'next/navigation'; -import { checkEmpty, checkNumber, isEmpty } from '@nf-team/core'; +import { ensureArray, getNumberOrDefault, isEmpty } from '@nf-team/core'; import { useGoogleMap } from '@react-google-maps/api'; import QueryString from 'qs'; @@ -110,10 +110,10 @@ function MapContainer({ defaultCountryCode, defaultLocation, user }: Props) { }; const isCenterChange = () => { - const isEqualLat = checkNumber(searchResultCenter.lat).toFixed(3) - === checkNumber(centerLatitude).toFixed(3); - const isEqualLng = checkNumber(searchResultCenter.lng).toFixed(3) - === checkNumber(centerLongitude).toFixed(3); + const isEqualLat = getNumberOrDefault(searchResultCenter.lat).toFixed(3) + === getNumberOrDefault(centerLatitude).toFixed(3); + const isEqualLng = getNumberOrDefault(searchResultCenter.lng).toFixed(3) + === getNumberOrDefault(centerLongitude).toFixed(3); if (isEqualLat && isEqualLng) { return true; @@ -122,7 +122,7 @@ function MapContainer({ defaultCountryCode, defaultLocation, user }: Props) { return false; }; - const placesWithSearchResult = useMemo(() => checkEmpty(places?.pages) + const placesWithSearchResult = useMemo(() => ensureArray(places?.pages) .filter((page) => !!page.results?.length && page.status === 'OK') .flatMap((page) => page.results), [places]); diff --git a/src/components/place/PlaceDetail/index.tsx b/src/components/place/PlaceDetail/index.tsx index b65e01a3..a3e7c595 100644 --- a/src/components/place/PlaceDetail/index.tsx +++ b/src/components/place/PlaceDetail/index.tsx @@ -4,7 +4,7 @@ import { useCallback, useMemo, useRef } from 'react'; import { notFound, useRouter } from 'next/navigation'; -import { checkEmpty, checkNumber } from '@nf-team/core'; +import { ensureArray, getNumberOrDefault } from '@nf-team/core'; import clsx from 'clsx'; import { motion } from 'framer-motion'; @@ -71,11 +71,11 @@ function PlaceDetail({ const isVisibleLoading = isLoading || !placeDetail; - const googleReviewCount = checkNumber(placeDetail?.reviews?.length); - const koreanReviewCount = checkEmpty(placeDetail?.reviews).filter(({ + const googleReviewCount = getNumberOrDefault(placeDetail?.reviews?.length); + const koreanReviewCount = ensureArray(placeDetail?.reviews).filter(({ language, original_language, }) => (original_language ? original_language === 'ko' : language === 'ko')).length; - const blogCount = checkNumber(placeDetail?.searchBlogPost?.total_count); + const blogCount = getNumberOrDefault(placeDetail?.searchBlogPost?.total_count); const goToExternalLink = (eventName: EventName) => (url?: string) => sendEvent({ name: eventName, @@ -240,7 +240,7 @@ function PlaceDetail({
- {placeDetail?.rating ? checkNumber(placeDetail?.rating).toFixed(1) : '별점 없음'} + {placeDetail?.rating ? getNumberOrDefault(placeDetail?.rating).toFixed(1) : '별점 없음'}
@@ -272,11 +272,11 @@ function PlaceDetail({
- {checkEmpty(placeDetail?.searchBlogPost?.posts).map(({ + {ensureArray(placeDetail?.searchBlogPost?.posts).map(({ title, description, link, thumbnail, }) => ( const getScrollState = useCallback(() => { if (rootRef?.current) { return { - scrollTop: checkNumber(rootRef.current?.scrollTop), + scrollTop: getNumberOrDefault(rootRef.current?.scrollTop), scrollHeight: rootRef.current.scrollHeight, clientHeight: rootRef.current.clientHeight, }; } return { - scrollTop: checkNumber(document.scrollingElement?.scrollTop), + scrollTop: getNumberOrDefault(document.scrollingElement?.scrollTop), scrollHeight: document.documentElement.scrollHeight, clientHeight: document.documentElement.clientHeight, }; diff --git a/yarn.lock b/yarn.lock index 24bccdc0..79452f21 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2678,10 +2678,10 @@ __metadata: languageName: node linkType: hard -"@nf-team/core@npm:^2.0.3": - version: 2.0.3 - resolution: "@nf-team/core@npm:2.0.3" - checksum: 10/36c3bed76489faf4e48092e8172ddcc29e38abde910503142a6d00d032ebf468a5bd97a2b017d9fbd37f480e53250c9ee4883dab98e1b8f7c1cef537b7c903e2 +"@nf-team/core@npm:^3.0.1": + version: 3.0.1 + resolution: "@nf-team/core@npm:3.0.1" + checksum: 10/16f0912284bebaf66245d0a4050f02ad97f7dfaa22be7d25b92dd79af5247caae3fe7651ed76aee4add835a4362209572a33c1a56d0a2aaa6031543fd0e71992 languageName: node linkType: hard @@ -12284,7 +12284,7 @@ __metadata: "@commitlint/cli": "npm:^17.4.3" "@commitlint/config-conventional": "npm:^17.4.3" "@next/eslint-plugin-next": "npm:^14.2.13" - "@nf-team/core": "npm:^2.0.3" + "@nf-team/core": "npm:^3.0.1" "@nf-team/eslint-config": "npm:^3.3.0" "@nf-team/react": "npm:^2.6.0" "@nf-team/storage": "npm:^1.0.1"