Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] 결과 수정 페이지 api 연동, 기능 구현 #111

Merged
merged 31 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
338a9d2
fix(apps/web): useScroll 버그 수정
minseong0324 Feb 6, 2025
ae91471
feat(packages/ui): TextField.Submit disabled 상태 추가
minseong0324 Feb 6, 2025
1ca9aa8
feat(apps/web): 게시물 그룹별 게시물 목록 조회 API
minseong0324 Feb 6, 2025
aa71d6f
feat(apps/web): 게시물 프롬프트 기반 일괄 수정
minseong0324 Feb 6, 2025
91aa11a
feat(apps/web): 게시물 기타 정보 수정 API
minseong0324 Feb 6, 2025
f094f50
feat(apps/web): 게시물 개별 삭제 API
minseong0324 Feb 6, 2025
d0da5da
feat(apps/web): 게시물 추가 생성 API
minseong0324 Feb 6, 2025
65eb046
fix(apps/web): DND 버그 수정
minseong0324 Feb 6, 2025
1912ebf
feat(apps/web): 타입 추가
minseong0324 Feb 6, 2025
520e708
feat(apps/web): 결과 수정 페이지 기능 구현 완료
minseong0324 Feb 6, 2025
87fdcc9
remove(apps/web): 불필요 코드 삭제
minseong0324 Feb 6, 2025
fe5c934
refactor(apps/web): SkeletonItems 분리
minseong0324 Feb 6, 2025
a228b1b
feat(packages/ui): TextField 'white' variant 추가
minseong0324 Feb 6, 2025
4652ee8
feat(packages/ui): TextField 'white' variant 추가
minseong0324 Feb 6, 2025
440dba2
Merge branch 'develop' of https://github.com/YAPP-Github/25th-Web-Tea…
minseong0324 Feb 6, 2025
31b9b20
fix(apps/web): 자잘한 수정
minseong0324 Feb 6, 2025
f5b82d3
fix(apps/web): invalidate 제거. 데이터 패칭으로 인해 버벅임
minseong0324 Feb 6, 2025
bcf716a
feat(apps/web): optimistic update 추가
minseong0324 Feb 7, 2025
ccd253d
remove(apps/web): SkeletonItems 삭제
minseong0324 Feb 7, 2025
a845c00
feat(apps/web): optimistic update 추가
minseong0324 Feb 7, 2025
d0000be
fix(apps/web): optimistic update 제거
minseong0324 Feb 7, 2025
d23040a
chore(apps/web): 베럴 파일 추가 및 import, export 경로 수정
minseong0324 Feb 7, 2025
e7dba51
fix(apps/web): dnd, 정렬 버그 수정
minseong0324 Feb 7, 2025
803e6e6
feat(apps/web): 게시글 eof 값에 따라 생성 막기
minseong0324 Feb 7, 2025
7381cad
fix(apps/web): 로딩 상태
minseong0324 Feb 7, 2025
d888d60
feat(apps/web): 생성 중에 dnd 방지, 예약하러가기 방지
minseong0324 Feb 7, 2025
0038e9f
wip
minseong0324 Feb 7, 2025
92738a6
fix(apps/web): 상태 업데이트 해결 및 불필요 로직 제거, 리팩토링
minseong0324 Feb 7, 2025
40e5a11
fix(apps/web): 불필요 상태 반영 및 드롭 시 콜백 버그 수정
minseong0324 Feb 7, 2025
f6471b7
remove(apps/web): 불필요 코드 삭제
minseong0324 Feb 7, 2025
617c9f5
fix(apps/web): 불필요 스타일 제거
minseong0324 Feb 7, 2025
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
219 changes: 57 additions & 162 deletions apps/web/src/app/(prompt)/edit/[agentId]/[postGroupId]/Edit.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
'use client';

import React, { RefObject } from 'react';
import { useScroll } from '@web/hooks';
import * as style from './pageStyle.css';
import { NavBar, MainBreadcrumbItem } from '@web/components/common';
import { Breadcrumb, Button, Chip, Icon, Accordion } from '@repo/ui';
import { Breadcrumb, Button, Icon } from '@repo/ui';
import { POST_STATUS } from '@web/types/post';
import { INITIAL_CONTENT_ITEMS } from './constants';
import { DndController, useDndController } from '@web/components/common';
import { DndController } from '@web/components/common';
import { EditPageParams } from './types';
import { DragGuide } from './_components/DragGuide/DragGuide';
import { useGetAllPostsQuery } from '@web/store/query/useGetAllPostsQuery';
import { useUpdatePostsMutation } from '@web/store/mutation/useUpdatePostsMutation';
import { useRouter } from 'next/navigation';
import { EditContent } from './_components/EditContent/EditContent';
import { SKELETON_STATUS } from '@web/types/post';

type EditContentProps = {
scrollRef: RefObject<HTMLDivElement>;
isScrolled: boolean;
agentId: EditPageParams['agentId'];
postGroupId: EditPageParams['postGroupId'];
};
export default function Edit({ agentId, postGroupId }: EditPageParams) {
const [scrollRef, isScrolled] = useScroll<HTMLDivElement>({ threshold: 100 });
const { data: posts } = useGetAllPostsQuery({
agentId,
postGroupId,
});
const { mutate: updatePosts } = useUpdatePostsMutation({
agentId,
postGroupId,
});
Comment on lines +17 to +24
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

로딩 및 에러 상태 처리가 필요합니다.

데이터 페칭 시 로딩 상태와 에러 상태 처리가 누락되어 있습니다.

다음과 같이 개선하세요:

-  const { data: posts } = useGetAllPostsQuery({
+  const { data: posts, isLoading, error } = useGetAllPostsQuery({
     agentId,
     postGroupId,
   });
   const { mutate: updatePosts } = useUpdatePostsMutation({
     agentId,
     postGroupId,
   });
+
+  if (isLoading) return <LoadingSpinner />;
+  if (error) return <ErrorComponent message={error.message} />;
+  if (!posts?.data?.posts) return null;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const { data: posts } = useGetAllPostsQuery({
agentId,
postGroupId,
});
const { mutate: updatePosts } = useUpdatePostsMutation({
agentId,
postGroupId,
});
const { data: posts, isLoading, error } = useGetAllPostsQuery({
agentId,
postGroupId,
});
const { mutate: updatePosts } = useUpdatePostsMutation({
agentId,
postGroupId,
});
if (isLoading) return <LoadingSpinner />;
if (error) return <ErrorComponent message={error.message} />;
if (!posts?.data?.posts) return null;

const router = useRouter();

function EditContent({
scrollRef,
isScrolled,
agentId,
postGroupId,
}: EditContentProps) {
const { getItemsByStatus, handleRemove } = useDndController();
/**
* READY_TO_UPLOAD 상태인 게시물이 있는지 확인
*/
const hasReadyToUploadPosts = posts.data.posts.some(
(post) => post.status === POST_STATUS.READY_TO_UPLOAD
);

/**
* 스켈레톤 상태(생성중)인 포스트가 있는지 확인
*/
const isGenerating = posts.data.posts.some(
(post) => post.uploadTime === SKELETON_STATUS
);

return (
<div className={style.mainStyle} ref={scrollRef}>
Expand All @@ -41,8 +54,10 @@ function EditContent({
size="large"
variant="primary"
leftAddon={<Icon name="checkCalendar" size={20} />}
onClick={() => {}}
disabled={false}
onClick={() =>
router.push(`/edit/${agentId}/${postGroupId}/schedule`)
}
disabled={!hasReadyToUploadPosts || isGenerating}
isLoading={false}
className={style.submitButtonStyle}
>
Expand All @@ -51,148 +66,28 @@ function EditContent({
}
isScrolled={isScrolled}
/>
<div className={style.contentStyle}>
<Accordion
type="multiple"
defaultValue={[
POST_STATUS.GENERATED,
POST_STATUS.EDITING,
POST_STATUS.READY_TO_UPLOAD,
]}
className={style.accordionStyle}
>
{/* 생성된 글 영역 */}
<Accordion.Item
value={POST_STATUS.GENERATED}
className={style.accordionItemStyle}
>
<Accordion.Trigger className={style.accordionTriggerStyle}>
<Chip variant="grey">생성된 글</Chip>
</Accordion.Trigger>
<Accordion.Content>
<DndController.Droppable id={POST_STATUS.GENERATED}>
<DndController.SortableList
items={getItemsByStatus(POST_STATUS.GENERATED).map(
(item) => item.id
)}
>
{getItemsByStatus(POST_STATUS.GENERATED).map((item) => (
<DndController.Item
key={item.id}
id={item.id}
summary={item.summary}
updatedAt={item.updatedAt}
onRemove={() => handleRemove(item.id)}
onModify={() => {}}
/>
))}
</DndController.SortableList>
</DndController.Droppable>
</Accordion.Content>
</Accordion.Item>

{/* 수정 중인 글 영역 */}
<Accordion.Item
value={POST_STATUS.EDITING}
className={style.accordionItemStyle}
>
<Accordion.Trigger className={style.accordionTriggerStyle}>
<Chip variant="purple">수정 중인 글</Chip>
</Accordion.Trigger>
<Accordion.Content id={POST_STATUS.EDITING}>
<DndController.Droppable id={POST_STATUS.EDITING}>
<DndController.SortableList
items={getItemsByStatus(POST_STATUS.EDITING).map(
(item) => item.id
)}
>
{getItemsByStatus(POST_STATUS.EDITING).length > 0 ? (
getItemsByStatus(POST_STATUS.EDITING).map((item) => (
<DndController.Item
key={item.id}
id={item.id}
summary={item.summary}
updatedAt={item.updatedAt}
onRemove={() => handleRemove(item.id)}
onModify={() => {}}
/>
))
) : (
<DragGuide description="수정 중인 글을 끌어서 여기에 놓아주세요" />
)}
</DndController.SortableList>
</DndController.Droppable>
</Accordion.Content>
</Accordion.Item>

{/* 업로드할 글 영역 */}
<Accordion.Item
value={POST_STATUS.READY_TO_UPLOAD}
className={style.accordionItemStyle}
>
<Accordion.Trigger className={style.accordionTriggerStyle}>
<Chip variant="green">업로드할 글</Chip>
</Accordion.Trigger>
<Accordion.Content id={POST_STATUS.READY_TO_UPLOAD}>
<DndController.Droppable id={POST_STATUS.READY_TO_UPLOAD}>
<DndController.SortableList
items={getItemsByStatus(POST_STATUS.READY_TO_UPLOAD).map(
(item) => item.id
)}
>
{getItemsByStatus(POST_STATUS.READY_TO_UPLOAD).length > 0 ? (
getItemsByStatus(POST_STATUS.READY_TO_UPLOAD).map(
(item) => (
<DndController.Item
key={item.id}
id={item.id}
summary={item.summary}
updatedAt={item.updatedAt}
onRemove={() => handleRemove(item.id)}
onModify={() => {}}
/>
)
)
) : (
<DragGuide description="업로드가 준비된 글을 끌어서 여기에 놓아주세요" />
)}
</DndController.SortableList>
</DndController.Droppable>
</Accordion.Content>
</Accordion.Item>
</Accordion>
</div>
<DndController
key={posts.data.posts.map((p) => p.id).join(',')}
initialItems={posts.data.posts}
disabled={isGenerating}
onDragEnd={
isGenerating
? undefined
: (updatedItems) => {
const updatePayload = {
posts: updatedItems.map((item) => ({
postId: item.id,
status: item.status,
displayOrder: item.displayOrder,
uploadTime: item.uploadTime,
})),
};
updatePosts(updatePayload);
}
}
>
<EditContent agentId={agentId} postGroupId={postGroupId} />
</DndController>
</div>
);
}

export default function Edit({ agentId, postGroupId }: EditPageParams) {
const [scrollRef, isScrolled] = useScroll<HTMLDivElement>({ threshold: 100 });

return (
<DndController
initialItems={INITIAL_CONTENT_ITEMS}
onDragEnd={(items) => {
console.log('=== Current Items Status ===');
const itemsByStatus = {
GENERATED: items.filter((item) => item.status === 'GENERATED'),
EDITING: items.filter((item) => item.status === 'EDITING'),
READY_TO_UPLOAD: items.filter(
(item) => item.status === 'READY_TO_UPLOAD'
),
};
console.log('GENERATED:', itemsByStatus.GENERATED);
console.log('EDITING:', itemsByStatus.EDITING);
console.log('READY_TO_UPLOAD:', itemsByStatus.READY_TO_UPLOAD);
console.log('========================');
}}
>
<EditContent
scrollRef={scrollRef}
isScrolled={isScrolled}
agentId={agentId}
postGroupId={postGroupId}
/>
</DndController>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { style } from '@vanilla-extract/css';
import { vars } from '@repo/theme';

export const contentStyle = style({
position: 'relative',
width: '100%',
padding: `${vars.space[80]} ${vars.space[24]}`,
margin: '0 auto',
overflowX: 'auto',
});

export const submitButtonStyle = style({
fontSize: vars.typography.fontSize[18],
});

export const accordionStyle = style({
display: 'flex',
gap: vars.space[64],
height: 'fit-content',
minWidth: 'min-content',
padding: `0 ${vars.space[32]}`,
});

export const accordionTriggerStyle = style({
height: '8rem',
padding: `${vars.space[12]} ${vars.space[16]}`,
});

export const accordionItemStyle = style({
width: '51.2rem',
flex: '0 0 auto',
});

export const accordionContentStyle = style({
display: 'flex',
flexDirection: 'column',
gap: vars.space[10],
});

export const contentInnerWrapper = style({
height: '100%',
});

export const buttonWrapperStyle = style({
display: 'flex',
justifyContent: 'flex-end',
});
Loading