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

Commit

Permalink
[Back] Split ProductGetList -> ProductGetCount & LexicalEntity - [Fro…
Browse files Browse the repository at this point in the history
…nt] Carousel -> PhotoList & AdminProduct | AdminProductGet.List -> useList | Export ProductEntity to Get - [Front | SignalR] UpdateCache | GetVersionCache | WithTimeCache -> GetTimeCache | liveSafe | Remove FindCover | PhotoList | LiveState (#92)

* Update package version and fix cache method calls

* Update SignalR UpdateCache method to handle query expiration

* Update version and add new method in AdminNet and SignalR

* Update code with new methods and versions

* Update version numbers and import statements

* Update product data and lexical entity

* Update AdminProduct component and AdminNet

* Refactor photo list retrieval and cover selection

* Refactor gallery and product get methods

* Add useState hook and update AdminProductPhoto component

* Update data grid components

* Update version numbers and function names

* Refactor AdminProduct component and add API call for counting product variants, combos, and stock

* Fix photo caption fallback and handle error in product retrieval

* Update dependencies and fix navigation bug

* Update version and refactor code

* The most significant changes include the update of the `AdminHub` class in `Post.cs` to use a case-insensitive comparison when checking if a product already exists in the database. This change enhances the product search functionality. The `Add.tsx` file has also been updated to improve the user experience during product creation. The `Create` button is now disabled while loading, and the `setName` function is called after a new product is created. The `AdminNet.ts` and `SignalR.ts` files have been updated to remove several functions related to caching and versioning, and a new function `Index` has been added. This change simplifies the code and improves performance.

The `package.json` and `pnpm-lock.yaml` files have been updated to include a new dependency, `dexie-react-hooks` version `1.1.7`. This new dependency provides additional React hooks for the Dexie.js library, which is a minimalistic wrapper for IndexedDB.

The `index.tsx` and `Get.ts` files have been updated to use the `useList` function instead of the `List` function. This change makes the code more concise and easier to read.

In the `SignalR.ts` file, the `UpdateCache`, `GetVersionCache`, and `GetTimeCache` functions have been updated to use the new `Index` function. This change improves the efficiency of these functions.

Changes:

1. `AdminHub` class in `Post.cs` updated for case-insensitive product comparison.
2. `package.json` and `pnpm-lock.yaml` updated to include `dexie-react-hooks` version `1.1.7`.
3. `Add.tsx` updated to improve product creation process.
4. `index.tsx` and `Get.ts` updated to use `useList` function.
5. `AdminNet.ts` and `SignalR.ts` updated to remove caching and versioning functions and add `Index` function.
6. `SignalR.ts` updated to use `Index` function in `UpdateCache`, `GetVersionCache`, and `GetTimeCache` functions.

* The most significant changes in the codebase revolve around the refactoring of the `AdminProductData` class to the `AdminNet` class, the replacement of the `useEffect` hook with the `useAsyncEffect` hook, and the addition of new methods to the `Table` class.

1. The `AdminProductData` class was replaced with the `AdminNet` class in several files (`Data.ts`, `Delete.ts`, `Get.ts`, `Post.ts`). This change indicates a shift towards a more generic network handling class. The `AdminProductDelete`, `AdminProductGet`, and `AdminProductPost` classes were also updated to use the `AdminNet` class.

2. The `useEffect` hook from React was replaced with `useAsyncEffect` from `ahooks` in `index.tsx` to better handle asynchronous operations within the effect hook. The `AdminProduct` function was updated to use this new hook, and the logic within the hook was improved for efficiency and clarity.

3. The `Table` class in `Table.ts` saw several updates. The generic `TPre` was replaced with `unknown` to increase flexibility. New methods `useGet` and `useGetOrSet` were added, which use the `useLiveQuery` hook from `dexie-react-hooks` to fetch and update data. The `Set` method was also updated to throw an error if the expiration time is less than the current time to prevent setting data with an expired time.

4. A new method, `useTimeCache`, was added to the `SignalR` class in `SignalR.ts`. This method is used to cache data for a specified amount of time.

* The most significant changes include the removal of the `dayjs` library and its replacement with a custom function for time manipulation, the removal of `useTimeCache` method from the `SignalR` class, and the replacement of `useGet` and `useGetOrSet` methods in the `Table` class with `Get` and `GetOrSet` methods. Additionally, the `dexie-react-hooks` library was removed from the `Table.ts` file, and the `await` keyword was replaced with `Promise.resolve` in several places to ensure the code always returns a promise.

1. The `dayjs` library was removed and replaced with a custom function that adds 1 minute to a `dayjs` object, improving the flexibility of time manipulation in the code.
2. The `useTimeCache` method was removed from the `SignalR` class as it was no longer needed for caching data.
3. The `useGet` and `useGetOrSet` methods in the `Table` class were replaced with `Get` and `GetOrSet` methods, eliminating the use of the `useLiveQuery` hook from the `dexie-react-hooks` library.
4. The `dexie-react-hooks` library was removed from the `Table.ts` file as it was no longer needed.
5. The `await` keyword was replaced with `Promise.resolve` in several places to ensure the code always returns a promise.
6. The `FindCover` method in the `AdminOrderGet` and `OrderGet` classes was replaced with destructuring assignment to get the `cover` variable, simplifying the code and improving readability.
7. The `debugger;` statement was removed from the `UpdateCache` method in the `SignalR` class as it's not recommended for production code.
8. The `ProductGet.PhotoList` method was modified to take an additional `log` parameter, improving the method's logging capabilities.

* Update AdminProductDelete component version to 0.2.1 and add loading state to delete button
  • Loading branch information
Aloento authored Jan 14, 2024
1 parent d2927b6 commit e9a42d8
Show file tree
Hide file tree
Showing 33 changed files with 1,014 additions and 876 deletions.
18 changes: 15 additions & 3 deletions SoarCraft.AwaiShop/AdminHub/Product/Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,30 @@ internal partial class AdminHub {
* <remarks>
* @author Aloento
* @since 0.1.0
* @version 2.0.0
* </remarks>
*/
public Task<uint[]> ProductGetList() =>
this.Db.Products
.Select(x => x.ProductId)
.ToArrayAsync();

/**
* <remarks>
* @author Aloento
* @since 1.2.0
* @version 1.0.0
* </remarks>
*/
public async Task<dynamic[]> ProductGetList() =>
public async Task<dynamic?> ProductGetCount(uint prodId) =>
await this.Db.Products
.Where(x => x.ProductId == prodId)
.Select(x => new {
x.ProductId,
Variant = x.Variants.Count,
Combo = x.Combos.Count,
Stock = x.Combos.Sum(s => s.Stock)
})
.ToArrayAsync();
.SingleOrDefaultAsync();

/**
* <remarks>
Expand Down
2 changes: 1 addition & 1 deletion SoarCraft.AwaiShop/AdminHub/Product/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task<uint> ProductPostCreate(string name) {
if (!valid.IsValid(name))
throw new HubException(valid.FormatErrorMessage("Name"));

if (await this.Db.Products.AnyAsync(x => EF.Functions.Like(x.Name, name)))
if (await this.Db.Products.AnyAsync(x => EF.Functions.ILike(x.Name, name)))
throw new HubException($"Product {name} already exist");

var temp = await this.Db.Products.AddAsync(new() {
Expand Down
25 changes: 24 additions & 1 deletion SoarCraft.AwaiShop/Hub/Product/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal partial class ShopHub {
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 0.1.0
* @version 0.2.0
* </remarks>
*/
public async Task<dynamic?> ProductEntity(uint key, uint? version) {
Expand All @@ -23,6 +23,29 @@ internal partial class ShopHub {
.Select(x => new {
x.Name,
Category = x.Category!.Name,
x.Version
})
.SingleOrDefaultAsync();
}

/**
* <remarks>
* @author Aloento
* @since 1.2.0
* @version 1.0.0
* </remarks>
*/
public async Task<dynamic?> LexicalEntity(uint key, uint? version) {
if (version is not null) {
var noChange = await this.Db.Products
.AnyAsync(x => x.ProductId == key && x.Version == version);

if (noChange) return true;
}

return await this.Db.Products
.Where(x => x.ProductId == key)
.Select(x => new {
x.Description,
x.Version
})
Expand Down
1 change: 1 addition & 0 deletions SoarCraft.AwaiShop/Hub/Product/Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ public Task<uint[]> ProductGetPhotoList(uint prodId) =>
.Where(x => x.ProductId == prodId)
.Select(x => x.PhotoId)
.ToArrayAsync();

}
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "awaishop",
"private": true,
"version": "1.2.0",
"version": "1.3.0",
"type": "module",
"author": {
"name": "Aloento",
Expand All @@ -15,13 +15,13 @@
"update": "npx npm-check-updates -u"
},
"dependencies": {
"@azure/msal-browser": "^3.6.0",
"@azure/msal-common": "^14.5.0",
"@azure/msal-react": "^2.0.8",
"@fluentui/react-components": "^9.44.0",
"@fluentui/react-hooks": "^8.6.34",
"@fluentui/react-icons": "^2.0.224",
"@griffel/react": "^1.5.19",
"@azure/msal-browser": "^3.7.0",
"@azure/msal-common": "^14.6.0",
"@azure/msal-react": "^2.0.9",
"@fluentui/react-components": "^9.44.3",
"@fluentui/react-hooks": "^8.6.35",
"@fluentui/react-icons": "^2.0.225",
"@griffel/react": "^1.5.20",
"@lexical/clipboard": "0.10.0",
"@lexical/code": "0.10.0",
"@lexical/file": "0.10.0",
Expand All @@ -41,6 +41,7 @@
"ahooks": "^3.7.8",
"dayjs": "^1.11.10",
"dexie": "^3.2.4",
"dexie-react-hooks": "^1.1.7",
"lexical": "0.10.0",
"lodash-es": "^4.17.21",
"react": "^18.2.0",
Expand Down
Loading

0 comments on commit e9a42d8

Please sign in to comment.