feat: 10/21 회의 반영 — 공유 링크·로그인 없이 댓글·구글 로그인만, 히어로·오늘의 각 좋아요·댓글, 히어로 오늘/내일 스위치, 단풍 지도 65곳·3단계
- 공유: 이미지와 함께 고정 URL을 넘기고 링크도 클립보드에 복사 - 로그인 창은 구글만, 댓글은 로그인 없이 '동네 익명'(링크·전화번호 막기, IP당 하루 20개, 같은 IP만 지우기) - 히어로·오늘의 각 카드에 좋아요·댓글 (PostType HERO·TODAY_GAK) - 히어로 오늘/내일 스위치: 내일 구간별 날씨 점수·기온·최저최고·습도·1위 각, /v1/weather/today?day=tomorrow - 단풍 지도: 단풍 그림 지도, 단풍 전·첫 단풍·절정, 단풍잎·은행잎, 명소 65곳(산림청 예측 + 가까운 지점 날짜) - 하단 탭 바 불투명 (홈 바 자리로 글이 비치지 않게) - 사람 글 동네 우선 정렬·내 글 목록, 내 각 '있는 각에서 불러오기' - 댓글 표 user_id NULL 허용·ip_hash·region_name (운영 DB ALTER 필요)
This commit is contained in:
1 parent
14f24d1ab0
commit
93e041bb91
46 files changed
+1820
-337
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import { useState } from 'react'
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { likePostMutation, unlikePostMutation } from '../api/client/@tanstack/react-query.gen'
|
||||
import type { PostReaction, ResFeed } from '../api/client/types.gen'
|
||||
|
||||
export type PinnedKey = 'hero_post' | 'gak_post'
|
||||
|
||||
/** 히어로·오늘의 각처럼 포스트 틀이 아닌 카드의 좋아요. 화면을 먼저 바꾸고 실패하면 되돌린다 */
|
||||
export function usePinnedLike(key: PinnedKey, r?: PostReaction | null) {
|
||||
const queryClient = useQueryClient()
|
||||
const like = useMutation(likePostMutation())
|
||||
const unlike = useMutation(unlikePostMutation())
|
||||
const [failed, setFailed] = useState(false)
|
||||
const liked = !!r?.liked
|
||||
const count = r?.like_count ?? 0
|
||||
const patch = (values: Partial<PostReaction>) =>
|
||||
queryClient.setQueriesData<ResFeed>({ predicate: (q) => (q.queryKey[0] as { _id?: string } | undefined)?._id === 'getFeed' }, (feed) =>
|
||||
feed?.[key] && feed[key].post_id === r?.post_id ? { ...feed, [key]: { ...feed[key], ...values } } : feed,
|
||||
)
|
||||
const toggle = () => {
|
||||
if (!r || like.isPending || unlike.isPending) return
|
||||
const on = !liked
|
||||
setFailed(false)
|
||||
patch({ liked: on, like_count: count + (on ? 1 : -1) })
|
||||
const revert = () => {
|
||||
patch({ liked, like_count: count })
|
||||
setFailed(true)
|
||||
}
|
||||
;(on ? like : unlike).mutate(
|
||||
{ path: { post_id: r.post_id } },
|
||||
{
|
||||
onSuccess: (res) => (res.result?.success ? patch({ liked: res.liked ?? on, ...(res.like_count != null ? { like_count: res.like_count } : {}) }) : revert()),
|
||||
onError: revert,
|
||||
},
|
||||
)
|
||||
}
|
||||
return { liked, count, failed, toggle }
|
||||
}
|
||||
Reference in new issue
Block a user