Skip to content

Commit ff07db2

Browse files
committed
apply code review
1 parent 5302cd6 commit ff07db2

File tree

4 files changed

+25
-35
lines changed

4 files changed

+25
-35
lines changed

services/one-app/src/app/(site)/lost-found/[lostId]/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import PlusIcon from '@/common/assets/icons/plus';
33
import { SuspensedQueryBoundary } from '@/common/components/SuspensedQueryBoundary/SuspensedQueryBoundary';
44
import LostFoundDetail from '../_components/LostFoundDetail';
55

6-
type Params = {
6+
type Props = {
77
params: {
88
lostId: string;
99
};
1010
};
1111

12-
export default function LostFoundDetailPage({ params }: Params) {
12+
export default function LostFoundDetailPage({ params }: Props) {
1313
const { lostId } = params;
1414

1515
return (

services/one-app/src/app/(site)/lost-found/_components/LostFoundList.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,14 @@ const LostFoundList = () => {
2525
return (
2626
<>
2727
{lostArticles.map((item, idx) => (
28-
// item.id로만 하면 key 중복이 발생하고 있음.
29-
// 해결 필요
3028
<Link key={`${item.id}-${idx}`} href={`/lost-found/${item.id}`}>
29+
{/* item.id로만 하면 key 중복이 발생하고 있음. 확인 필요 */}
3130
{item.title}
3231
</Link>
3332
))}
34-
{hasNextPage && (
35-
<IntersectionArea
36-
callback={intersectCallback}
37-
intersectionOptions={{ rootMargin: '24% 0px', threshold: 0 }}
38-
>
39-
<span className="visuallyHidden">더 보기</span>
40-
</IntersectionArea>
41-
)}
33+
<IntersectionArea when={hasNextPage} callback={intersectCallback}>
34+
<span className="visuallyHidden">더 보기</span>
35+
</IntersectionArea>
4236
</>
4337
);
4438
};

services/one-app/src/common/components/IntersectionArea.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,28 @@ import type { IntersectionOptions } from 'react-intersection-observer';
55

66
import { useIntersectionObserver } from '@/common/hooks/useIntersectionObserver';
77

8-
interface FetchNextPageOptions {
8+
interface Props {
99
callback: () => void;
10+
when: boolean;
1011
intersectionOptions?: IntersectionOptions;
1112
}
1213

1314
function IntersectionArea({
1415
children,
1516
callback,
17+
when,
1618
intersectionOptions,
17-
}: PropsWithChildren<FetchNextPageOptions>) {
19+
}: PropsWithChildren<Props>) {
1820
const { ref } = useIntersectionObserver({
1921
callback,
2022
intersectionOptions,
2123
});
2224

23-
return (
25+
return when ? (
2426
<div ref={ref} className="flex justify-center w-full">
2527
{children}
2628
</div>
27-
);
29+
) : null;
2830
}
2931

3032
export default IntersectionArea;

services/one-app/src/common/utils/object.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,36 @@
11
import queryString from 'query-string';
22

33
export const isValidObject = (obj: unknown): obj is Record<string, any> => {
4-
return typeof obj === 'object' && obj !== null;
4+
return typeof obj === 'object' && obj !== null && !Array.isArray(obj);
55
};
66

77
export function removeFalsyValues<T extends Record<string, any>>(
88
obj: T,
99
options: { removeEmptyStrings?: boolean; removeZero?: boolean } = {},
1010
): Partial<T> {
1111
if (!isValidObject(obj)) {
12-
return obj;
12+
throw new Error('obj must be a non-null object');
1313
}
1414

15-
const result: Partial<T> = {};
16-
17-
for (const key in obj) {
18-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
19-
const value = obj[key];
20-
if (
21-
value !== undefined &&
22-
value !== null &&
23-
(options.removeZero ? value !== 0 : true) &&
24-
(options.removeEmptyStrings ? value !== '' : true)
25-
) {
26-
result[key] = value;
27-
}
15+
return Object.entries(obj).reduce((result, [key, value]) => {
16+
if (
17+
value !== undefined &&
18+
value !== null &&
19+
(options.removeZero ? value !== 0 : true) &&
20+
(options.removeEmptyStrings ? value !== '' : true)
21+
) {
22+
result[key as keyof T] = value;
2823
}
29-
}
30-
31-
return result;
24+
return result;
25+
}, {} as Partial<T>);
3226
}
3327

3428
export const objectToQueryString = <T extends Record<string, any>>(
3529
params: T,
3630
options?: { removeEmptyStrings?: boolean; removeZero?: boolean },
3731
): string => {
3832
if (!isValidObject(params)) {
39-
return '';
33+
throw new Error('params must be a non-null object');
4034
}
4135

4236
return queryString.stringify(removeFalsyValues(params, options));

0 commit comments

Comments
 (0)