feat: 앱 계정 레벨 — 하루 출석 각, 아바타 Lv 표시, 내 정보 레벨 카드, 내 레벨·레벨업 창, 공유하면 하루 한 번 각, 각을 주는 일 뒤 레벨 다시 받기. 아이콘 목록을 웹 아이콘 전부로 (GA sheet_open level·levelUp)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
01b5f917b9
commit
e40a9a0539
16 files changed
+360
-19
No files matched your search
+67
-2
@@ -1,4 +1,4 @@
|
||||
// frontend/public 의 아이콘을 그대로 쓴다. Metro 는 정적 require 만 묶을 수 있어 이름마다 적는다
|
||||
// frontend/public 의 아이콘을 그대로 쓴다 (공용 public/icons, 웹 전용 public/b/icons). Metro 는 정적 require 만 묶을 수 있어 이름마다 적는다
|
||||
export const ICONS: Record<string, number> = {
|
||||
apple: require('../../../frontend/public/icons/apple.png'),
|
||||
baseball: require('../../../frontend/public/icons/baseball.png'),
|
||||
@@ -6,6 +6,7 @@ export const ICONS: Record<string, number> = {
|
||||
bike: require('../../../frontend/public/icons/bike.png'),
|
||||
bingsu: require('../../../frontend/public/icons/bingsu.png'),
|
||||
blanket: require('../../../frontend/public/icons/blanket.png'),
|
||||
boiler: require('../../../frontend/public/icons/boiler.png'),
|
||||
bronze: require('../../../frontend/public/icons/bronze.png'),
|
||||
bungeoppang: require('../../../frontend/public/icons/bungeoppang.png'),
|
||||
camping: require('../../../frontend/public/icons/camping.png'),
|
||||
@@ -14,17 +15,24 @@ export const ICONS: Record<string, number> = {
|
||||
chimaek: require('../../../frontend/public/icons/chimaek.png'),
|
||||
cloud: require('../../../frontend/public/icons/cloud.png'),
|
||||
coldwind: require('../../../frontend/public/icons/coldwind.png'),
|
||||
date: require('../../../frontend/public/icons/date.png'),
|
||||
delivery: require('../../../frontend/public/icons/delivery.png'),
|
||||
dog: require('../../../frontend/public/icons/dog.png'),
|
||||
drive: require('../../../frontend/public/icons/drive.png'),
|
||||
fallen_leaf: require('../../../frontend/public/icons/fallen_leaf.png'),
|
||||
fishing: require('../../../frontend/public/icons/fishing.png'),
|
||||
flower: require('../../../frontend/public/icons/flower.png'),
|
||||
frizz: require('../../../frontend/public/icons/frizz.png'),
|
||||
game: require('../../../frontend/public/icons/game.png'),
|
||||
garden: require('../../../frontend/public/icons/garden.png'),
|
||||
gift: require('../../../frontend/public/icons/gift.png'),
|
||||
ginkgo: require('../../../frontend/public/icons/ginkgo.png'),
|
||||
glasses: require('../../../frontend/public/icons/glasses.png'),
|
||||
gold: require('../../../frontend/public/icons/gold.png'),
|
||||
golf: require('../../../frontend/public/icons/golf.png'),
|
||||
hangang: require('../../../frontend/public/icons/hangang.png'),
|
||||
hiking: require('../../../frontend/public/icons/hiking.png'),
|
||||
hyodo: require('../../../frontend/public/icons/hyodo.png'),
|
||||
iced_hot: require('../../../frontend/public/icons/iced_hot.png'),
|
||||
indoordry: require('../../../frontend/public/icons/indoordry.png'),
|
||||
jipkok: require('../../../frontend/public/icons/jipkok.png'),
|
||||
@@ -38,10 +46,12 @@ export const ICONS: Record<string, number> = {
|
||||
maple: require('../../../frontend/public/icons/maple.png'),
|
||||
mask: require('../../../frontend/public/icons/mask.png'),
|
||||
moon: require('../../../frontend/public/icons/moon.png'),
|
||||
mosquito: require('../../../frontend/public/icons/mosquito.png'),
|
||||
muggy: require('../../../frontend/public/icons/muggy.png'),
|
||||
naengmyeon: require('../../../frontend/public/icons/naengmyeon.png'),
|
||||
netflix: require('../../../frontend/public/icons/netflix.png'),
|
||||
pajeon: require('../../../frontend/public/icons/pajeon.png'),
|
||||
party: require('../../../frontend/public/icons/party.png'),
|
||||
peanut: require('../../../frontend/public/icons/peanut.png'),
|
||||
photo: require('../../../frontend/public/icons/photo.png'),
|
||||
picnic: require('../../../frontend/public/icons/picnic.png'),
|
||||
@@ -49,29 +59,84 @@ export const ICONS: Record<string, number> = {
|
||||
rain: require('../../../frontend/public/icons/rain.png'),
|
||||
riverwind: require('../../../frontend/public/icons/riverwind.png'),
|
||||
running: require('../../../frontend/public/icons/running.png'),
|
||||
selfie: require('../../../frontend/public/icons/selfie.png'),
|
||||
sentimental: require('../../../frontend/public/icons/sentimental.png'),
|
||||
silver: require('../../../frontend/public/icons/silver.png'),
|
||||
singing_rain: require('../../../frontend/public/icons/singing_rain.png'),
|
||||
snow: require('../../../frontend/public/icons/snow.png'),
|
||||
stars: require('../../../frontend/public/icons/stars.png'),
|
||||
study: require('../../../frontend/public/icons/study.png'),
|
||||
sun_cloud: require('../../../frontend/public/icons/sun_cloud.png'),
|
||||
sun: require('../../../frontend/public/icons/sun.png'),
|
||||
sun_cloud: require('../../../frontend/public/icons/sun_cloud.png'),
|
||||
sunscreen: require('../../../frontend/public/icons/sunscreen.png'),
|
||||
sunset: require('../../../frontend/public/icons/sunset.png'),
|
||||
sweet_potato: require('../../../frontend/public/icons/sweet_potato.png'),
|
||||
tangerine: require('../../../frontend/public/icons/tangerine.png'),
|
||||
taxi: require('../../../frontend/public/icons/taxi.png'),
|
||||
tennis: require('../../../frontend/public/icons/tennis.png'),
|
||||
thanks: require('../../../frontend/public/icons/thanks.png'),
|
||||
themepark: require('../../../frontend/public/icons/themepark.png'),
|
||||
trot: require('../../../frontend/public/icons/trot.png'),
|
||||
umbrella: require('../../../frontend/public/icons/umbrella.png'),
|
||||
vent: require('../../../frontend/public/icons/vent.png'),
|
||||
walk: require('../../../frontend/public/icons/walk.png'),
|
||||
waterplay: require('../../../frontend/public/icons/waterplay.png'),
|
||||
yajang: require('../../../frontend/public/icons/yajang.png'),
|
||||
alarm_clock: require('../../../frontend/public/b/icons/alarm_clock.png'),
|
||||
bat: require('../../../frontend/public/b/icons/bat.png'),
|
||||
briefcase: require('../../../frontend/public/b/icons/briefcase.png'),
|
||||
bulb: require('../../../frontend/public/b/icons/bulb.png'),
|
||||
calendar: require('../../../frontend/public/b/icons/calendar.png'),
|
||||
candy: require('../../../frontend/public/b/icons/candy.png'),
|
||||
check_mark_button: require('../../../frontend/public/b/icons/check_mark_button.png'),
|
||||
christmas_tree: require('../../../frontend/public/b/icons/christmas_tree.png'),
|
||||
clapper: require('../../../frontend/public/b/icons/clapper.png'),
|
||||
concert: require('../../../frontend/public/b/icons/concert.png'),
|
||||
crystal_ball: require('../../../frontend/public/b/icons/crystal_ball.png'),
|
||||
dango: require('../../../frontend/public/b/icons/dango.png'),
|
||||
droplet: require('../../../frontend/public/b/icons/droplet.png'),
|
||||
exhibition: require('../../../frontend/public/b/icons/exhibition.png'),
|
||||
fireworks: require('../../../frontend/public/b/icons/fireworks.png'),
|
||||
full_moon: require('../../../frontend/public/b/icons/full_moon.png'),
|
||||
ghost: require('../../../frontend/public/b/icons/ghost.png'),
|
||||
jack_o_lantern: require('../../../frontend/public/b/icons/jack_o_lantern.png'),
|
||||
leaf: require('../../../frontend/public/b/icons/leaf.png'),
|
||||
locked: require('../../../frontend/public/b/icons/locked.png'),
|
||||
lollipop: require('../../../frontend/public/b/icons/lollipop.png'),
|
||||
milky_way: require('../../../frontend/public/b/icons/milky_way.png'),
|
||||
money_bag: require('../../../frontend/public/b/icons/money_bag.png'),
|
||||
moon_viewing: require('../../../frontend/public/b/icons/moon_viewing.png'),
|
||||
pear: require('../../../frontend/public/b/icons/pear.png'),
|
||||
pepero_almond: require('../../../frontend/public/b/icons/pepero_almond.png'),
|
||||
pepero_basket: require('../../../frontend/public/b/icons/pepero_basket.png'),
|
||||
pepero_box: require('../../../frontend/public/b/icons/pepero_box.png'),
|
||||
pepero_bundle: require('../../../frontend/public/b/icons/pepero_bundle.png'),
|
||||
pepero_choco: require('../../../frontend/public/b/icons/pepero_choco.png'),
|
||||
pepero_nude: require('../../../frontend/public/b/icons/pepero_nude.png'),
|
||||
pepero_pair: require('../../../frontend/public/b/icons/pepero_pair.png'),
|
||||
pepero_strawberry: require('../../../frontend/public/b/icons/pepero_strawberry.png'),
|
||||
popup: require('../../../frontend/public/b/icons/popup.png'),
|
||||
rainbow: require('../../../frontend/public/b/icons/rainbow.png'),
|
||||
red_heart: require('../../../frontend/public/b/icons/red_heart.png'),
|
||||
sheaf: require('../../../frontend/public/b/icons/sheaf.png'),
|
||||
shooting_star: require('../../../frontend/public/b/icons/shooting_star.png'),
|
||||
skull: require('../../../frontend/public/b/icons/skull.png'),
|
||||
sparkles: require('../../../frontend/public/b/icons/sparkles.png'),
|
||||
speech: require('../../../frontend/public/b/icons/speech.png'),
|
||||
spider: require('../../../frontend/public/b/icons/spider.png'),
|
||||
spider_web: require('../../../frontend/public/b/icons/spider_web.png'),
|
||||
spiral_calendar: require('../../../frontend/public/b/icons/spiral_calendar.png'),
|
||||
sunrise: require('../../../frontend/public/b/icons/sunrise.png'),
|
||||
thermo: require('../../../frontend/public/b/icons/thermo.png'),
|
||||
tshirt: require('../../../frontend/public/b/icons/tshirt.png'),
|
||||
two_hearts: require('../../../frontend/public/b/icons/two_hearts.png'),
|
||||
warning: require('../../../frontend/public/b/icons/warning.png'),
|
||||
xmas_candy_cane: require('../../../frontend/public/b/icons/xmas_candy_cane.png'),
|
||||
xmas_gingerbread: require('../../../frontend/public/b/icons/xmas_gingerbread.png'),
|
||||
xmas_ornament: require('../../../frontend/public/b/icons/xmas_ornament.png'),
|
||||
xmas_santa: require('../../../frontend/public/b/icons/xmas_santa.png'),
|
||||
xmas_santa_hat: require('../../../frontend/public/b/icons/xmas_santa_hat.png'),
|
||||
xmas_stocking: require('../../../frontend/public/b/icons/xmas_stocking.png'),
|
||||
xmas_wreath: require('../../../frontend/public/b/icons/xmas_wreath.png'),
|
||||
yin_yang: require('../../../frontend/public/b/icons/yin_yang.png'),
|
||||
};
|
||||
@@ -0,0 +1,95 @@
|
||||
import { attendMutation, myLevelOptions, myLevelQueryKey, sharedMutation } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import type { ResLevel } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { router, type Href } from 'expo-router';
|
||||
import * as SecureStore from 'expo-secure-store';
|
||||
import { useEffect, useRef } from 'react';
|
||||
|
||||
import { useAuth } from '@/lib/auth';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
|
||||
/** 잠시 숨긴 기능 (아이콘 줄·각 모으는 법에서 뺀다, 웹 features.ts 와 같게) */
|
||||
export const HIDDEN = new Set<string>(['tarot']);
|
||||
|
||||
// 받침 있으면 a, 없으면 b: josa('연애운', '이', '가') → '연애운이'
|
||||
export const josa = (w: string, a: string, b: string) => {
|
||||
const c = w.charCodeAt(w.length - 1) - 0xac00;
|
||||
return w + (c >= 0 && c < 11172 && c % 28 === 0 ? b : a);
|
||||
};
|
||||
|
||||
// 레벨마다 보여 줄 하늘 아이콘 (이름은 서버 LEVELS)
|
||||
const LEVEL_ICON = ['droplet', 'sun', 'leaf', 'rainbow', 'sunset', 'milky_way', 'shooting_star'];
|
||||
export const levelIcon = (level: number) => LEVEL_ICON[Math.min(Math.max(level, 1), LEVEL_ICON.length) - 1];
|
||||
|
||||
/** 서버 응답에서 기본값이 있는 칸은 생략될 수 있어 채워 둔다 */
|
||||
export type Level = ResLevel & { points: number; level: number; floor: number; streak: number };
|
||||
|
||||
const toLevel = (d: ResLevel): Level | undefined => (d.result?.success ? { ...d, points: d.points ?? 0, level: d.level ?? 1, floor: d.floor ?? 0, streak: d.streak ?? 0 } : undefined);
|
||||
|
||||
/** 내 레벨 (로그인했을 때만). 각을 주는 일은 모두 mutation 이라 끝날 때마다 다시 받는다(query-client.ts) */
|
||||
export function useLevel() {
|
||||
const { loggedIn } = useAuth();
|
||||
return useQuery({ ...myLevelOptions(), enabled: loggedIn, staleTime: 60_000, select: toLevel });
|
||||
}
|
||||
|
||||
/** 다음 레벨까지 진행률 0~1 */
|
||||
export function progress(l: Level) {
|
||||
if (l.next_points == null) return 1;
|
||||
return Math.min(1, (l.points - l.floor) / (l.next_points - l.floor));
|
||||
}
|
||||
|
||||
/** 다음 레벨에서 열리는 것 이름 */
|
||||
export const nextUnlock = (l: Level) => (l.unlocks ?? []).filter((u) => u.level === l.level + 1).map((u) => u.name);
|
||||
|
||||
/** 창을 닫고 그 화면으로 간다 */
|
||||
export function useCloseAndGo() {
|
||||
const { close } = useSheet();
|
||||
return (to: string) => {
|
||||
close();
|
||||
router.push(to as Href);
|
||||
};
|
||||
}
|
||||
|
||||
const SEEN_KEY = 'nalssigak.levelSeen';
|
||||
|
||||
/** 로그인한 사람이 앱을 열면 하루 한 번 출석 각. 레벨이 오르면 축하 창을 띄운다 (루트 레이아웃에 한 번 둔다) */
|
||||
export function LevelWatcher() {
|
||||
const { loggedIn, me } = useAuth();
|
||||
const { open } = useSheet();
|
||||
const queryClient = useQueryClient();
|
||||
const level = useLevel().data;
|
||||
const { mutate } = useMutation({ ...attendMutation() });
|
||||
const attended = useRef<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!loggedIn || !me || attended.current === me.login_id) return;
|
||||
attended.current = me.login_id;
|
||||
mutate({}, { onSuccess: (res) => res.result?.success && queryClient.setQueryData(myLevelQueryKey(), res) });
|
||||
}, [loggedIn, me, mutate, queryClient]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!level || !me) return;
|
||||
// SecureStore 키는 영문·숫자·._- 만 된다
|
||||
const key = `${SEEN_KEY}.${me.login_id.replace(/[^\w.-]/g, '_')}`;
|
||||
let seen: number | null = null;
|
||||
try {
|
||||
seen = Number(SecureStore.getItem(key)) || null;
|
||||
SecureStore.setItem(key, String(level.level));
|
||||
} catch (e) {
|
||||
console.warn('[level] 본 레벨을 저장하지 못함', e);
|
||||
}
|
||||
// 처음 보는 기기에선 축하하지 않는다 (예전 레벨을 모름)
|
||||
if (seen != null && level.level > seen) open({ type: 'levelUp', level: level.level });
|
||||
}, [level, me, open]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/** 공유를 마치면 하루 한 번 각 (로그인했을 때만) */
|
||||
export function useShareReward() {
|
||||
const { loggedIn } = useAuth();
|
||||
const { mutate } = useMutation({ ...sharedMutation() });
|
||||
return () => {
|
||||
if (loggedIn) mutate({});
|
||||
};
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { focusManager, keepPreviousData, QueryClient } from '@tanstack/react-query';
|
||||
import { myLevelQueryKey } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import { focusManager, keepPreviousData, MutationCache, QueryClient } from '@tanstack/react-query';
|
||||
import { AppState, Platform } from 'react-native';
|
||||
|
||||
// 앱이 다시 앞으로 오면 '포커스'로 보고, 5분 넘게 묵은 데이터만 다시 받는다
|
||||
@@ -10,6 +11,8 @@ if (Platform.OS !== 'web') {
|
||||
}
|
||||
|
||||
// 웹과 같은 기본값: 다시 받는 동안 이전 결과를 그대로 두어 화면이 비지 않게 한다
|
||||
export const queryClient = new QueryClient({
|
||||
export const queryClient: QueryClient = new QueryClient({
|
||||
defaultOptions: { queries: { staleTime: 5 * 60 * 1000, retry: 1, placeholderData: keepPreviousData } },
|
||||
// 각을 주는 일(좋아요·댓글·글·공유·사주)은 모두 mutation 이라, 끝나면 내 레벨을 다시 받는다 (웹 main.tsx)
|
||||
mutationCache: new MutationCache({ onSuccess: () => queryClient.invalidateQueries({ queryKey: myLevelQueryKey() }) }),
|
||||
});
|
||||
@@ -4,19 +4,32 @@ import { Share, type View } from 'react-native';
|
||||
import { captureRef } from 'react-native-view-shot';
|
||||
|
||||
import { track } from '@/lib/analytics';
|
||||
import { useShareReward } from '@/lib/level';
|
||||
|
||||
/** 보이는 화면 조각을 PNG로 찍어 공유. 이미지 공유가 안 되는 곳(웹 등)이면 글로 보낸다 */
|
||||
export async function shareView(ref: RefObject<View | null>, { title, message }: { title: string; message: string }) {
|
||||
type ShareText = { title: string; message: string };
|
||||
|
||||
/** 보이는 화면 조각을 PNG로 찍어 공유. 이미지 공유가 안 되는 곳(웹 등)이면 글로 보낸다. 보냈으면 true */
|
||||
async function shareView(ref: RefObject<View | null>, { title, message }: ShareText) {
|
||||
try {
|
||||
if (ref.current && (await Sharing.isAvailableAsync())) {
|
||||
const uri = await captureRef(ref, { format: 'png', quality: 1, result: 'tmpfile' });
|
||||
await Sharing.shareAsync(uri, { mimeType: 'image/png', UTI: 'public.png', dialogTitle: title });
|
||||
// 앱은 보이는 카드를 그대로 찍어 보내므로 비율은 'card'
|
||||
track('share', { content_type: 'image', item_id: title, method: 'share_sheet', ratio: 'card' });
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
await Share.share({ message });
|
||||
const res = await Share.share({ message });
|
||||
return res.action === Share.sharedAction;
|
||||
} catch (e) {
|
||||
console.warn('공유 실패', e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 화면 조각 공유. 보내면 하루 한 번 각을 받는다 (로그인했을 때만) */
|
||||
export function useShare() {
|
||||
const reward = useShareReward();
|
||||
return async (ref: RefObject<View | null>, text: ShareText) => {
|
||||
if (await shareView(ref, text)) reward();
|
||||
};
|
||||
}
|
||||
@@ -9,10 +9,12 @@ export type SheetState =
|
||||
| { type: 'article'; articleId: number }
|
||||
| CommentsState
|
||||
| { type: 'seasonWeek' }
|
||||
| { type: 'login'; then?: CommentsState }
|
||||
| { type: 'login'; then?: CommentsState; why?: 'level' }
|
||||
| { type: 'me' }
|
||||
| { type: 'region' }
|
||||
| { type: 'weatherWhy'; why: WeatherWhyPayload }
|
||||
| { type: 'level' }
|
||||
| { type: 'levelUp'; level: number }
|
||||
| null;
|
||||
|
||||
export type SheetApi = { open: (s: Exclude<SheetState, null>) => void; close: () => void };
|
||||
|
||||
Reference in new issue
Block a user