Skip to content

Commit

Permalink
feat(inventory): add loading spinner when loading inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Aug 30, 2023
1 parent 1e0d29e commit a7ffb2d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions client/src/app/pages/inventory/inventory.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<ion-card-header>
<ion-card-title>
Inventory ({{ items.length }} / 100)
<ion-spinner *ngIf="isLoadingItems$ | async"></ion-spinner>
</ion-card-title>
</ion-card-header>

Expand Down
1 change: 1 addition & 0 deletions client/src/app/pages/inventory/inventory.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class InventoryPage implements OnInit {
Record<ItemSlot, IEquipment>
>;
@Select(InventoryStore.items) items$!: Observable<IItem[]>;
@Select(InventoryStore.isLoadingItems) isLoadingItems$!: Observable<boolean>;

public readonly basicEquipTypes = AllArmor;

Expand Down
1 change: 1 addition & 0 deletions client/src/interfaces/inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface IInventoryStore {
version: number;
inventory: IInventory;
items: IItem[];
isLoadingItems: boolean;
}
4 changes: 3 additions & 1 deletion client/src/stores/inventory/inventory.functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const defaultStore: () => IInventoryStore = () => ({
resources: {},
},
items: [],
isLoadingItems: false,
});

export function setInventory(
Expand Down Expand Up @@ -56,6 +57,7 @@ export function updateInventoryItems(
if (!helpers) return;
const { player, content } = helpers;

ctx.patchState({ isLoadingItems: true });
player.getInventoryItems().subscribe((res: any) => {
const items = res.items
.filter((i: any) => !i.isInUse)
Expand All @@ -64,7 +66,7 @@ export function updateInventoryItems(
instanceId: i.instanceId,
})) as IItem[];

ctx.patchState({ items });
ctx.patchState({ items, isLoadingItems: false });
});
}

Expand Down
5 changes: 5 additions & 0 deletions client/src/stores/inventory/inventory.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ export class InventoryStore {
static items(state: IInventoryStore) {
return state.items ?? [];
}

@Selector()
static isLoadingItems(state: IInventoryStore) {
return state.isLoadingItems;
}
}
4 changes: 4 additions & 0 deletions client/src/styles/ionic-overrides.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ ion-button.icon-only {
--padding-start: 4px;
--padding-end: 4px;
}

ion-spinner {
height: 20px;
}

0 comments on commit a7ffb2d

Please sign in to comment.