Skip to content

Commit

Permalink
Refactor: admin file list name fix
Browse files Browse the repository at this point in the history
  • Loading branch information
swgvenghy committed Aug 12, 2024
1 parent babd69b commit 985ac03
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/ui/pages/admin/file-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,30 @@ const FileList: React.FC = () => {
console.error('Upload failed', error);
}
setUploading(false);
setFileList([]);
};

useEffect(() => {
const fetchData = async () => {
setLoading(true);
try {
const response = await adminRetrieveFile({ type, category });
const formattedData = response.documents.reduce((acc: DataListType[], item: any) => {
const exists = acc.find((data) => data.title === item.title);
if (!exists) {
acc.push({
title: item.title,
createdAt: item.created_at,
});
}
return acc;
}, []);
console.log(dataList);
const formattedData: DataListType[] = [];

Object.keys(response.documents).forEach((key) => {
const documentsArray = response.documents[key];

documentsArray.forEach((item: any) => {
const exists = formattedData.find((data) => data.title === item.title);
if (!exists) {
formattedData.push({
title: item.title,
createdAt: item.created_at,
});
}
});
});

setDataList(formattedData);
} catch (error) {
console.error('다운로드 에러', error);
Expand Down

0 comments on commit 985ac03

Please sign in to comment.