Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions apps/audience/src/entities/notice/api/notice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import type {
FestivalNoticesResponseData,
} from '@shared/types/notice-response';

import type { SavedNoticesResponse } from '../types/types';

type RequestOptions = {
signal?: AbortSignal;
};
Expand Down Expand Up @@ -46,3 +48,9 @@ export const postNoticeBookmark = (noticeId: number, isBookmarked: boolean) =>
END_POINT.POST_NOTICE_BOOKMARK(noticeId),
{ isBookmarked },
);

export const getSavedNotices = (params: PageSizeParams = {}) =>
get<SavedNoticesResponse, PageSizeParams>(
END_POINT.GET_SAVED_NOTICES,
params,
);
14 changes: 13 additions & 1 deletion apps/audience/src/entities/notice/model/query-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import type { PageSizeParams } from '@amp/shared/types';

import { USERS_QUERY_KEY } from '@shared/constants/query-key';

import { getFestivalBanner, getFestivalNotices } from '../api/notice';
import {
getFestivalBanner,
getFestivalNotices,
getSavedNotices,
} from '../api/notice';

export const NOTICES_QUERY_OPTIONS = {
LIST: (eventId: number, params: PageSizeParams = {}) =>
Expand All @@ -20,3 +24,11 @@ export const NOTICES_QUERY_OPTIONS = {
enabled: Number.isFinite(festivalId),
}),
} as const;

export const SAVED_NOTICES_QUERY_OPTIONS = {
LIST: (params: PageSizeParams = {}) =>
queryOptions({
queryKey: [...USERS_QUERY_KEY.SAVED_NOTICES(), params],
queryFn: () => getSavedNotices(params),
}),
} as const;
Comment on lines +28 to +34
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Suggest: AbortSignal 지원 추가를 고려해보세요.

NOTICES_QUERY_OPTIONS.LISTsignal을 전달해서 요청 취소를 지원하는데, SAVED_NOTICES_QUERY_OPTIONS.LIST는 signal을 전달하지 않아요. 사용자가 페이지를 빠르게 이탈할 때 불필요한 네트워크 요청이 계속될 수 있어요.

현재 getSavedNotices 함수가 options를 받지 않아서 signal을 전달할 수 없는 구조인데, 일관성과 UX 개선을 위해 추후 리팩토링 시 고려해주시면 좋을 것 같아요.

♻️ 제안하는 수정 방향 (notice.ts와 query-options.ts 둘 다 수정 필요)

notice.ts:

-export const getSavedNotices = (params: PageSizeParams = {}) =>
-  get<SavedNoticesResponse, PageSizeParams>(
+export const getSavedNotices = (
+  params: PageSizeParams = {},
+  options: RequestOptions = {},
+) =>
+  get<SavedNoticesResponse, PageSizeParams>(
     END_POINT.GET_SAVED_NOTICES,
     params,
+    options,
   );

query-options.ts:

 export const SAVED_NOTICES_QUERY_OPTIONS = {
   LIST: (params: PageSizeParams = {}) =>
     queryOptions({
       queryKey: [...USERS_QUERY_KEY.SAVED_NOTICES(), params],
-      queryFn: () => getSavedNotices(params),
+      queryFn: ({ signal }) => getSavedNotices(params, { signal }),
     }),
 } as const;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/audience/src/entities/notice/model/query-options.ts` around lines 28 -
34, SAVED_NOTICES_QUERY_OPTIONS.LIST currently calls getSavedNotices without
supporting AbortSignal, unlike NOTICES_QUERY_OPTIONS.LIST; update
getSavedNotices to accept an options object (e.g., { signal?: AbortSignal,
...params }) and then change SAVED_NOTICES_QUERY_OPTIONS.LIST to forward the
signal into queryOptions's queryFn so the AbortSignal passed by react-query (or
your queryOptions helper) cancels the network request; ensure types
(PageSizeParams or a new interface) are updated and queryOptions usage remains
consistent.

Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import { Pagination } from '@shared/types';

export interface SavedNoticeItem {
savedNoticeId: number;
noticeId: number;
festivalTitle: string;
categoryName: string;
content: string;
title: string;
imageUrl: string;
}

export interface SavedNoticesPagination {
currentPage: number;
totalPages: number;
totalElements: number;
size: number;
hasNext: boolean;
hasPrevious: boolean;
imageUrls: string[];
}

export interface SavedNoticesResponse {
notices: SavedNoticeItem[];
pagination: SavedNoticesPagination;
pagination: Pagination;
}
22 changes: 0 additions & 22 deletions apps/audience/src/features/saved-notice/query.ts

This file was deleted.

4 changes: 2 additions & 2 deletions apps/audience/src/pages/saved-notices/saved-notices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { generatePath, useNavigate } from 'react-router';
import { CardNotice, EmptyView } from '@amp/ads-ui';
import { Loading } from '@amp/compositions';

import { SAVED_NOTICES_QUERY_OPTIONS } from '@features/saved-notice/query';
import { SAVED_NOTICES_QUERY_OPTIONS } from '@entities/notice/model/query-options';

import { ROUTE_PATH } from '@shared/constants/path';

Expand Down Expand Up @@ -36,7 +36,7 @@ const SavedNoticesPage = () => {
{savedNoticesData.notices.map((notice, index) => (
<div key={notice.noticeId}>
<CardNotice
imageUrls={notice.imageUrl ? [notice.imageUrl] : []}
imageUrls={notice.imageUrls ?? []}
title={notice.title}
content={notice.content}
onClick={() => {
Expand Down
1 change: 1 addition & 0 deletions apps/audience/src/shared/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './pagination';
8 changes: 8 additions & 0 deletions apps/audience/src/shared/types/pagination.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface Pagination {
currentPage: number;
totalPages: number;
totalElements: number;
size: number;
hasNext: boolean;
hasPrevious: boolean;
}
Loading