Skip to content

Commit 63f16e3

Browse files
committed
perf: Optimize the prompt messages during collection operations
1 parent 89bb746 commit 63f16e3

6 files changed

Lines changed: 63 additions & 5 deletions

File tree

i18n/locales/en.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@
7272
"Use": "Use",
7373
"Favorite": "Favorite",
7474
"Edit": "Edit",
75-
"Unfavorite": "Remove from Favorites"
75+
"Unfavorite": "Remove from Favorites",
76+
"FavoriteSuccess": "Added to favorites successfully",
77+
"FavoriteFailed": "Failed to save to favorites",
78+
"UnfavoriteSuccess": "Removed from favorites successfully",
79+
"UnfavoriteFailed": "Failed to remove from favorites"
7680
},
7781
"EditModal": {
7882
"ModifyConnectionInfo": "Modify Connection Info",

i18n/locales/zh.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@
7272
"Use": "使用",
7373
"Favorite": "收藏",
7474
"Edit": "编辑",
75-
"Unfavorite": "取消收藏"
75+
"Unfavorite": "取消收藏",
76+
"FavoriteSuccess": "收藏成功",
77+
"FavoriteFailed": "收藏失败",
78+
"UnfavoriteSuccess": "取消收藏成功",
79+
"UnfavoriteFailed": "取消收藏失败"
7680
},
7781
"EditModal": {
7882
"ModifyConnectionInfo": "修改连接信息",

src-tauri/src/commands/set_favorite.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub async fn set_favorite(app: AppHandle, site: String, cookie_header: String, a
1010
if !favorite_data.success {
1111
let _ = app.emit(
1212
"set-favorite-failure",
13-
json!({ "status": favorite_data.status }),
13+
json!({ "status": "failed" }),
1414
);
1515
return;
1616
}

src-tauri/src/commands/unfavorite.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub async fn unfavorite(app: AppHandle, site: String, cookie_header: String, ass
1111
info!("result {:?}", result);
1212

1313
if !result.success {
14-
let _ = app.emit("unfavorite-failure", json!({ "status": result.status }));
14+
let _ = app.emit("unfavorite-failure", json!({ "status": "failed" }));
1515
return;
1616
}
1717

src-tauri/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ pub async fn to_api_response(
166166
ApiResponse {
167167
status,
168168
data,
169-
success: status == 200 || status == 201,
169+
success: status == 200 || status == 201 || status == 204,
170170
}
171171
}
172172
Err(e) => {

ui/composables/useAssetAction.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ let unlistenGetTokenFailure: UnlistenFn | null = null;
1010
let unlistenGetTokenSuccess: UnlistenFn | null = null;
1111
let unlistenFavoriteSuccess: UnlistenFn | null = null;
1212
let unlistenFavoriteFailed: UnlistenFn | null = null;
13+
let unlistenUnfavoriteSuccess: UnlistenFn | null = null;
14+
let unlistenUnfavoriteFailed: UnlistenFn | null = null;
1315
let unlistenGetAssetDetailSuccess: UnlistenFn | null = null;
1416
let unlistenGetAssetDetailFailed: UnlistenFn | null = null;
1517
let unlistenRenameSuccess: UnlistenFn | null = null;
@@ -23,13 +25,17 @@ function releaseTauriEventListeners() {
2325
unlistenFavoriteSuccess?.();
2426
unlistenFavoriteFailed?.();
2527
unlistenGetTokenFailure?.();
28+
unlistenUnfavoriteSuccess?.();
29+
unlistenUnfavoriteFailed?.();
2630
unlistenGetAssetDetailSuccess?.();
2731
unlistenGetAssetDetailFailed?.();
2832
unlistenRenameSuccess?.();
2933
unlistenRenameError?.();
3034
unlistenGetTokenFailure = null;
3135
unlistenGetTokenSuccess = null;
3236
unlistenFavoriteSuccess = null;
37+
unlistenUnfavoriteFailed = null;
38+
unlistenUnfavoriteSuccess = null;
3339
unlistenFavoriteFailed = null;
3440
unlistenGetAssetDetailSuccess = null;
3541
unlistenGetAssetDetailFailed = null;
@@ -351,6 +357,13 @@ export const useAssetAction = () => {
351357
}
352358

353359
const payload = event.payload as eventPayload;
360+
if (payload.status === "success") {
361+
toast.add({
362+
title: t("ContextMenu.FavoriteSuccess"),
363+
color: "primary",
364+
icon: "line-md:check-all"
365+
});
366+
}
354367
});
355368

356369
unlistenFavoriteFailed = await useTauriEventListen("set-favorite-failure", (event) => {
@@ -359,6 +372,43 @@ export const useAssetAction = () => {
359372
}
360373

361374
const payload = event.payload as eventPayload;
375+
if (payload.status === "failed") {
376+
toast.add({
377+
title: t("ContextMenu.FavoriteFailed"),
378+
color: "error",
379+
icon: "line-md:close-circle"
380+
});
381+
}
382+
});
383+
384+
unlistenUnfavoriteSuccess = await useTauriEventListen("unfavorite-success", (event) => {
385+
interface eventPayload {
386+
status: string;
387+
}
388+
389+
const payload = event.payload as eventPayload;
390+
if (payload.status === "success") {
391+
toast.add({
392+
title: t("ContextMenu.UnfavoriteSuccess"),
393+
color: "primary",
394+
icon: "line-md:check-all"
395+
});
396+
}
397+
});
398+
399+
unlistenUnfavoriteFailed = await useTauriEventListen("unfavorite-failure", (event) => {
400+
interface eventPayload {
401+
status: string;
402+
}
403+
404+
const payload = event.payload as eventPayload;
405+
if (payload.status === "failed") {
406+
toast.add({
407+
title: t("ContextMenu.UnfavoriteFailed"),
408+
color: "error",
409+
icon: "line-md:close-circle"
410+
});
411+
}
362412
});
363413

364414
unlistenGetAssetDetailSuccess = await useTauriEventListen("get-asset-detail-success", (event) => {

0 commit comments

Comments
 (0)