84 lines
3.7 KiB
TypeScript
84 lines
3.7 KiB
TypeScript
import { getSeasonWeekOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
|
import { kst, seasonOf } from '@nalssigak/shared/lib';
|
|
import { useQuery } from '@tanstack/react-query';
|
|
import { usePathname } from 'expo-router';
|
|
import { useState } from 'react';
|
|
import { Pressable, View } from 'react-native';
|
|
import { Text } from '@/components/text';
|
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
import { useCSSVariable } from 'uniwind';
|
|
|
|
import { PinIcon } from '@/components/svg';
|
|
import { Avatar, Ic, Skel } from '@/components/ui';
|
|
import { useAuth } from '@/lib/auth';
|
|
import { useRegion } from '@/lib/region';
|
|
import { useSheet } from '@/lib/sheet';
|
|
import { useSky } from '@/lib/sky';
|
|
|
|
const TITLES: Record<string, string> = { '/sky': '노을', '/gak': '오늘의 각', '/week': '주말·행사', '/season': '계절·상식' };
|
|
|
|
/** 로고 옆 계절 칩: 계절 이름과 지금 절기. 누르면 이번 주 절기 창 */
|
|
function SeasonChip() {
|
|
const { open } = useSheet();
|
|
const week = useQuery(getSeasonWeekOptions());
|
|
const [month] = useState(() => kst(new Date()).mo);
|
|
const [name, icon] = seasonOf(month);
|
|
const term = week.data?.term_now?.name;
|
|
return (
|
|
<Pressable onPress={() => open({ type: 'seasonWeek' })} accessibilityLabel={`지금 ${name}${term ? `, ${term}` : ''}. 이번 주 절기 보기`} className="shrink flex-row items-center gap-1 rounded-full bg-card/70 py-1 pr-2.5 pl-1.5">
|
|
<Ic name={icon} size={18} />
|
|
<Text numberOfLines={1} className="shrink text-[13px] font-extrabold text-ink">
|
|
{name}
|
|
{term && <Text className="font-bold opacity-70"> · {term}</Text>}
|
|
</Text>
|
|
</Pressable>
|
|
);
|
|
}
|
|
|
|
/** 오른쪽 끝: 내 정보(아바타) 또는 로그인 버튼 */
|
|
function Account() {
|
|
const { open } = useSheet();
|
|
const { me, mePending } = useAuth();
|
|
if (mePending) return <View className="size-9 shrink-0 rounded-full bg-skel" />;
|
|
if (me)
|
|
return (
|
|
<Pressable onPress={() => open({ type: 'me' })} accessibilityLabel={`내 정보, ${me.nickname}`} className="shrink-0 rounded-full" style={{ boxShadow: '0 6px 12px rgb(40 48 74 / 0.12)' }}>
|
|
<Avatar character={me.character} color={me.color} mood={me.mood} size={36} />
|
|
</Pressable>
|
|
);
|
|
return (
|
|
<Pressable onPress={() => open({ type: 'login' })} className="shrink-0 rounded-full bg-ink-btn px-3 py-1.5">
|
|
<Text className="text-[13px] font-extrabold text-white">로그인</Text>
|
|
</Pressable>
|
|
);
|
|
}
|
|
|
|
export function TopBar() {
|
|
const pathname = usePathname();
|
|
const { region, locateStatus } = useRegion();
|
|
const { open } = useSheet();
|
|
const { kind } = useSky();
|
|
const { top } = useSafeAreaInsets();
|
|
const ink = String(useCSSVariable('--color-ink'));
|
|
const title = TITLES[pathname];
|
|
return (
|
|
<View style={{ paddingTop: top, backgroundColor: kind === 'night' ? 'rgb(14 20 51 / 0.35)' : 'rgb(255 255 255 / 0.18)' }}>
|
|
<View className="h-[54px] flex-row items-center gap-2 px-4">
|
|
{title ? <Text className="font-jua text-[22px] text-ink">{title}</Text> : <Text className="font-jua text-[25px] text-orange">날씨각</Text>}
|
|
<SeasonChip />
|
|
<Pressable onPress={() => open({ type: 'region' })} accessibilityLabel={`위치 바꾸기, 지금 ${region.name}`} className="ml-auto shrink-0 flex-row items-center gap-1 rounded-full border-b-4 border-shade bg-card px-3 pt-1 pb-1.5">
|
|
<PinIcon size={14} color={ink} />
|
|
{locateStatus === 'locating' ? (
|
|
<Skel className="w-[52px]" />
|
|
) : (
|
|
<Text numberOfLines={1} className="text-[13.5px] font-bold text-ink">
|
|
{region.name.split(' ').at(-1)}
|
|
</Text>
|
|
)}
|
|
</Pressable>
|
|
<Account />
|
|
</View>
|
|
</View>
|
|
);
|
|
}
|