Skip to content

Commit dcf6c2e

Browse files
committed
Add app initializer, cache & option stores
Introduce application initialization and a client-side caching layer for common option data. Adds AppInitializerService, InitialDataLoader, IndexedDbService, AppCacheService and AppChannelService (cross-tab sync), plus SessionStorageService. Implement generic stores (OptionCacheStore, PaginatedCacheStore) and concrete stores for categories, manufacturers, OEM codes, part origins, statuses, unit-sales and warehouses. Add ProductByIdService, query utilities (createDefaultQuery/isSameQuery), many new/updated models (GeneralOption, query pagination fields, cache models) and adjust services/components to use the new stores and types. Remove legacy warehouses service and add paginationInitialData helper. Purpose: consolidate option loading, enable persistent caching and deduplicate initial API calls.
1 parent 756b09f commit dcf6c2e

59 files changed

Lines changed: 1390 additions & 349 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/app/app.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { ChangeDetectionStrategy, Component } from '@angular/core';
1+
import { afterNextRender, ChangeDetectionStrategy, Component, inject } from '@angular/core';
22
import { AppShellComponent } from './components/app-shell/app-shell';
3+
import { AppInitializerService } from './core/initialization/app-initializer.service';
34

45
@Component({
56
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -9,4 +10,12 @@ import { AppShellComponent } from './components/app-shell/app-shell';
910
templateUrl: './app.html',
1011
styleUrl: './app.css',
1112
})
12-
export class App {}
13+
export class App {
14+
private readonly initializer = inject(AppInitializerService);
15+
16+
constructor() {
17+
afterNextRender(() => {
18+
void this.initializer.initialize();
19+
});
20+
}
21+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { inject, Injectable } from '@angular/core';
2+
import { CategoryStore } from '../store/category-store/category-store';
3+
import { ManufacturerStore } from '../store/manufacturer-store/manufacturer-store';
4+
import { OemCodeStore } from '../store/oem-code-store/oem-code-store';
5+
import { StatusStore } from '../store/status-store/status-store';
6+
import { UnitSaleStore } from '../store/unit-sale/unit-sale-store';
7+
import { WarehouseStore } from '../store/warehouse/warehouse-store';
8+
import { PartOriginStore } from '../store/part-origin/part-origin-store';
9+
10+
@Injectable({
11+
providedIn: 'root',
12+
})
13+
export class AppInitializerService {
14+
private readonly statusStore = inject(StatusStore);
15+
private readonly oemCodeStore = inject(OemCodeStore);
16+
private readonly categoryStore = inject(CategoryStore);
17+
private readonly unitSaleStore = inject(UnitSaleStore);
18+
private readonly warehouseStore = inject(WarehouseStore);
19+
private readonly partOriginStore = inject(PartOriginStore);
20+
private readonly manufacturerStore = inject(ManufacturerStore);
21+
22+
async initialize(): Promise<void> {
23+
await Promise.all([
24+
this.oemCodeStore.loadInitial(),
25+
this.statusStore.loadInitialOptions(),
26+
this.unitSaleStore.loadInitialOptions(),
27+
this.categoryStore.loadInitialOptions(),
28+
this.warehouseStore.loadInitialOptions(),
29+
this.partOriginStore.loadInitialOptions(),
30+
this.manufacturerStore.loadInitialOptions(),
31+
]);
32+
}
33+
}
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
// export interface CategoryOptionsResponse {
2-
// success: boolean;
3-
// message: string;
4-
// data: CategoryOption[];
5-
// }
1+
import { GeneralOption } from '../generals/general-options-response.model';
62

7-
export interface CategoryOption {
8-
id: string;
9-
label: string;
10-
description: string;
3+
export interface CategoryOption extends GeneralOption {
114
icon: string;
5+
description: string;
126
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { AutocompleteOption } from '../design-system/auto-complete.model';
2+
import { getAllResponse } from '../generals/general-responses-list.model';
3+
import { GeneralOptionQuery } from '../generals/general-option-query.model';
4+
5+
export interface CategoryQueryCache {
6+
query: GeneralOptionQuery;
7+
response: getAllResponse<AutocompleteOption[]>;
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { GeneralOption } from '../generals/general-options-response.model';
2+
3+
export interface AutocompleteOption extends GeneralOption {
4+
icon: string;
5+
disabled: boolean;
6+
description: string;
7+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export interface DSelectOption {
2-
label: string;
3-
value: string | number;
4-
disabled?: boolean;
1+
import { GeneralOption } from '../generals/general-options-response.model';
2+
3+
export interface SelectOption extends GeneralOption {
4+
disabled: boolean;
55
}

src/app/core/models/generals/general-option-query.model.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
export interface GeneralOptionQuery {
22
search: string | null;
33
active: boolean | null;
4-
limit: number | null;
4+
per_page: number | null;
5+
page: number | null;
6+
manufacturer_id: string | null;
57
}
68

79
// ALTERNATIVA PRA PAGINAÇÃO
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface GeneralOption {
2+
value: string;
3+
label: string;
4+
sublabel: string;
5+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export interface CacheEntry<T> {
2+
data: T;
3+
cachedAt: number;
4+
expiresAt: number;
5+
version: number;
6+
}
7+
8+
export interface CacheChangedEvent {
9+
type: 'updated' | 'removed';
10+
key: string;
11+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { getAllResponse } from '../generals/general-responses-list.model';
2+
import { GeneralOptionQuery } from '../generals/general-option-query.model';
3+
import { AutocompleteOption } from '../design-system/auto-complete.model';
4+
5+
export interface ManufacturerQueryCache {
6+
query: GeneralOptionQuery;
7+
response: getAllResponse<AutocompleteOption[]>;
8+
}

0 commit comments

Comments
 (0)