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 renaming and updating methods, a…
Browse files Browse the repository at this point in the history
…dding new types and methods, and updating import statements across multiple files. The `ProductDeleteCategory` method in `Delete.cs` has been renamed to `ProductDetachCategory`, and the import statements in `OrderInfo.tsx`, `Delete.ts`, `Get.ts`, and `Post.ts` have been updated. New types have been added to `Entity.ts` and `Data.ts`, and new methods have been added to `Get.ts`, `Data.ts`, and `Get.tsx`. The `Order` and `Comment` methods in `Entity.ts`, the `Product`, `Lexical`, `Photo`, `Type`, and `Variant` methods in `Data.ts`, and the `useMe` method in `Get.tsx` have been updated. The `OrderGet` class in `Get.ts` and the `ProductGet` class in `Get.ts` now extend `OrderEntity` and `ProductData` respectively.

1. The method `ProductDeleteCategory` in `Delete.cs` has been renamed to `ProductDetachCategory`.
2. The import statement in `OrderInfo.tsx` has been updated to include `OrderEntity` from `"~/ShopNet/Order/Entity"`.
3. The `Order` type in `OrderInfo.tsx` has been changed from `Awaited<ReturnType<typeof Hub.Order.Get.Order>>` to `OrderEntity.Order`.
4. The version annotation in `Category.tsx` has been updated from `0.3.2` to `0.3.4`.
5. New code has been added to `Category.tsx` to handle the detaching of a category from a product.
6. The import statement in `Delete.ts` has been updated to remove `dayjs`.
7. The `useProduct` method in `Delete.ts` has been updated to use `AdminProductGet.ListUpdate` instead of `this.UpdateCache`.
8. The `useCategory` method in `Delete.ts` has been updated to use `ProductDetachCategory` instead of `ProductDeleteCategory` and `ProductData.ProductUpdate` instead of `this.UpdateCache`.
9. The import statement in `Get.ts` has been updated to include `dayjs`.
10. The `useList` method in `Get.ts` has been updated to use `this.list` instead of `"ProductGetList"`, and a new method `ListUpdate` has been added.
11. The import statement in `Post.ts` has been updated to remove `dayjs` and include `AdminProductGet`.
12. The `useCreate` method in `Post.ts` has been updated to use `AdminProductGet.ListUpdate` instead of `this.UpdateCache`.
13. New types have been added to `Entity.ts` under the namespace `OrderEntity`.
14. The `Order` and `Comment` methods in `Entity.ts` have been updated to return the new types from `OrderEntity`.
15. The import statement in `Get.ts` has been updated to remove `ShopNet` and include `OrderEntity`.
16. The `OrderGet` class in `Get.ts` now extends `OrderEntity` instead of `ShopNet`.
17. The `PhotoList` method in `Get.ts` has been updated to return `ProductData.Photo[]` instead of `Awaited<ReturnType<typeof this.Photo>>[]`.
18. The `Order` method in `Get.ts` has been removed.
19. New types have been added to `Data.ts` under the namespace `ProductData`.
20. The `Product`, `Lexical`, `Photo`, `Type`, and `Variant` methods in `Data.ts` have been updated to return the new types from `ProductData`.
21. A new method `ProductUpdate` has been added to `Data.ts`.
22. The `ProductGet` class in `Get.ts` now extends `ProductData` instead of `ShopNet`.
23. The `useMe` method in `Get.tsx` has been updated to return `UserGet.Me` instead of `IUserGetMe`.
24. A new method `MeUpdate` has been added to `Get.tsx`.
25. The `useUpdate` method in `Post.ts` has been updated to use `UserGet.MeUpdate` instead of `this.UpdateCache`.
  • Loading branch information
Aloento committed Jan 23, 2024
1 parent 420dcba commit ef453ed
Show file tree
Hide file tree
Showing 15 changed files with 595 additions and 518 deletions.
2 changes: 1 addition & 1 deletion SoarCraft.AwaiShop/AdminHub/Product/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public async Task<bool> ProductDeleteProduct(uint prodId) {
* @version 0.1.0
* </remarks>
*/
public async Task<bool> ProductDeleteCategory(uint prodId) {
public async Task<bool> ProductDetachCategory(uint prodId) {
var prod = await this.Db.Products
.SingleAsync(x => x.ProductId == prodId);

Expand Down
2 changes: 1 addition & 1 deletion SoarCraft.AwaiShop/SoarCraft.AwaiShop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<PackageReference Include="Microsoft.Identity.Web" Version="2.16.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.2" />
<PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="8.101.2" />
<PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="8.101.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"update": "npx npm-check-updates -u"
},
"dependencies": {
"@azure/msal-browser": "^3.7.0",
"@azure/msal-common": "^14.6.0",
"@azure/msal-react": "^2.0.9",
"@fluentui/react-components": "^9.45.0",
"@azure/msal-browser": "^3.7.1",
"@azure/msal-common": "^14.6.1",
"@azure/msal-react": "^2.0.10",
"@fluentui/react-components": "^9.46.0",
"@fluentui/react-hooks": "^8.6.36",
"@fluentui/react-icons": "^2.0.225",
"@griffel/react": "^1.5.20",
Expand Down
879 changes: 440 additions & 439 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/Components/OrderInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Logger } from "~/Helpers/Logger";
import { ColFlex, Flex } from "~/Helpers/Styles";
import { Hub } from "~/ShopNet";
import { AdminHub } from "~/ShopNet/Admin";
import { OrderEntity } from "~/ShopNet/Order/Entity";

/**
* @author Aloento
Expand All @@ -26,7 +27,7 @@ const useStyles = makeStyles({
*/
interface IOrderInfo {
OrderId: number;
Order: Awaited<ReturnType<typeof Hub.Order.Get.Order>>;
Order: OrderEntity.Order;
Admin?: true;
}

Expand Down
55 changes: 46 additions & 9 deletions src/Pages/Admin/Product/Category.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const log = new Logger("Admin", "Product", "Detail", "Category");
/**
* @author Aloento
* @since 0.5.0
* @version 0.3.2
* @version 0.3.4
*/
export function AdminProductCategory({ ProdId }: { ProdId: number; }) {
const [cate, setCate] = useState("");
Expand Down Expand Up @@ -64,6 +64,27 @@ export function AdminProductCategory({ ProdId }: { ProdId: number; }) {
}
});

const { run: det } = AdminHub.Product.Delete.useCategory({
manual: true,
onError(e, params) {
dispatch({
Message: "Failed Detach Category",
Request: params,
Error: e
});
},
onSuccess() {
dispatchToast(
<Toast>
<ToastTitle>Category Detached</ToastTitle>
</Toast>,
{ intent: "success" }
);

setFalse();
}
});

const { data: cates } = useRequest(() => Hub.Gallery.Get.Categories(), {
onSuccess(data) {
setMatchCate(data);
Expand Down Expand Up @@ -116,17 +137,33 @@ export function AdminProductCategory({ ProdId }: { ProdId: number; }) {
}

{matchCate?.map(x => <Option key={x}>{x}</Option>)}

{
matchCate?.length === cates?.length
?
<Option key="" text="">
Pending
</Option>
: null
}
</Combobox>

{edit
? <Button appearance="subtle" icon={<SendRegular />} onClick={() => {
if (cate)
run(ProdId, cate)
else {

}
}} />
: <Button appearance="subtle" icon={<EditRegular />} onClick={setTrue} />}
? <Button
appearance="subtle"
icon={<SendRegular />}
onClick={() => {
if (cate)
run(ProdId, cate);
else
det(ProdId);
}}
/>
: <Button
appearance="subtle"
icon={<EditRegular />}
onClick={setTrue}
/>}
</div>
);
}
11 changes: 4 additions & 7 deletions src/ShopNet/Admin/Product/Delete.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useRequest } from "ahooks";
import { Options } from "ahooks/lib/useRequest/src/types";
import dayjs from "dayjs";
import { ProductData } from "~/ShopNet/Product/Data";
import { AdminNet } from "../AdminNet";
import { AdminProductGet } from "./Get";
Expand Down Expand Up @@ -73,9 +72,7 @@ export abstract class AdminProductDelete extends AdminNet {
const res = await this.Invoke<boolean>("ProductDeleteProduct", prodId);
this.EnsureTrue(res);

this.UpdateCache<Awaited<ReturnType<typeof AdminProductGet.useList>>>(x =>
x!.filter(x => x !== prodId), "", "ProductGetList", dayjs().add(1, "m")
);
AdminProductGet.ListUpdate(x => x!.filter(x => x !== prodId));

return res;
}, options);
Expand All @@ -88,13 +85,13 @@ export abstract class AdminProductDelete extends AdminNet {
*/
public static useCategory(options: Options<true, [number]>) {
return useRequest(async prodId => {
const res = await this.Invoke<boolean>("ProductDeleteCategory", prodId);
const res = await this.Invoke<boolean>("ProductDetachCategory", prodId);
this.EnsureTrue(res);

this.UpdateCache<Awaited<ReturnType<typeof ProductData.Product>>>(x => {
ProductData.ProductUpdate(prodId, x => {
x.Category = undefined;
return x;
}, prodId, "ProductEntity", dayjs().add(1, "m"));
});

return res;
}, options);
Expand Down
8 changes: 7 additions & 1 deletion src/ShopNet/Admin/Product/Get.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useConst } from "@fluentui/react-hooks";
import dayjs from "dayjs";
import { useLiveQuery } from "dexie-react-hooks";
import type { Logger } from "~/Helpers/Logger";
import { IProductCount } from "~/Pages/Admin/Product";
Expand All @@ -15,6 +16,8 @@ export abstract class AdminProductGet extends AdminNet {
/** "Product", "Get" */
protected static override readonly Log = [...super.Log, "Product", "Get"];

public static readonly list = "ProductGetList";

/**
* @author Aloento
* @since 0.5.0
Expand All @@ -24,12 +27,15 @@ export abstract class AdminProductGet extends AdminNet {
const log = useConst(() => pLog.With(...this.Log, "List"));

const res = useLiveQuery(() =>
this.GetTimeCache<number[]>("", "ProductGetList", (x) => x.add(1, "m"))
this.GetTimeCache<number[]>("", this.list, (x) => x.add(1, "m"))
.catch(log.error)
);

return res;
}
public static ListUpdate(action: (raw: number[]) => number[]) {
return this.UpdateCache(action, "", this.list, dayjs().add(1, "m"));
}

/**
* @author Aloento
Expand Down
4 changes: 2 additions & 2 deletions src/ShopNet/Admin/Product/Post.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useConst } from "@fluentui/react-hooks";
import { useRequest } from "ahooks";
import { Options } from "ahooks/lib/useRequest/src/types";
import dayjs from "dayjs";
import { Subject } from "rxjs";
import { Logger } from "~/Helpers/Logger";
import { CurrentEditor } from "~/Lexical/Utils";
import { AdminNet } from "../AdminNet";
import { AdminProductGet } from "./Get";

/**
* @author Aloento
Expand All @@ -24,7 +24,7 @@ export abstract class AdminProductPost extends AdminNet {
public static useCreate(options: Options<number, [string]>) {
return useRequest(async name => {
const res = await this.Invoke<number>("ProductPostCreate", name);
this.UpdateCache<number[]>(x => [res, ...x], "", "ProductGetList", dayjs().add(1, "m"))
AdminProductGet.ListUpdate(x => [res, ...x])
return res;
}, options);
}
Expand Down
26 changes: 16 additions & 10 deletions src/ShopNet/Order/Entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import { IConcurrency } from "../Database";
import { ShopNet } from "../ShopNet";

export namespace OrderEntity {
export type Order = {
Status: string;
CreateAt: Date;
TrackingNumber?: string;
} & IConcurrency;

export type Comment = {
Content: string;
Name?: string;
CreateAt: Date;
} & IConcurrency;
}

/**
* @author Aloento
* @since 1.0.0
Expand All @@ -12,11 +26,7 @@ export abstract class OrderEntity extends ShopNet {
* @since 1.0.0
* @version 0.1.0
*/
public static Order(key: number): Promise<({
Status: string;
CreateAt: Date;
TrackingNumber?: string;
} & IConcurrency) | void> {
public static Order(key: number): Promise<OrderEntity.Order> {
this.EnsureLogin();
return this.GetVersionCache(key, "OrderEntity");
}
Expand All @@ -26,11 +36,7 @@ export abstract class OrderEntity extends ShopNet {
* @since 1.0.0
* @version 0.1.0
*/
public static Comment(key: number): Promise<({
Content: string;
Name?: string;
CreateAt: Date;
} & IConcurrency) | void> {
public static Comment(key: number): Promise<OrderEntity.Comment> {
this.EnsureLogin();
return this.GetVersionCache(key, "CommentEntity");
}
Expand Down
9 changes: 3 additions & 6 deletions src/ShopNet/Order/Get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import { IComment } from "~/Pages/History/Comment";
import { IOrderDetail } from "~/Pages/History/Detail";
import { ProductData } from "../Product/Data";
import { ProductGet } from "../Product/Get";
import { ShopNet } from "../ShopNet";
import { OrderEntity } from "./Entity";

/**
* @author Aloento
* @since 0.5.0
* @version 0.2.0
*/
export abstract class OrderGet extends ShopNet {
export abstract class OrderGet extends OrderEntity {
/** "Order", "Get" */
protected static override readonly Log = [...super.Log, "Order", "Get"];

Expand All @@ -37,7 +36,7 @@ export abstract class OrderGet extends ShopNet {
const items: IOrderItem[] = [];

for (const meta of list) {
const order = await OrderEntity.Order(meta.OrderId);
const order = await this.Order(meta.OrderId);

if (!order) {
log.warn(`[Mismatch] Order ${meta.OrderId} not found`);
Expand Down Expand Up @@ -140,7 +139,7 @@ export abstract class OrderGet extends ShopNet {
const comments: IComment[] = [];

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

if (!cmt) {
log.warn(`[Mismatch] Comment ${cmtId} not found. Order : ${orderId}`);
Expand All @@ -159,6 +158,4 @@ export abstract class OrderGet extends ShopNet {
Comments: comments.sort((a, b) => a.Time.getTime() - b.Time.getTime())
};
}

public static Order = OrderEntity.Order;
}
Loading

0 comments on commit ef453ed

Please sign in to comment.