Skip to content

Commit

Permalink
chore: update some likedUsers to likedUser (#135)
Browse files Browse the repository at this point in the history
- likedUsers: Pick<LikedUsers, 'id'>[] to likedUser
  • Loading branch information
hee-suh authored Sep 21, 2024
1 parent 45adc46 commit 9ff6796
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/app/map/[mapId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const MapMain = ({ params: { mapId } }: { params: { mapId: string } }) => {
if (selectedFilterNames.category === 'all') return true
if (
selectedFilterNames.category === 'like' &&
place.likedUsers?.some((likedUser) => likedUser.id === userData.id)
place.likedUser?.some((liked) => liked.id === userData.id)
)
return true
if (
Expand Down
13 changes: 5 additions & 8 deletions src/app/map/[mapId]/place-list-bottom-sheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ const PlaceListBottomSheet = forwardRef<
const getIsLike = (place: PlaceType): boolean => {
if (typeof userId === 'undefined') return false

if (place.likedUsers?.some((likedUser) => likedUser.id === userId))
return true
if (place.likedUser?.some((liked) => liked.id === userId)) return true

return false
}
Expand All @@ -54,11 +53,9 @@ const PlaceListBottomSheet = forwardRef<
p.place.id === place.place.id
? {
...p,
likedUsers: getIsLike(place)
? p.likedUsers?.filter(
(likedUser) => likedUser.id !== userId,
)
: [...(p.likedUsers ?? []), { id: userId }],
likedUser: getIsLike(place)
? p.likedUser?.filter((liked) => liked.id !== userId)
: [...(p.likedUser ?? []), { id: userId }],
}
: p,
),
Expand Down Expand Up @@ -145,7 +142,7 @@ const PlaceListBottomSheet = forwardRef<
pick={{
isLiked: getIsLike(place),
isMyPick: place.createdBy?.id === userId,
numOfLikes: place.likedUsers?.length || 0,
numOfLikes: place.likedUser?.length || 0,

onClickLike: (e) => {
e.preventDefault()
Expand Down
15 changes: 6 additions & 9 deletions src/app/search/[query]/result-search-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ const ResultSearchListBox = ({
const [likeInfoPlaces, setLikeInfoPlaces] = useState(
[...places].map((place) => ({
isLike:
!!place.likedUsers?.find((likedUser) => likedUser.id === user?.id) ||
false,
numOfLike: place.likedUsers?.length ?? 0,
!!place.likedUser?.find((liked) => liked.id === user?.id) || false,
numOfLike: place.likedUser?.length ?? 0,
})),
)

Expand All @@ -45,20 +44,18 @@ const ResultSearchListBox = ({
setLikeInfoPlaces(
places.map((place) => ({
isLike:
!!place.likedUsers?.find(
(likedUser) => likedUser.id === user?.id,
) || false,
numOfLike: place.likedUsers?.length ?? 0,
!!place.likedUser?.find((liked) => liked.id === user?.id) || false,
numOfLike: place.likedUser?.length ?? 0,
})),
)
}
}, [likeInfoPlaces.length, places, user?.id])

const calculateNumOfLike = (place: SearchPlace, isLikePlace: boolean) => {
const initialNumOfLike = place.likedUsers?.length || 0
const initialNumOfLike = place.likedUser?.length || 0

if (!user?.id) return initialNumOfLike
if (place.likedUsers?.find((likedUser) => likedUser.id === user.id)) {
if (place.likedUser?.find((liked) => liked.id === user.id)) {
if (isLikePlace) return initialNumOfLike
return initialNumOfLike - 1
}
Expand Down
8 changes: 3 additions & 5 deletions src/components/place/place-map-popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ const PlaceMapPopup = forwardRef<HTMLAnchorElement, PlaceMapPopupProps>(
const place = selectedPlace.place

const getNumOfLike = () => {
const initialNumOfLike = selectedPlace.likedUsers?.length || 0
const initialNumOfLike = selectedPlace.likedUser?.length || 0

if (!user?.id) return initialNumOfLike
if (
selectedPlace.likedUsers.some((likedUser) => likedUser.id === user.id)
) {
if (selectedPlace.likedUser.some((liked) => liked.id === user.id)) {
if (isLikePlace) return initialNumOfLike
return initialNumOfLike - 1
}
Expand Down Expand Up @@ -110,7 +108,7 @@ const PlaceMapPopup = forwardRef<HTMLAnchorElement, PlaceMapPopupProps>(
useEffect(() => {
if (!user) return
setIsLikePlace(
selectedPlace.likedUsers.some((likedUser) => likedUser.id === user.id),
selectedPlace.likedUser.some((liked) => liked.id === user.id),
)
}, [user, selectedPlace])

Expand Down
10 changes: 5 additions & 5 deletions src/constants/place.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const PLACE_LIST_DATA: PlaceType[] = [
},
],
comments: [{}],
likedUsers: [{ id: 1 }, { id: 2 }, { id: 3 }],
likedUser: [{ id: 1 }, { id: 2 }, { id: 3 }],
createdBy: {
id: 1,
nickname: 'foodie',
Expand Down Expand Up @@ -92,7 +92,7 @@ export const PLACE_LIST_DATA: PlaceType[] = [
},
],
comments: [{}],
likedUsers: [{ id: 2 }, { id: 3 }, { id: 4 }],
likedUser: [{ id: 2 }, { id: 3 }, { id: 4 }],
createdBy: {
id: 2,
nickname: 'sushiLover',
Expand Down Expand Up @@ -140,7 +140,7 @@ export const PLACE_LIST_DATA: PlaceType[] = [
},
],
comments: [{}],
likedUsers: [{ id: 3 }, { id: 4 }, { id: 5 }],
likedUser: [{ id: 3 }, { id: 4 }, { id: 5 }],
createdBy: {
id: 3,
nickname: 'meatLover',
Expand Down Expand Up @@ -188,7 +188,7 @@ export const PLACE_LIST_DATA: PlaceType[] = [
},
],
comments: [{}],
likedUsers: [{ id: 4 }, { id: 5 }, { id: 6 }],
likedUser: [{ id: 4 }, { id: 5 }, { id: 6 }],
createdBy: {
id: 4,
nickname: 'noodleFan',
Expand Down Expand Up @@ -237,7 +237,7 @@ export const PLACE_LIST_DATA: PlaceType[] = [
},
],
comments: [{}],
likedUsers: [{ id: 5 }, { id: 6 }, { id: 7 }],
likedUser: [{ id: 5 }, { id: 6 }, { id: 7 }],
createdBy: {
id: 5,
nickname: 'cafeLover',
Expand Down
4 changes: 2 additions & 2 deletions src/models/api/place.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface PlaceType {
}
tags: TagItem[]
comments: unknown[]
likedUsers: Pick<LikeUsers, 'id'>[]
likedUser: Pick<LikeUsers, 'id'>[]
createdBy: {
id: number
nickname: string
Expand All @@ -36,7 +36,7 @@ export interface SearchPlace {
tags: string[]
createdBy?: Creator
score: number
likedUsers: Pick<LikeUsers, 'id'>[]
likedUser: Pick<LikeUsers, 'id'>[]
}

export const isSearchPlace = (
Expand Down
14 changes: 14 additions & 0 deletions src/utils/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,24 @@ const proxy = {
get: (url: string): Promise<any> => client.public.get(`/proxy?url=${url}`),
}

const gpt = {
restaurants: {
recommend: {
test: {
get: (question: string, x: string, y: string): Promise<any> =>
client.secure.get(
`/gpt/restaurants/recommend/test?question=${question}&x=${x}&y=${y}`,
),
},
},
},
}

export const api = {
users,
maps,
search,
place,
proxy,
gpt,
} as const
2 changes: 1 addition & 1 deletion src/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const convertSearchPlaceToPlaceType = (
): PlaceType => {
return {
...searchPlace,
likedUsers: searchPlace.likedUsers ?? [],
likedUser: searchPlace.likedUser ?? [],
createdBy: {
id: -1,
nickname: '',
Expand Down

0 comments on commit 9ff6796

Please sign in to comment.