Skip to content

Commit

Permalink
Merge pull request #214 from ssu-student-union/feat/#196_add-channel-…
Browse files Browse the repository at this point in the history
…talk

Feat/#196 add channel talk
  • Loading branch information
Kangnets authored Oct 11, 2024
2 parents c276ab2 + 03162c1 commit e4555e9
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 118 deletions.
2 changes: 1 addition & 1 deletion src/apis/postBoardDataSubCategoryPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { client } from '@/apis/client';

export const postBoardDataSubCategoryPosts = (
fileCategory: string,
fileType: string,
fileType: (string | null)[],
resBody: object,
accessToken: string
) => {
Expand Down
46 changes: 17 additions & 29 deletions src/pages/data/containers/dataBoxSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface Post {
fileData: string[];
fileNames: string[];
fileUrl: string[];
fileType: string[];
fileType: string | never[]; // Allow empty array here
title?: string;
date?: string; // Make it optional
content?: string[];
Expand Down Expand Up @@ -69,31 +69,24 @@ export default function DataBoxSection({ userId, authority }: DataBoxSectionProp

const fetchTotalData = async (page: number = 1) => {
try {
console.log('fetchTotalData called');

const TotalResponse = await getBoardDataPosts({ filters, page });

if (TotalResponse.data?.data?.postListResDto?.length > 0) {
console.log('TotalElements', TotalResponse.data.data.pageInfo.totalElements);
setInitialTotalElements(TotalResponse.data.data.pageInfo.totalElements);
}
} catch (error) {
console.error('Error fetching latest special category:', error);
('');
}
};

const fetchLatestSpecialCategory = async (page: number = 1) => {
try {
console.log('fetchLatestSpecialCategory called');

const filters = {
subCategory: '총학생회칙',
};
const latestResponse = await getBoardDataPosts({ filters, page });

if (latestResponse.data?.data?.postListResDto?.length > 0) {
console.log('latestResponse', latestResponse);

const latestPost = latestResponse.data.data.postListResDto[0];
setLatestDataBox({
postId: latestPost.postId,
Expand All @@ -109,10 +102,9 @@ export default function DataBoxSection({ userId, authority }: DataBoxSectionProp
isNotice: latestPost.isNotice || false,
// Add other necessary fields
});
console.log('latestDataBox', latestDataBox);
}
} catch (error) {
console.error('Error fetching latest special category:', error);
('');
}
};

Expand All @@ -127,7 +119,6 @@ export default function DataBoxSection({ userId, authority }: DataBoxSectionProp
category: filters.subCategory,
q: searchInput,
});
console.log('Search API Response:', searchResponse);

if (searchResponse?.data?.postListResDto) {
const currentTotalElements = searchResponse.data.pageInfo.totalElements;
Expand All @@ -153,32 +144,24 @@ export default function DataBoxSection({ userId, authority }: DataBoxSectionProp
fileType: post.files ? post.files.map((file: File) => file.fileType) : [],
}));

console.log('categorizedDataBoxes', categorizedDataBoxes);
setDataBoxes(categorizedDataBoxes);
setTotalPage(searchResponse.data.pageInfo.totalPages);
} else {
console.error('API response data structure is not as expected:', searchResponse);
setDataBoxes([]);
}
} catch (error) {
console.error('Error fetching data:', error);
setDataBoxes([]);
}
};

const fetchData = async (filters: any = {}, page: number = 1) => {
console.log('Fetching data with filters:', filters);
try {
const response = await getBoardDataPosts({ filters, page });
console.log('API Response:', response);
setData(response.data);

if (response.data?.data?.postListResDto?.length > 0) {
const currentTotalElements = response.data.data.pageInfo.totalElements;

console.log('currentTotalElements', currentTotalElements);
console.log('initialTotalElements', initialTotalElements);

if (
(initialTotalElements !== null && currentTotalElements > initialTotalElements) ||
currentTotalElements === 0
Expand Down Expand Up @@ -209,7 +192,6 @@ export default function DataBoxSection({ userId, authority }: DataBoxSectionProp
};

useEffect(() => {
console.log('fetchLatestSpecialCategory called');
fetchLatestSpecialCategory();
}, []);

Expand Down Expand Up @@ -327,7 +309,7 @@ export default function DataBoxSection({ userId, authority }: DataBoxSectionProp
<div className="mt-[5px] flex justify-end space-x-2" onClick={(e) => e.stopPropagation()}>
{Array.isArray(data.fileUrl) && data.fileUrl.length > 0 ? (
data.fileUrl.map((fileUrl: string, fileIndex: number) => {
const fileType = data.fileType[fileIndex] || '';
const fileType = data.fileType[fileIndex].split(',')[fileIndex] || '';
const fileName = data.fileNames[fileIndex] || 'Unknown File';
return (
<button
Expand All @@ -340,27 +322,33 @@ export default function DataBoxSection({ userId, authority }: DataBoxSectionProp
);
})
) : (
<span className="text-sm text-gray-500">No Files</span>
<span className="text-sm text-gray-500">등록된 게시물이 없습니다</span>
)}
</div>
</div>
))
) : (
<div className="text-center text-lg font-medium text-gray-500">데이터가 없습니다.</div>
<div className="mb-72 mt-72 text-center text-lg font-medium text-gray-500">등록된 게시물이 없습니다</div>
)}

<div className="mt-[34px] xs:flex xs:justify-center sm:flex sm:justify-center md:flex md:justify-center lg:hidden xl:hidden xxl:hidden">
{isAuthor ? <DataEditBtn /> : null}
</div>

<div className="mt-[109px] flex w-full justify-between text-lg xs:mt-[34px] sm:mt-[34px] md:mt-[34px] lg:mt-[49px] lg:pl-[123px] xl:mt-[49px] xl:pl-[123px]">
<Pagination totalPages={totalPage} currentPage={currentPage} onPageChange={handlePageChange} />
{isAuthor && (
{isAuthor && (
<div className="mt-[109px] flex w-full justify-between text-lg xs:mt-[34px] sm:mt-[34px] md:mt-[34px] lg:mt-[49px] lg:pl-[123px] xl:mt-[49px] xl:pl-[123px] xxl:pl-[123px]">
<Pagination totalPages={totalPage} currentPage={currentPage} onPageChange={handlePageChange} />
<div className="hidden lg:block xl:block xxl:block">
<DataEditBtn />
</div>
)}
</div>
</div>
)}

{!isAuthor && (
<div className="mt-[109px] flex w-full justify-between text-lg xs:mt-[34px] sm:mt-[34px] md:mt-[34px] lg:mt-[49px] xl:mt-[49px] ">
<Pagination totalPages={totalPage} currentPage={currentPage} onPageChange={handlePageChange} />
</div>
)}
</div>
</div>
</>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/data/containers/edit/EditSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export default function UploadSection({ userId }: { userId: string }) {
const fileName = newFileData.fileName.length > 0 ? newFileData.fileName : null;
const userName = userId || 'Unknown';
const fileCategory = newFileData.category.length > 0 ? newFileData.category[0] : 'defaultCategory'; // 'defaultCategory'를 기본값으로 설정
const fileType = '결과보고서';
const fileType = newFileData.fileType.length > 0 ? newFileData.fileType[0] : 'defaultFileType'; // 'defaultCategory'를 기본값으로 설정

console.log(fileName);

Expand Down Expand Up @@ -281,13 +281,13 @@ export default function UploadSection({ userId }: { userId: string }) {
postFileList: fileUrls,
};

const response = await postBoardDataSubCategoryPosts(fileCategory, fileType, resBody, accessToken);
const response = await postBoardDataSubCategoryPosts(fileCategory, [fileType], resBody, accessToken);

console.log('Post Response:', response);

if (response.status === 200) {
alert('파일 업로드가 완료되었습니다.');
navigate('/homepage-frontend/data');
navigate('/data');
} else {
alert('오류가 발생했습니다. 다시 시도해주세요.');
}
Expand Down
Loading

0 comments on commit e4555e9

Please sign in to comment.