From 4276a7a56db3a4460b1f71814f5a2134d3ad2234 Mon Sep 17 00:00:00 2001 From: Zeng1998 <1129142694@qq.com> Date: Mon, 31 Oct 2022 19:23:44 +0800 Subject: [PATCH] feat: remove unused resources (#379) * feat: dialog content enhancement * feat: remove unused resources * update * update Co-authored-by: boojack --- web/src/components/ResourcesDialog.tsx | 30 ++++++++++++++++++++++++++ web/src/less/resources-dialog.less | 8 +++++++ web/src/locales/en.json | 7 ++++-- web/src/locales/vi.json | 7 ++++-- web/src/locales/zh.json | 7 ++++-- 5 files changed, 53 insertions(+), 6 deletions(-) diff --git a/web/src/components/ResourcesDialog.tsx b/web/src/components/ResourcesDialog.tsx index 986cc04b5..637f6ffeb 100644 --- a/web/src/components/ResourcesDialog.tsx +++ b/web/src/components/ResourcesDialog.tsx @@ -101,6 +101,31 @@ const ResourcesDialog: React.FC = (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) => { {t("resources.upload")} +
+ +
{loadingState.isLoading ? (

{t("resources.fetching-data")}

diff --git a/web/src/less/resources-dialog.less b/web/src/less/resources-dialog.less index c3aa5aa98..a01656705 100644 --- a/web/src/less/resources-dialog.less +++ b/web/src/less/resources-dialog.less @@ -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; } diff --git a/web/src/locales/en.json b/web/src/locales/en.json index 1ce2975f9..db87e0f72 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -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", diff --git a/web/src/locales/vi.json b/web/src/locales/vi.json index 9927e613c..1d3336a57 100644 --- a/web/src/locales/vi.json +++ b/web/src/locales/vi.json @@ -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ữ", diff --git a/web/src/locales/zh.json b/web/src/locales/zh.json index 1a0a08f91..883411a08 100644 --- a/web/src/locales/zh.json +++ b/web/src/locales/zh.json @@ -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",