Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/features/feedbacks/components/FeedbacksAllSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ function FeedbacksAllSection() {
});
};

// 필터와 목록 사이 — 공지 목록 위 여백과 같은 12다
return (
<div className="flex flex-col gap-4 pb-24">
<div className="flex flex-col gap-3 pb-24">
<div className="flex flex-col gap-3">
<div className="px-5">
<Typography
Expand Down
24 changes: 21 additions & 3 deletions src/features/home/HomeScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PushBadge, TopNavigationButton } from "@wanteddev/wds";
import { Loading, PushBadge, TopNavigationButton } from "@wanteddev/wds";
import { IconBell, IconSearch, IconSetting } from "@wanteddev/wds-icon";
import { Suspense, useState } from "react";
import { useNavigate } from "react-router-dom";
Expand All @@ -25,11 +25,13 @@ import HomeNoticeBannerSkeleton from "@/features/home/components/HomeNoticeBanne
import HomeRentalSection from "@/features/home/components/HomeRentalSection";
import HomeRentalSkeleton from "@/features/home/components/HomeRentalSkeleton";
import { HOME_HAS_UNREAD_NOTIFICATION } from "@/features/home/constants/homeMock";
import { useHomePullToRefresh } from "@/features/home/hooks/useHomePullToRefresh";
import { LOCKER_ASSIGNMENT_PATH } from "@/features/lockers/constants/lockers";
import { NOTIFICATIONS_PATH } from "@/features/notifications/constants/notifications";
import { getSearchPath } from "@/features/search/constants/search";
import { SETTINGS_PATHS } from "@/features/settings/constants/settings";
import { openExternalLink } from "@/lib/openExternalLink";
import { useRefreshHomeQueries } from "@/shared/entities/home/homeQueries";
import type {
HomeApplySection,
HomeBanner,
Expand All @@ -45,6 +47,10 @@ function HomeScreen() {
const navigate = useNavigate();

const [isScrolled, setIsScrolled] = useState(false);
// 로고를 누르거나 맨 위에서 당기면 맨 위로 올리고 홈 데이터를 다시 받는다
const refreshHomeQueries = useRefreshHomeQueries();
const { indicatorRef, isRefreshing, refresh, scrollRef } =
useHomePullToRefresh(refreshHomeQueries);

// 상세·신청·내 내역처럼 화면을 쌓는 이동은 슬라이드로, 하단 탭 화면(빌릴게·행사와 그 탭)으로는 바로 바꾼다
const push = (to: string) => navigate(to, { viewTransition: true });
Expand Down Expand Up @@ -72,10 +78,20 @@ function HomeScreen() {

return (
<div className="relative flex h-full flex-col">
{/* 새로고침 로딩 표시 — 당기거나 새로고침하는 동안 스크롤 영역이 내려간 만큼 위에 펼쳐진다(useHomePullToRefresh) */}
<div
className="pointer-events-none absolute inset-x-0 top-0 flex h-0 items-center justify-center overflow-hidden"
ref={indicatorRef}
>
{/* WDS Loading은 size를 단위 없이 CSS에 넣어서 숫자(24)를 주면 크기가 0이 된다 — 단위를 붙인다 */}
<Loading size="24px" variant="circular" />
</div>
{/* 스크롤 영역 자체를 flex로 두면 내용이 길 때 섹션이 줄어들어서(배너 가로 스크롤 영역은 최소 높이가 0) 안쪽에서 쌓는다 */}
<div
className="scrollbar-hidden min-h-0 flex-1 overflow-y-auto"
aria-busy={isRefreshing}
className="scrollbar-hidden min-h-0 flex-1 overflow-y-auto overscroll-y-contain"
onScroll={(event) => setIsScrolled(event.currentTarget.scrollTop > 0)}
ref={scrollRef}
>
{/* Figma: Top Navigation State=Home (nodeId 547:31364), 알림 있을 때 (3147:146473)
홈만 헤더를 스크롤 영역 안에 둔다. Figma는 헤더 배경이 없어 배너 그림자가 헤더까지 번지는데,
Expand All @@ -87,7 +103,9 @@ function HomeScreen() {
<ScreenHeader
title={
<h2>
<img alt="stream" className="h-8 w-28" src={logo} />
<button className="block" onClick={refresh} type="button">
<img alt="stream" className="h-8 w-28" src={logo} />
</button>
</h2>
}
trailing={
Expand Down
153 changes: 153 additions & 0 deletions src/features/home/hooks/useHomePullToRefresh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import {
useCallback,
useEffect,
useLayoutEffect,
useRef,
useState,
} from "react";

// 당긴 거리의 절반만 따라 내려온다 — 손가락을 그대로 따라오면 살짝 끌어도 새로고침된다
const PULL_RESISTANCE = 0.5;
// 내용이 이만큼 내려온 채로 놓으면 새로고침한다. 새로고침하는 동안 로딩 표시가 이 높이로 떠 있다
const REFRESH_OFFSET = 56;
const MAX_PULL_OFFSET = 96;
// 손가락이 이만큼 움직이기 전에는 방향을 정하지 않는다 — 배너를 가로로 넘기는 손짓과 섞이지 않게 한다
const DIRECTION_LOCK_DISTANCE = 6;
const SETTLE_TRANSITION = "transform 200ms ease-out, height 200ms ease-out";

// 로딩 표시 높이와 스크롤 영역이 내려온 거리를 같이 맞춘다. 0이면 transform을 지워서 흔적을 남기지 않는다
function applyOffset(
scroller: HTMLElement | null,
indicator: HTMLElement | null,
offset: number,
animate: boolean,
) {
for (const element of [scroller, indicator]) {
if (element) {
element.style.transition = animate ? SETTLE_TRANSITION : "";
}
}
if (scroller) {
scroller.style.transform = offset > 0 ? `translateY(${offset}px)` : "";
}
if (indicator) {
indicator.style.height = `${offset}px`;
}
}

// 홈 맨 위에서 아래로 당겼다 놓으면 onRefresh를 부른다(당겨서 새로고침). 로고를 눌렀을 때 쓰는 refresh도 같이 준다 —
// 맨 위로 올리고 같은 로딩 표시를 띄운 채 onRefresh가 끝나기를 기다린다.
// 스크롤 영역(헤더 포함)이 통째로 내려오고, 그 위로 드러나는 자리에 로딩 표시(indicatorRef)가 펼쳐진다.
// 당기는 동안은 리렌더 없이 DOM에 바로 적용하고(useLockersPinchZoom과 같은 방식), 새로고침 중인지만 상태로 둔다.
// 당기는 손짓은 touchmove를 preventDefault해서 브라우저 바운스로 넘기지 않는다 — React의 touch 핸들러는 passive라
// 막을 수 없어서 리스너를 직접 단다. Android Chrome의 당겨서 새로고침은 스크롤 영역의 overscroll-behavior로 막는다.
export function useHomePullToRefresh(onRefresh: () => Promise<unknown>) {
const scrollRef = useRef<HTMLDivElement>(null);
const indicatorRef = useRef<HTMLDivElement>(null);
const [isRefreshing, setIsRefreshing] = useState(false);
const isRefreshingRef = useRef(false);
const onRefreshRef = useRef(onRefresh);

useLayoutEffect(() => {
onRefreshRef.current = onRefresh;
}, [onRefresh]);

const refresh = useCallback(async () => {
if (isRefreshingRef.current) {
return;
}
isRefreshingRef.current = true;
setIsRefreshing(true);
scrollRef.current?.scrollTo({ top: 0 });
applyOffset(scrollRef.current, indicatorRef.current, REFRESH_OFFSET, true);
try {
await onRefreshRef.current();
} finally {
isRefreshingRef.current = false;
setIsRefreshing(false);
applyOffset(scrollRef.current, indicatorRef.current, 0, true);
}
}, []);

useEffect(() => {
const scroller = scrollRef.current;
if (!scroller) {
return;
}

let gesture: {
startX: number;
startY: number;
isPulling: boolean;
} | null = null;
let offset = 0;

const handleTouchStart = (event: TouchEvent) => {
// 맨 위가 아니거나 이미 새로고침 중이면 평소 스크롤로 둔다
if (
isRefreshingRef.current ||
scroller.scrollTop > 0 ||
event.touches.length !== 1
) {
gesture = null;
return;
}
gesture = {
isPulling: false,
startX: event.touches[0].clientX,
startY: event.touches[0].clientY,
};
offset = 0;
};

const handleTouchMove = (event: TouchEvent) => {
if (!gesture) {
return;
}
const dx = event.touches[0].clientX - gesture.startX;
const dy = event.touches[0].clientY - gesture.startY;
if (!gesture.isPulling) {
if (Math.hypot(dx, dy) < DIRECTION_LOCK_DISTANCE) {
return;
}
// 가로로 넘기거나 위로 밀면(아래 내용 보기) 당기기가 아니다
if (Math.abs(dx) > Math.abs(dy) || dy < 0) {
gesture = null;
return;
}
gesture.isPulling = true;
}
event.preventDefault();
offset = Math.min(Math.max(dy, 0) * PULL_RESISTANCE, MAX_PULL_OFFSET);
applyOffset(scroller, indicatorRef.current, offset, false);
};

const handleTouchEnd = () => {
const wasPulling = gesture?.isPulling === true;
gesture = null;
if (!wasPulling) {
return;
}
if (offset >= REFRESH_OFFSET) {
void refresh();
} else {
applyOffset(scroller, indicatorRef.current, 0, true);
}
};

scroller.addEventListener("touchstart", handleTouchStart, {
passive: true,
});
scroller.addEventListener("touchmove", handleTouchMove, { passive: false });
scroller.addEventListener("touchend", handleTouchEnd);
scroller.addEventListener("touchcancel", handleTouchEnd);
return () => {
scroller.removeEventListener("touchstart", handleTouchStart);
scroller.removeEventListener("touchmove", handleTouchMove);
scroller.removeEventListener("touchend", handleTouchEnd);
scroller.removeEventListener("touchcancel", handleTouchEnd);
};
}, [refresh]);

return { indicatorRef, isRefreshing, refresh, scrollRef };
}
6 changes: 4 additions & 2 deletions src/features/notices/components/NoticesCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ function NoticesCard({
hasThumbnail = false,
thumbnailUrl,
}: NoticesCardProps) {
// 썸네일이 있으면 제목이 한 줄(noWrap)이라, 글 칸이 제목 길이만큼 버티지 않게 min-w-0으로 줄여서 썸네일 앞에서
// 말줄임되게 한다. Figma는 제목이 짧아 제목·썸네일 사이 간격이 없는데, 말줄임표가 썸네일에 붙지 않게 12를 둔다.
return (
<div
className={`flex w-full items-center justify-between px-5 ${hasThumbnail ? "" : "py-[7px]"}`}
className={`flex w-full items-center justify-between gap-3 px-5 ${hasThumbnail ? "" : "py-[7px]"}`}
>
<div className="flex flex-1 flex-col gap-1">
<div className="flex min-w-0 flex-1 flex-col gap-1">
{/* 고정 공지의 핀은 썸네일 유무와 상관없이 제목 앞에 붙는다. 썸네일이 없으면 제목이 여러 줄로 이어진다 */}
<div className="flex items-center gap-1">
{isPinned && <img alt="" className="size-5 shrink-0" src={pinIcon} />}
Expand Down
5 changes: 3 additions & 2 deletions src/features/notices/components/NoticesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ function NoticesList({ category }: NoticesListProps) {
isFetchingNextPage,
});

// Figma(1256:81800)는 목록 위 여백·카드 사이 간격이 16인데, 넓어 보여서 둘 다 12로 줄였다(열린피드백 목록과 같다)
return (
<div className="py-4">
<div className="flex flex-col gap-4">
<div className="py-3">
<div className="flex flex-col gap-3">
{notices.map((notice, index) => (
<Fragment key={notice.noticeId}>
{index > 0 && (
Expand Down
15 changes: 14 additions & 1 deletion src/shared/entities/home/homeQueries.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { queryOptions } from "@tanstack/react-query";
import { queryOptions, useQueryClient } from "@tanstack/react-query";
import { z } from "zod";

import { api } from "@/shared/api";
import { billilgeKeys } from "@/shared/entities/billilge/billilgeKeys";
import { FEE_STATUSES } from "@/shared/entities/fee/feeQueries";
import { homeKeys } from "@/shared/entities/home/homeKeys";

Expand Down Expand Up @@ -87,3 +88,15 @@ export const homeQueries = {
),
}),
};

// 홈 새로고침(로고·당겨서 새로고침) — 홈 조회와, 대여 현황이 쓰는 빌릴게 대여 이력(반납 필요·대여 내역) 조회를 다시 받는다.
// 페이지를 새로고침한 것처럼 보이게 받아 둔 데이터를 비우고(resetQueries) 받는다 — 받는 동안 섹션마다 스켈레톤이 보인다.
// 다 받은 뒤에 끝나는 Promise를 돌려준다.
export function useRefreshHomeQueries() {
const queryClient = useQueryClient();
return () =>
Promise.all([
queryClient.resetQueries({ queryKey: homeKeys.root() }),
queryClient.resetQueries({ queryKey: billilgeKeys.histories() }),
]);
}
Loading