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

Commit

Permalink
The most significant changes involve the restructuring of methods in …
Browse files Browse the repository at this point in the history
…the `AdminHub` and `ShopHub` classes, and the modification of components and functions in `Drawer.tsx`, `index.tsx`, `Detail.tsx`, and `List.tsx`. The `OrderGetDetail` method in `AdminHub` class has been divided into two separate methods, `OrderGetItems` and `OrderGetCmts`, to retrieve order items and comments respectively. The `OrderGetItems` and `OrderGetCmts` methods in `ShopHub` class have been updated to change the order of the `Where` clauses.

In `Drawer.tsx`, the `AdminOrderList` component has been imported and used conditionally based on the `Admin` prop in `OrderDetailDrawer` function. The `OrderDetail` function in `index.tsx` has been updated to change the index used to set the `curr` variable based on the `Admin` prop.

The `AdminOrderDetail` function in `Detail.tsx` has been updated to remove the `Field` component wrapping the `AdminOrderList` component. The `AdminOrderList` function in `List.tsx` has been updated to wrap the `DelegateDataGrid` component with a `Field` component.

The `AdminOrderGet` class in `Get.ts` has been updated to remove the `Detail` method. The `OrderGet` class in `Get.ts` has been updated to add an optional `admin` parameter to the `useItems` and `useCmts` methods. This parameter is used to determine whether to use `AdminNet` or `this` for the `useTimeCache` method.

Lastly, the `SignalR` class in `SignalR.ts` has been updated to change the `INet` type to be a member of the `SignalR` namespace. All methods in the `SignalR` class that used `INet` have been updated to use `SignalR.INet` instead. The `GetVersionCache`, `GetTimeCache`, `useTimeCache`, `UpdateCache` methods in `SignalR` class have been updated to use `SignalR.INet` instead of `INet`.
  • Loading branch information
Aloento committed Feb 15, 2024
1 parent aa830a3 commit d4eea88
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 165 deletions.
22 changes: 12 additions & 10 deletions SoarCraft.AwaiShop/AdminHub/Order/Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,28 @@ await this.Db.Orders
* <remarks>
* @author Aloento
* @since 1.0.0
* @version 1.0.0
* @version 1.1.0
* </remarks>
*/
public async Task<dynamic> OrderGetDetail(uint orderId) {
var items = await this.Db.OrderCombos
public async Task<dynamic> OrderGetItems(uint orderId) =>
await this.Db.OrderCombos
.Where(x => x.OrderId == orderId)
.Select(x => new {
x.Quantity,
Types = x.Combo.Types.Select(t => t.TypeId).ToArray()
})
.ToArrayAsync();

var cmts = await this.Db.Comments
/**
* <remarks>
* @author Aloento
* @since 1.0.0
* @version 1.1.0
* </remarks>
*/
public Task<uint[]> OrderGetCmts(uint orderId) =>
this.Db.Comments
.Where(x => x.OrderId == orderId)
.Select(x => x.CommentId)
.ToArrayAsync();

return new {
Items = items,
Comments = cmts
};
}
}
6 changes: 4 additions & 2 deletions SoarCraft.AwaiShop/Hub/Order/Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ await this.Db.Orders
[Authorize]
public async Task<dynamic> OrderGetItems(uint orderId) =>
await this.Db.OrderCombos
.Where(x => x.OrderId == orderId && x.Order.UserId == this.UserId)
.Where(x => x.Order.UserId == this.UserId)
.Where(x => x.OrderId == orderId)
.Select(x => new {
x.Quantity,
Types = x.Combo.Types.Select(t => t.TypeId).ToArray()
Expand All @@ -49,7 +50,8 @@ await this.Db.OrderCombos
[Authorize]
public Task<uint[]> OrderGetCmts(uint orderId) =>
this.Db.Comments
.Where(x => x.OrderId == orderId && x.Order.UserId == this.UserId)
.Where(x => x.Order.UserId == this.UserId)
.Where(x => x.OrderId == orderId)
.Select(x => x.CommentId)
.ToArrayAsync();
}
19 changes: 13 additions & 6 deletions src/Components/Order/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ICartItem } from "~/Components/ShopCart";
import { MakeCoverCol } from "~/Helpers/CoverCol";
import { ColFlex } from "~/Helpers/Styles";
import { useSWR } from "~/Helpers/useSWR";
import { AdminOrderList } from "~/Pages/Admin/Order/List";
import { Hub } from "~/ShopNet";
import { AdminHub } from "~/ShopNet/Admin";
import { SignalR } from "~/ShopNet/SignalR";
Expand Down Expand Up @@ -100,16 +101,22 @@ export function OrderDetailDrawer({ OrderId, Admin, ParentLog }: IOrderComp) {
useMemory: true
});

const { data: cart } = Hub.Order.Get.useItems(OrderId, ParentLog);
const { data: cart } = Hub.Order.Get.useItems(OrderId, ParentLog, Admin);

return (
<div className={style.body}>
<OrderInfo OrderId={OrderId} Order={order} ParentLog={ParentLog} />
<OrderInfo OrderId={OrderId} Order={order} Admin={Admin} ParentLog={ParentLog} />

<DelegateDataGrid
Items={cart}
Columns={[MakeCoverCol(44, ParentLog), ...columns]}
/>
{
Admin
?
<AdminOrderList Items={cart} />
:
<DelegateDataGrid
Items={cart}
Columns={[MakeCoverCol(44, ParentLog), ...columns]}
/>
}

<OrderComment OrderId={OrderId} ParentLog={ParentLog} />

Expand Down
2 changes: 1 addition & 1 deletion src/Components/Order/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function OrderDetail({ OrderId, Admin, ParentLog }: IOrderComp) {

const [open, { set }] = useBoolean();
const { Nav, Paths } = useRouter();
const curr = parseInt(Paths.at(1)!);
const curr = parseInt(Paths.at(Admin ? 2 : 1)!);

useEffect(() => set(curr === OrderId), [curr]);
const ref = useRef(null);
Expand Down
6 changes: 2 additions & 4 deletions src/Pages/Admin/Order/Detail.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Field, makeStyles, tokens } from "@fluentui/react-components";
import { Button, makeStyles, tokens } from "@fluentui/react-components";
import { Drawer, DrawerBody, DrawerHeader, DrawerHeaderTitle } from "@fluentui/react-components/unstable";
import { DismissRegular, OpenRegular } from "@fluentui/react-icons";
import { useBoolean, useRequest } from "ahooks";
Expand Down Expand Up @@ -96,9 +96,7 @@ export function AdminOrderDetail({ OrderId }: { OrderId: number; }) {
<DrawerBody className={style.body}>
<OrderInfo OrderId={OrderId} Order={order} Admin />

<Field label="Required Products" size="large">
<AdminOrderList Items={data?.ShopCart} />
</Field>
<AdminOrderList Items={data?.ShopCart} />

<Shipment OrderId={OrderId} TrackingNumber={order?.TrackingNumber} Refresh={run} />

Expand Down
6 changes: 4 additions & 2 deletions src/Pages/Admin/Order/List.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DataGridCell, DataGridHeaderCell, TableColumnDefinition, createTableColumn, makeStyles } from "@fluentui/react-components";
import { DataGridCell, DataGridHeaderCell, Field, TableColumnDefinition, createTableColumn, makeStyles } from "@fluentui/react-components";
import { DelegateDataGrid } from "~/Components/DataGrid";
import { ICartItem } from "~/Components/ShopCart";

Expand Down Expand Up @@ -64,6 +64,8 @@ const columns: TableColumnDefinition<ICartItem>[] = [
*/
export function AdminOrderList({ Items }: { Items?: ICartItem[] }) {
return (
<DelegateDataGrid Items={Items} Columns={columns} />
<Field label="Required Products" size="large">
<DelegateDataGrid Items={Items} Columns={columns} />
</Field>
)
}
105 changes: 0 additions & 105 deletions src/ShopNet/Admin/Order/Get.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { IOrderComp } from "~/Components/Order";
import { ICartItem } from "~/Components/ShopCart";
import { Logger } from "~/Helpers/Logger";
import { IAdminOrderItem } from "~/Pages/Admin/Order";
import { IComment } from "~/Pages/History/Comment";
import { ProductData } from "~/ShopNet/Product/Data";
import { ProductGet } from "~/ShopNet/Product/Get";
import { AdminNet } from "../AdminNet";
import { AdminUserEntity } from "../User/Entity";
import { AdminOrderEntity } from "./Entity";
Expand Down Expand Up @@ -90,107 +86,6 @@ export abstract class AdminOrderGet extends AdminNet {
return items;
}

/**
* @author Aloento
* @since 1.0.0
* @version 0.1.1
*/
public static async Detail(orderId: number, pLog: Logger): Promise<IOrderComp> {
this.EnsureLogin();
const log = pLog.With(...this.Log, "Detail");

const meta = await this.GetTimeCache<
{
Items: {
Types: number[];
Quantity: number;
}[],
Comments: number[];
}
>(orderId, "OrderGetDetail", (x) => x.add(1, "m"), orderId);

const items: ICartItem[] = [];
let index = 0;

for (const combo of meta.Items) {
const variType: Record<string, string> = {};
let prodId = 0;

for (const typeId of combo.Types) {
const type = await ProductData.Type(typeId);

if (!type) {
log.warn(`[Mismatch] Type ${typeId} not found. Order : ${orderId}`);
continue;
}

const vari = await ProductData.Variant(type.VariantId);

if (!vari) {
log.warn(`[Mismatch] Variant ${type.VariantId} not found. Type : ${typeId}, Order : ${orderId}`);
continue;
}

variType[vari.Name] = type.Name;
prodId = vari.ProductId;
}

const prod = await ProductData.Product(prodId);

if (!prod) {
log.warn(`[Mismatch] Product ${prodId} not found. Order : ${orderId}`);
continue;
}

const [_, cover] = await ProductGet.PhotoList(prodId, log);

if (!cover)
log.warn(`Product ${prodId} has no photo`);

items.push({
Id: index++,
ProdId: prodId,
Cover: cover || "",
Name: prod.Name,
Type: variType,
Quantity: combo.Quantity,
});
}

const comments: IComment[] = [];

for (const cmtId of meta.Comments) {
const cmt = await AdminOrderEntity.Comment(cmtId);

if (!cmt) {
log.warn(`[Mismatch] Comment ${cmtId} not found. Order : ${orderId}`);
continue;
}

let name = "Client";

if (cmt.UserId) {
const user = await AdminUserEntity.User(cmt.UserId);

if (user)
name = user.Name;
else
log.warn(`[Mismatch] User ${cmt.UserId} not found. Order : ${orderId}`);
}

comments.push({
Content: cmt.Content,
Time: cmt.CreateAt,
User: name
});
}

return {
ShopCart: items,
Comments: comments.sort((a, b) => a.Time.getTime() - b.Time.getTime())
};
}

public static Order = AdminOrderEntity.Order;
public static Export = AdminOrderExport.Export;
}
70 changes: 50 additions & 20 deletions src/ShopNet/Order/Get.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { useConst } from "@fluentui/react-hooks";
import { useAsyncEffect } from "ahooks";
import { useState } from "react";
import { IComment } from "~/Components/Order/Comment";
import { ICartItem } from "~/Components/ShopCart";
import type { IComment } from "~/Components/Order/Comment";
import type { ICartItem } from "~/Components/ShopCart";
import { Logger } from "~/Helpers/Logger";
import { IOrderItem } from "~/Pages/History";
import type { IOrderItem } from "~/Pages/History";
import { AdminNet } from "../Admin/AdminNet";
import { AdminOrderEntity } from "../Admin/Order/Entity";
import { AdminUserEntity } from "../Admin/User/Entity";
import { ProductData } from "../Product/Data";
import { ProductGet } from "../Product/Get";
import { OrderEntity } from "./Entity";
Expand Down Expand Up @@ -75,13 +78,13 @@ export abstract class OrderGet extends OrderEntity {
/**
* @author Aloento
* @since 0.5.0
* @version 2.0.0
* @version 2.1.0
*/
public static useItems(orderId: number, pLog: Logger) {
public static useItems(orderId: number, pLog: Logger, admin?: true) {
const log = useConst(() => pLog.With(...this.Log, "Items"));
const [res, setRes] = useState<ICartItem[]>();

const req = this.useTimeCache<
const req = (admin ? AdminNet : this).useTimeCache<
{
Types: number[];
Quantity: number;
Expand Down Expand Up @@ -160,13 +163,13 @@ export abstract class OrderGet extends OrderEntity {
/**
* @author Aloento
* @since 1.3.5
* @version 0.1.0
* @version 1.0.0
*/
public static useCmts(orderId: number, pLog: Logger) {
public static useCmts(orderId: number, pLog: Logger, admin?: true) {
const log = useConst(() => pLog.With(...this.Log, "Cmts"));
const [res, setRes] = useState<IComment[]>();

const req = this.useTimeCache<number[]>(
const req = (admin ? AdminNet : this).useTimeCache<number[]>(
orderId,
"OrderGetCmts",
{
Expand All @@ -182,20 +185,47 @@ export abstract class OrderGet extends OrderEntity {

const comments: IComment[] = [];

for (const cmtId of cmts) {
const cmt = await this.Comment(cmtId);
if (admin)
for (const cmtId of cmts) {
const cmt = await AdminOrderEntity.Comment(cmtId);

if (!cmt) {
log.warn(`[Mismatch] Comment ${cmtId} not found. Order : ${orderId}`);
continue;
if (!cmt) {
log.warn(`[Mismatch] Comment ${cmtId} not found. Order : ${orderId}`);
continue;
}

let name = "Client";

if (cmt.UserId) {
const user = await AdminUserEntity.User(cmt.UserId);

if (user)
name = user.Name;
else
log.warn(`[Mismatch] User ${cmt.UserId} not found. Order : ${orderId}`);
}

comments.push({
Content: cmt.Content,
Time: cmt.CreateAt,
User: name
});
}
else
for (const cmtId of cmts) {
const cmt = await this.Comment(cmtId);

comments.push({
Content: cmt.Content,
Time: cmt.CreateAt,
User: cmt.Name || "You"
});
}
if (!cmt) {
log.warn(`[Mismatch] Comment ${cmtId} not found. Order : ${orderId}`);
continue;
}

comments.push({
Content: cmt.Content,
Time: cmt.CreateAt,
User: cmt.Name || "You"
});
}

setRes(comments.sort((a, b) => a.Time.getTime() - b.Time.getTime()));
}, [req.data]);
Expand Down
Loading

0 comments on commit d4eea88

Please sign in to comment.