From bae1e930aa242f0d692d352908bc352432e1132c Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Thu, 25 Jan 2024 17:08:39 +0100 Subject: [PATCH] Refactor photo update logic and remove unused code --- SoarCraft.AwaiShop/AdminHub/Product/Patch.cs | 3 ++- src/Pages/Admin/Product/Photo/Edit.tsx | 28 +++++++------------- src/Pages/Admin/Product/Photo/index.tsx | 8 +++--- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/SoarCraft.AwaiShop/AdminHub/Product/Patch.cs b/SoarCraft.AwaiShop/AdminHub/Product/Patch.cs index 3dbb925..d7da6db 100644 --- a/SoarCraft.AwaiShop/AdminHub/Product/Patch.cs +++ b/SoarCraft.AwaiShop/AdminHub/Product/Patch.cs @@ -122,7 +122,8 @@ public async Task ProductPatchCaption(uint photoId, string caption) { var row = await this.Db.Photos .Where(x => x.PhotoId == photoId) - .ExecuteUpdateAsync(x => x.SetProperty(p => p.Caption, caption)); + .ExecuteUpdateAsync(x => + x.SetProperty(p => p.Caption, caption)); return row > 0; } diff --git a/src/Pages/Admin/Product/Photo/Edit.tsx b/src/Pages/Admin/Product/Photo/Edit.tsx index ef3d901..513beed 100644 --- a/src/Pages/Admin/Product/Photo/Edit.tsx +++ b/src/Pages/Admin/Product/Photo/Edit.tsx @@ -30,24 +30,14 @@ const useStyles = makeStyles({ } }); -/** - * @author Aloento - * @since 0.5.0 - * @version 0.1.0 - */ -interface IAdminProductPhotoEdit { - Photo: IPhotoItem; - Refresh: () => void; -} - const log = new Logger("Admin", "Product", "Detail", "Photo", "Edit"); /** * @author Aloento * @since 0.5.0 - * @version 0.3.4 + * @version 0.3.5 */ -export function AdminProductPhotoEdit({ Photo: { Id, Cover, Caption, ProductId }, Refresh }: IAdminProductPhotoEdit) { +export function AdminProductPhotoEdit({ Id, Cover, Caption, ProductId }: IPhotoItem) { const style = useStyles(); const [cap, setCap] = useState(Caption || ""); @@ -69,13 +59,19 @@ export function AdminProductPhotoEdit({ Photo: { Id, Cover, Caption, ProductId } , { intent: "success" } ); - - Refresh(); } }); const { run: updateFile } = AdminHub.Product.Patch.usePhoto(log, { manual: true, + onBefore([prodId, file]) { + dispatchToast( + + Uploading Photo {file.name} for Product {prodId} to replace {Id} + , + { intent: "info" } + ); + }, onError(e, req) { dispatch({ Message: "Failed Update Photo", @@ -90,8 +86,6 @@ export function AdminProductPhotoEdit({ Photo: { Id, Cover, Caption, ProductId } , { intent: "success" } ); - - Refresh(); } }); @@ -111,8 +105,6 @@ export function AdminProductPhotoEdit({ Photo: { Id, Cover, Caption, ProductId } , { intent: "success" } ); - - Refresh(); } }); diff --git a/src/Pages/Admin/Product/Photo/index.tsx b/src/Pages/Admin/Product/Photo/index.tsx index 9ff0979..5ac0b10 100644 --- a/src/Pages/Admin/Product/Photo/index.tsx +++ b/src/Pages/Admin/Product/Photo/index.tsx @@ -45,7 +45,7 @@ export interface IPhotoItem { /** * @author Aloento * @since 0.5.0 - * @version 0.1.2 + * @version 0.1.3 */ const columns: TableColumnDefinition[] = [ MakeCoverCol(70, log), @@ -96,7 +96,7 @@ const columns: TableColumnDefinition[] = [ onClick={() => run(item.Id, false)} /> - + ) }, @@ -104,9 +104,7 @@ const columns: TableColumnDefinition[] = [ ] /** - * @author Aloento - * @since 0.5.0 - * @version 0.1.0 + * @deprecated */ let refreshCarousel: () => void = () => { };