Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
Refactor photo update logic and remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
Aloento committed Jan 25, 2024
1 parent fbc3ba2 commit bae1e93
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
3 changes: 2 additions & 1 deletion SoarCraft.AwaiShop/AdminHub/Product/Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ public async Task<bool> 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;
}
Expand Down
28 changes: 10 additions & 18 deletions src/Pages/Admin/Product/Photo/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 || "");

Expand All @@ -69,13 +59,19 @@ export function AdminProductPhotoEdit({ Photo: { Id, Cover, Caption, ProductId }
</Toast>,
{ intent: "success" }
);

Refresh();
}
});

const { run: updateFile } = AdminHub.Product.Patch.usePhoto(log, {
manual: true,
onBefore([prodId, file]) {
dispatchToast(
<Toast>
<ToastTitle>Uploading Photo {file.name} for Product {prodId} to replace {Id}</ToastTitle>
</Toast>,
{ intent: "info" }
);
},
onError(e, req) {
dispatch({
Message: "Failed Update Photo",
Expand All @@ -90,8 +86,6 @@ export function AdminProductPhotoEdit({ Photo: { Id, Cover, Caption, ProductId }
</Toast>,
{ intent: "success" }
);

Refresh();
}
});

Expand All @@ -111,8 +105,6 @@ export function AdminProductPhotoEdit({ Photo: { Id, Cover, Caption, ProductId }
</Toast>,
{ intent: "success" }
);

Refresh();
}
});

Expand Down
8 changes: 3 additions & 5 deletions src/Pages/Admin/Product/Photo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export interface IPhotoItem {
/**
* @author Aloento
* @since 0.5.0
* @version 0.1.2
* @version 0.1.3
*/
const columns: TableColumnDefinition<IPhotoItem>[] = [
MakeCoverCol(70, log),
Expand Down Expand Up @@ -96,17 +96,15 @@ const columns: TableColumnDefinition<IPhotoItem>[] = [
onClick={() => run(item.Id, false)}
/>

<AdminProductPhotoEdit Photo={item} Refresh={refreshCarousel} />
<AdminProductPhotoEdit {...item} />
</DataGridCell>
)
},
})
]

/**
* @author Aloento
* @since 0.5.0
* @version 0.1.0
* @deprecated
*/
let refreshCarousel: () => void = () => { };

Expand Down

0 comments on commit bae1e93

Please sign in to comment.