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

Commit

Permalink
[Back] ProductDeletePhoto | ProductPostMovePhoto | Remove Cover - [Fr…
Browse files Browse the repository at this point in the history
…ont] DelegateDataGrid | GuidImage | AdminProductPhotoAction | AdminProductPhotoEditCaption | AdminProductPhotoEditDelete | AdminProductPhotoEditReplace | MakeCoverCol | ProductCarousel | usePhoto | useMovePhoto | useGet
  • Loading branch information
Aloento committed Mar 2, 2024
1 parent 82f809c commit 85fb050
Show file tree
Hide file tree
Showing 43 changed files with 386 additions and 277 deletions.
18 changes: 14 additions & 4 deletions TSystems.LoveOTC/AdminHub/Product/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,25 @@ internal partial class AdminHub {
* <remarks>
* @author Aloento
* @since 0.1.0
* @version 0.2.0
* @version 0.3.0
* </remarks>
*/
public async Task<bool> ProductDeletePhoto(uint photoId) {
var res = await this.Db.Photos
.Where(x => x.PhotoId == photoId)
var where = this.Db.Photos
.Where(x => x.PhotoId == photoId);

var objId = await where
.Select(x => x.ObjectId)
.SingleAsync();

await this.Db.Objects
.Where(x => x.Id == objId)
.ExecuteDeleteAsync();

return res > 0;
await where
.ExecuteDeleteAsync();

return true;
}

/**
Expand Down
10 changes: 7 additions & 3 deletions TSystems.LoveOTC/AdminHub/Product/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task<uint> ProductPostCreate(string name) {
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 1.0.0
* @version 1.1.0
* </remarks>
*/
public async Task<bool> ProductPostMovePhoto(uint photoId, bool up) {
Expand All @@ -57,14 +57,18 @@ public async Task<bool> ProductPostMovePhoto(uint photoId, bool up) {
if (current == 1)
throw new HubException("Photo already at top");

var prev = photos[index - 1].Order;

photos[index - 1].Order = current;
photos[index].Order = (byte)(current - 1);
photos[index].Order = prev;
} else {
if (current == photos.Last().Order)
throw new HubException("Photo already at bottom");

var next = photos[index + 1].Order;

photos[index + 1].Order = current;
photos[index].Order = (byte)(current + 1);
photos[index].Order = next;
}

await this.Db.SaveChangesAsync();
Expand Down
3 changes: 2 additions & 1 deletion TSystems.LoveOTC/Hub/Product/Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ public Task<uint[]> ProductGetComboList(uint prodId) =>
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 0.2.0
* @version 0.2.1
* </remarks>
*/
public Task<uint[]> ProductGetPhotoList(uint prodId) =>
this.Db.Photos
.Where(x => x.ProductId == prodId)
.OrderBy(x => x.Order)
.Select(x => x.PhotoId)
.ToArrayAsync();
}
8 changes: 1 addition & 7 deletions TSystems.LoveOTC/Migrations/20240107210741_Init.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion TSystems.LoveOTC/Migrations/20240107210741_Init.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ protected override void Up(MigrationBuilder migrationBuilder)
columns: table => new
{
PhotoId = table.Column<long>(type: "bigint", nullable: false),
Cover = table.Column<bool>(type: "boolean", nullable: true),
Caption = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
Order = table.Column<byte>(type: "smallint", nullable: false),
ObjectId = table.Column<Guid>(type: "uuid", nullable: false),
Expand Down
8 changes: 1 addition & 7 deletions TSystems.LoveOTC/Migrations/ShopContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Proxies:ChangeTracking", false)
.HasAnnotation("Proxies:CheckEquality", false)
.HasAnnotation("Proxies:LazyLoading", true)
.HasAnnotation("ProductVersion", "8.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 63);

NpgsqlModelBuilderExtensions.UseHiLo(modelBuilder, "EntityFrameworkHiLoSequence");
Expand Down Expand Up @@ -215,9 +212,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasMaxLength(100)
.HasColumnType("character varying(100)");

b.Property<bool?>("Cover")
.HasColumnType("boolean");

b.Property<Guid>("ObjectId")
.HasColumnType("uuid");

Expand Down
4 changes: 1 addition & 3 deletions TSystems.LoveOTC/Models/Photo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ namespace TSystems.LoveOTC.Models;
* <remarks>
* @author Aloento
* @since 0.1.0
* @version 0.1.0
* @version 0.2.0
* </remarks>
*/
public class Photo : Concurrency {
public uint PhotoId { get; set; }

public bool? Cover { get; set; }

[StringLength(100)]
public string? Caption { get; set; }

Expand Down
17 changes: 8 additions & 9 deletions src/Components/DataGrid/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { DataGrid, DataGridBody, DataGridHeader, DataGridRow, SkeletonItem, TableColumnDefinition, TableRowId } from "@fluentui/react-components";

/**
* @author Aloento
* @since 0.1.0
* @version 0.2.1
*/
export interface IDataGrid<T extends { Id: TableRowId; }> {
interface IDataGrid<T> {
Items: T[] | undefined;
Columns: TableColumnDefinition<T>[];
NoHeader?: true;
Expand All @@ -14,14 +9,18 @@ export interface IDataGrid<T extends { Id: TableRowId; }> {
/**
* @author Aloento
* @since 0.1.0
* @version 0.2.1
* @version 0.3.0
*/
export function DelegateDataGrid<T extends { Id: TableRowId; }>({ Items, Columns, NoHeader }: IDataGrid<T>) {
export function DelegateDataGrid<T>({ Items, Columns, NoHeader }: IDataGrid<T> & { getRowId: (item: T) => TableRowId }): JSX.Element;
export function DelegateDataGrid<T extends { Id: TableRowId; }>({ Items, Columns, NoHeader }: IDataGrid<T>): JSX.Element;
export function DelegateDataGrid<T>({ Items, Columns, NoHeader, getRowId }: IDataGrid<T> & { getRowId?: (item: T) => TableRowId }) {
const id = getRowId || ((item: T & { Id: TableRowId; }) => item.Id);

return (
<DataGrid
items={Items || []}
columns={Columns}
getRowId={(item: T) => item.Id}
getRowId={id}
>
{
!NoHeader &&
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Order/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function OrderDetailDrawer({ OrderId, Admin, ParentLog }: IOrderComp) {
:
<DelegateDataGrid
Items={cart}
Columns={[MakeCoverCol(44, ParentLog), ...columns]}
Columns={[MakeCoverCol(44, ParentLog, (x: ICartItem) => x.Cover), ...columns]}
/>
}

Expand Down
2 changes: 1 addition & 1 deletion src/Components/ShopCart/Columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const columns: TableColumnDefinition<ICartItem>[] = [
*/
export function CartColumns(log: Logger): TableColumnDefinition<ICartItem>[] {
return [
MakeCoverCol(44, log),
MakeCoverCol(44, log, x => x.Cover),
...columns
];
}
11 changes: 6 additions & 5 deletions src/Helpers/CoverCol.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ const useStyles = makeStyles({
/**
* @author Aloento
* @since 0.5.0
* @version 0.2.0
* @version 1.0.0
*/
export function MakeCoverCol(size: number, log: Logger) {
export function MakeCoverCol<T>(size: number, log: Logger, fac: (item: T) => string) {
const w = { width: `${size}px` };

return createTableColumn<{ Cover: string; }>({
return createTableColumn<T>({
columnId: "Cover",
renderHeaderCell: () => {
const style = useStyles();
Expand All @@ -42,14 +42,15 @@ export function MakeCoverCol(size: number, log: Logger) {
},
renderCell(item) {
const style = useStyles();
const cover = fac(item);

return (
<DataGridCell className={style.unset}>
<GuidImage
className={style.img}
style={w}
Guid={item.Cover}
Log={log}
Guid={cover}
ParentLog={log}
/>
</DataGridCell>
)
Expand Down
26 changes: 10 additions & 16 deletions src/Helpers/GuidImage.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
import { Image } from "@fluentui/react-components";
import { useConst } from "@fluentui/react-hooks";
import { useRequest } from "ahooks";
import { ComponentProps, useEffect } from "react";
import { ComponentProps } from "react";
import { Hub } from "~/ShopNet";
import type { Logger } from "./Logger";
import type { ICompLog } from "./Logger";

const hold = (txt: string) => "https://placehold.co/400?text=" + txt + "...";

/**
* @author Aloento
* @since 1.0.0
* @version 0.2.1
* @version 0.3.0
*/
export function GuidImage({ Guid, Log, ...rest }: { Guid?: string, Log: Logger } & ComponentProps<typeof Image>) {
const log = useConst(() => Log.With("GuidImage"));

const { data, run } = useRequest(Hub.Storage.GetBySlice.bind(Hub.Storage), {
manual: true,
onError: log.error,
});
export function GuidImage({ Guid, ParentLog, ...rest }: { Guid?: string } & ComponentProps<typeof Image> & ICompLog) {
if (!Guid)
return <Image {...rest} src={hold("Pending")} />;

useEffect(() => {
Guid && run(Guid, log);
}, [Guid]);
const { data } = Hub.Storage.useGet(Guid, ParentLog);

return <Image {...rest} src={data ? URL.createObjectURL(new Blob(data)) : "https://placehold.co/400?text=Loading..."} />;
return <Image {...rest} src={data ? URL.createObjectURL(new Blob(data)) : hold("Loading")} />;
}
1 change: 0 additions & 1 deletion src/Pages/Admin/Product/Add.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export function AdminProductAddButton() {
const { dispatch, dispatchToast } = useErrorToast(log);

const { run, loading } = AdminHub.Product.Post.useCreate({
manual: true,
onError(e, params) {
dispatch({
Message: `Failed Create ${name}`,
Expand Down
2 changes: 0 additions & 2 deletions src/Pages/Admin/Product/Category.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export function AdminProductCategory({ ProdId }: { ProdId: number; }) {
const { dispatch, dispatchToast } = useErrorToast(log);

const { run } = AdminHub.Product.Patch.useCategory({
manual: true,
onError(e, params) {
dispatch({
Message: "Failed Update Category",
Expand All @@ -65,7 +64,6 @@ export function AdminProductCategory({ ProdId }: { ProdId: number; }) {
});

const { run: det } = AdminHub.Product.Delete.useCategory({
manual: true,
onError(e, params) {
dispatch({
Message: "Failed Detach Category",
Expand Down
1 change: 0 additions & 1 deletion src/Pages/Admin/Product/Combo/Delete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export function AdminProductComboDelete({ ComboId, Refresh }: { ComboId: number;
const { dispatch, dispatchToast } = useErrorToast(log);

const { run } = AdminHub.Product.Delete.useCombo({
manual: true,
onError(e, req) {
dispatch({
Message: "Failed Delete Combo",
Expand Down
1 change: 0 additions & 1 deletion src/Pages/Admin/Product/Combo/New.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export function AdminProductNewCombo({ ProdId, Refresh }: { ProdId: number; Refr
const { dispatch, dispatchToast } = useErrorToast(log);

const { run } = AdminHub.Product.Post.useCombo({
manual: true,
onError(e, req) {
dispatch({
Message: "Failed Create Combo",
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/Admin/Product/Combo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const columns: TableColumnDefinition<IDetailComboItem>[] = [
* @version 0.2.2
*/
export function AdminProductCombo({ ProdId }: { ProdId: number }) {
const { data, run } = useRequest(() => Hub.Product.Get.ComboItem(ProdId, log), {
const { data, run } = useRequest(() => Hub.Product.Get.ComboList(ProdId, log), {
onError: log.error
});

Expand Down
1 change: 0 additions & 1 deletion src/Pages/Admin/Product/Delete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export function AdminProductDelete({ ProdId }: { ProdId: number }) {
const { dispatch, dispatchToast } = useErrorToast(log);

const { run, loading } = AdminHub.Product.Delete.useProduct({
manual: true,
onError(e, params) {
dispatch({
Message: "Failed Delete Product",
Expand Down
1 change: 0 additions & 1 deletion src/Pages/Admin/Product/Lexical.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export function AdminProductLexical({ ProdId }: { ProdId: number }) {
const { dispatch, dispatchToast } = useErrorToast(log);

const { run } = AdminHub.Product.Post.useLexical({
manual: true,
onError(e, req) {
dispatch({
Message: "Failed Update Description",
Expand Down
1 change: 0 additions & 1 deletion src/Pages/Admin/Product/Name.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export function AdminProductName({ ProdId }: { ProdId: number; }) {
const { dispatch, dispatchToast } = useErrorToast(log);

const { run } = AdminHub.Product.Patch.useName({
manual: true,
onError(e, req) {
dispatch({
Message: "Failed Update Name",
Expand Down
Loading

0 comments on commit 85fb050

Please sign in to comment.