feat: remove unused resources (#379)

* feat: dialog content enhancement

* feat: remove unused resources

* update

* update

Co-authored-by: boojack <stevenlgtm@gmail.com>
This commit is contained in:
Zeng1998 2022-10-31 19:23:44 +08:00 committed by GitHub
parent d6fa1c7c80
commit 4276a7a56d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 6 deletions

View File

@ -101,6 +101,31 @@ const ResourcesDialog: React.FC<Props> = (props: Props) => {
toastHelper.success("Succeed to copy resource link to clipboard");
};
const handleDeleteUnusedResourcesBtnClick = () => {
let warningText = t("resources.warning-text-unused");
const unusedResources = resources.filter((resource) => {
if (resource.linkedMemoAmount === 0) {
warningText = warningText + `\n- ${resource.filename}`;
return true;
}
return false;
});
if (unusedResources.length === 0) {
toastHelper.success(t("resources.no-unused-resources"));
return;
}
showCommonDialog({
title: t("resources.delete-resource"),
content: warningText,
style: "warning",
onConfirm: async () => {
for (const resource of unusedResources) {
await resourceService.deleteResourceById(resource.id);
}
},
});
};
const handleDeleteResourceBtnClick = (resource: Resource) => {
let warningText = t("resources.warning-text");
if (resource.linkedMemoAmount > 0) {
@ -149,6 +174,11 @@ const ResourcesDialog: React.FC<Props> = (props: Props) => {
<span>{t("resources.upload")}</span>
</div>
</div>
<div className="delete-unused-resource-container">
<button className="delete-unused-resource-btn" onClick={handleDeleteUnusedResourcesBtnClick}>
{t("resources.clear-unused-resources")}
</button>
</div>
{loadingState.isLoading ? (
<div className="loading-text-container">
<p className="tip-text">{t("resources.fetching-data")}</p>

View File

@ -21,6 +21,14 @@
}
}
> .delete-unused-resource-container {
@apply flex w-full justify-end;
> .delete-unused-resource-btn {
@apply text-sm py-1 px-3 mr-2 rounded-md hover:opacity-80 bg-red-100 border border-solid border-red-600 text-red-600;
}
}
> .loading-text-container {
@apply flex flex-col justify-center items-center w-full h-32;
}

View File

@ -63,9 +63,12 @@
"preview": "Preview",
"copy-link": "Copy Link",
"delete-resource": "Delete Resource",
"warning-text": "Are you sure to delete this resource? THIS ACTION IS IRREVERSIABLE❗",
"warning-text": "Are you sure to delete this resource? THIS ACTION IS IRREVERSIABLE❗",
"linked-amount": "Linked memo amount",
"rename": "Rename"
"rename": "Rename",
"clear-unused-resources": "Clear unused resources",
"warning-text-unused": "Are you sure to delete these unused resource? THIS ACTION IS IRREVERSIABLE❗",
"no-unused-resources": "No unused resources"
},
"archived": {
"archived-memos": "Archived Memos",

View File

@ -63,9 +63,12 @@
"preview": "Xem trước",
"copy-link": "Sao chép",
"delete-resource": "Xóa tài nguyên",
"warning-text": "Bạn có chắc chắn xóa tài nguyên này không? HÀNH ĐỘNG KHÔNG THỂ KHÔI PHỤC❗",
"warning-text": "Bạn có chắc chắn xóa tài nguyên này không? HÀNH ĐỘNG KHÔNG THỂ KHÔI PHỤC❗",
"linked-amount": "Số memo đã liên kết",
"rename": "đổi tên"
"rename": "đổi tên",
"clear-unused-resources": "Xóa tài nguyên không sử dụng",
"warning-text-unused": "Bạn có chắc chắn xóa những tài nguyên không sử dụng này không? HÀNH ĐỘNG KHÔNG THỂ KHÔI PHỤC❗",
"no-unused-resources": "Không có tài nguyên không sử dụng"
},
"archived": {
"archived-memos": "Memo đã lưu trữ",

View File

@ -63,9 +63,12 @@
"preview": "预览",
"copy-link": "拷贝链接",
"delete-resource": "删除资源",
"warning-text": "确定删除这个资源么?此操作不可逆❗",
"warning-text": "确定删除这个资源么?此操作不可逆❗",
"linked-amount": "链接的 Memo 数量",
"rename": "重命名"
"rename": "重命名",
"clear-unused-resources": "清除无用资源",
"warning-text-unused": "确定删除这些无用资源么?此操作不可逆❗",
"no-unused-resources": "无可删除的资源"
},
"archived": {
"archived-memos": "已归档的 Memo",