feat: 앱 오늘 피드를 웹과 맞춤 — 히어로 오늘/내일 전환·좋아요·댓글·보내기·점수 근거 창, 오늘의 각 카드(gak_post), 날씨각 카드(그림 슬라이드), 행사·TOP5 띠 없앰, 좋아요·댓글 로그인 없이 (GA hero_day_switch, like hero_post·gak_post)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
e8b8cc79b6
commit
01b5f917b9
16 files changed
+449
-156
No files matched your search
@@ -1,8 +1,10 @@
|
||||
import { configureApi } from '@nalssigak/shared/api/setup';
|
||||
import * as SecureStore from 'expo-secure-store';
|
||||
|
||||
import { API_URL } from '@/lib/site';
|
||||
|
||||
configureApi({
|
||||
baseUrl: process.env.EXPO_PUBLIC_API_BASE_URL ?? 'http://localhost:9810',
|
||||
baseUrl: API_URL,
|
||||
storage: {
|
||||
getItem: (key) => SecureStore.getItem(key),
|
||||
setItem: (key, value) => SecureStore.setItem(key, value),
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import { likePostMutation, unlikePostMutation } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import type { PostReaction, ResFeed } from '@nalssigak/shared/api/client/types.gen';
|
||||
import type { PinnedKey } from '@nalssigak/shared/lib/analytics';
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { useState } from 'react';
|
||||
|
||||
import { track } from '@/lib/analytics';
|
||||
|
||||
/** 히어로·오늘의 각처럼 포스트 틀이 아닌 카드의 좋아요 (웹 pinnedLike.ts). 로그인 없이 된다. 화면을 먼저 바꾸고 실패하면 되돌린다 */
|
||||
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) => {
|
||||
if (!res.result?.success) return revert();
|
||||
patch({ liked: res.liked ?? on, ...(res.like_count != null ? { like_count: res.like_count } : {}) });
|
||||
if (on) track('like', { content_type: key, item_id: r.post_id });
|
||||
},
|
||||
onError: revert,
|
||||
},
|
||||
);
|
||||
};
|
||||
return { liked, count, failed, toggle };
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { createContext, use } from 'react';
|
||||
|
||||
import type { WeatherWhyPayload } from '@/components/sheets/weather-why';
|
||||
|
||||
type CommentsState = { type: 'comments'; postId: number; draft?: string };
|
||||
|
||||
export type SheetState =
|
||||
@@ -10,6 +12,7 @@ export type SheetState =
|
||||
| { type: 'login'; then?: CommentsState }
|
||||
| { type: 'me' }
|
||||
| { type: 'region' }
|
||||
| { type: 'weatherWhy'; why: WeatherWhyPayload }
|
||||
| null;
|
||||
|
||||
export type SheetApi = { open: (s: Exclude<SheetState, null>) => void; close: () => void };
|
||||
|
||||
@@ -2,3 +2,8 @@ export const SITE_URL = (process.env.EXPO_PUBLIC_SITE_URL ?? 'https://weather.o2
|
||||
|
||||
/** 서버가 주는 사진 경로가 '/season/..' 처럼 사이트 기준이면 사이트 주소를 붙인다 */
|
||||
export const imageUri = (path: string) => (path.startsWith('/') ? `${SITE_URL}${path}` : path);
|
||||
|
||||
/** API 서버 주소. 카드뉴스 그림(/v1/card/...)처럼 API 서버에서 주는 경로에 붙인다 */
|
||||
export const API_URL = (process.env.EXPO_PUBLIC_API_BASE_URL ?? 'http://localhost:9810').replace(/\/+$/, '');
|
||||
|
||||
export const apiUri = (path: string) => (path.startsWith('/') ? `${API_URL}${path}` : path);
|
||||
Reference in new issue
Block a user