@fluid-topics/ft-app-context 1.3.23 → 1.3.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
- import { FtBookmark, FtMySearch, FtUserAssetCount, FtUserAssetType } from "@fluid-topics/public-api";
1
+ import { FtBookmark, FtMySearch, FtUserAssetCount, FtUserAssetLabel, FtUserAssetType } from "@fluid-topics/public-api";
2
2
  import { FtReduxStore, Optional } from "@fluid-topics/ft-wc-utils";
3
3
  import { UserAssetsCountService } from "../services/user-assets/UserAssetCountService";
4
+ import { UserAssetLabelsService } from "../services/user-assets/UserAssetLabelsService";
4
5
  export declare const FtUserAssetsStoreName = "ft-user-assets";
5
6
  export interface AssetCounts {
6
7
  allAsset: Record<FtUserAssetType, number | undefined>;
@@ -12,6 +13,7 @@ export interface FtUserAssetsState {
12
13
  savedSearches: Optional<Array<FtMySearch>>;
13
14
  bookmarks: Optional<Array<FtBookmark>>;
14
15
  assetCounts: AssetCounts;
16
+ assetLabels: Array<FtUserAssetLabel>;
15
17
  }
16
18
  declare const reducers: {
17
19
  setAssetCount: (state: FtUserAssetsState, action: {
@@ -34,12 +36,13 @@ export type FtUserAssetsStateReducers = typeof reducers;
34
36
  export type FtUserAssetsStore = FtReduxStore<FtUserAssetsState, FtUserAssetsStateReducers>;
35
37
  export declare const ftUserAssetsStore: FtUserAssetsStore;
36
38
  export declare class UserAssetsActions {
37
- private assetCountsService;
39
+ private readonly assetCountsService;
40
+ private readonly assetLabelsService;
38
41
  private currentSession;
39
42
  private bookmarksAreUsed;
40
- private bookmarksService;
41
- private savedSearchesService;
42
- constructor(assetCountsService?: UserAssetsCountService);
43
+ private readonly bookmarksService;
44
+ private readonly savedSearchesService;
45
+ constructor(assetCountsService?: UserAssetsCountService, assetLabelsService?: UserAssetLabelsService);
43
46
  private reloadWhenUserSessionChanges;
44
47
  clearUserAssetCounts(): void;
45
48
  clear(): void;
@@ -47,6 +50,7 @@ export declare class UserAssetsActions {
47
50
  private clearMyBookmarks;
48
51
  reloadMySearches(): Promise<void>;
49
52
  reloadBookmarks(): Promise<void>;
53
+ reloadAssetLabels(): Promise<void>;
50
54
  loadAssetCount(assetType: FtUserAssetType): Promise<void>;
51
55
  loadBookmarkByMapId(mapId: string): Promise<void>;
52
56
  reloadAssetCount(assetType: FtUserAssetType): Promise<void>;
@@ -4,6 +4,7 @@ import { SavedSearchesService } from "../services/SavedSearchesService";
4
4
  import { BookmarksService } from "../services/BookmarksService";
5
5
  import { ftAppInfoStore } from "./FtAppInfoStore";
6
6
  import { UserAssetsCountService } from "../services/user-assets/UserAssetCountService";
7
+ import { UserAssetLabelsService } from "../services/user-assets/UserAssetLabelsService";
7
8
  export const FtUserAssetsStoreName = "ft-user-assets";
8
9
  const reducers = {
9
10
  setAssetCount: (state, action) => {
@@ -11,7 +12,7 @@ const reducers = {
11
12
  state.assetCounts.allAsset[userAssetType] = count;
12
13
  },
13
14
  clearAssetCount: (state) => {
14
- Object.values(FtUserAssetType).forEach(type => {
15
+ Object.values(FtUserAssetType).forEach((type) => {
15
16
  state.assetCounts.allAsset[type] = undefined;
16
17
  });
17
18
  },
@@ -30,13 +31,15 @@ export const ftUserAssetsStore = FtReduxStore.get({
30
31
  savedSearches: undefined,
31
32
  bookmarks: undefined,
32
33
  assetCounts: {
33
- allAsset: Object.fromEntries(Object.values(FtUserAssetType).map(key => [key, undefined])), bookmarkByMap: {},
34
+ allAsset: Object.fromEntries(Object.values(FtUserAssetType).map((key) => [key, undefined])), bookmarkByMap: {},
34
35
  },
36
+ assetLabels: [],
35
37
  },
36
38
  });
37
39
  export class UserAssetsActions {
38
- constructor(assetCountsService = new UserAssetsCountService()) {
40
+ constructor(assetCountsService = new UserAssetsCountService(), assetLabelsService = new UserAssetLabelsService()) {
39
41
  this.assetCountsService = assetCountsService;
42
+ this.assetLabelsService = assetLabelsService;
40
43
  this.currentSession = ftAppInfoStore.getState().session;
41
44
  this.bookmarksAreUsed = false;
42
45
  this.bookmarksService = new BookmarksService();
@@ -51,9 +54,11 @@ export class UserAssetsActions {
51
54
  this.clearMySearches(); // The search context automatically reload
52
55
  this.reloadBookmarks();
53
56
  this.clearUserAssetCounts();
57
+ this.reloadAssetLabels();
54
58
  }
55
59
  }
56
60
  clearUserAssetCounts() {
61
+ this.assetCountsService.clearCache();
57
62
  ftUserAssetsStore.actions.clearAssetCount();
58
63
  ftUserAssetsStore.actions.clearBookmarkCountByMap();
59
64
  }
@@ -78,6 +83,11 @@ export class UserAssetsActions {
78
83
  this.bookmarksService.clearCache();
79
84
  await this.updateBookmarksIfUsed();
80
85
  }
86
+ async reloadAssetLabels() {
87
+ this.assetLabelsService.clearCache();
88
+ const assetLabels = await this.assetLabelsService.getUserAssetLabels();
89
+ ftUserAssetsStore.actions.assetLabels(assetLabels);
90
+ }
81
91
  async loadAssetCount(assetType) {
82
92
  const assetCount = await this.assetCountsService.getUserAssetCount(assetType);
83
93
  if (assetCount) {
@@ -10,6 +10,6 @@ interface DateServiceFormatOptions {
10
10
  }
11
11
  export declare class DateService {
12
12
  isDate(metadataKey: string): boolean;
13
- format(date: string, options?: DateServiceFormatOptions): string;
13
+ format(date: string | Date, options?: DateServiceFormatOptions): string;
14
14
  }
15
15
  export {};
@@ -0,0 +1,7 @@
1
+ import { FtServiceWithCache } from "../FtServiceWithCache";
2
+ import { FtUserAssetLabel } from "@fluid-topics/public-api";
3
+ export declare class UserAssetLabelsService extends FtServiceWithCache {
4
+ private readonly CACHE_DURATION;
5
+ getUserAssetLabels(): Promise<Array<FtUserAssetLabel>>;
6
+ private isAuthenticated;
7
+ }
@@ -0,0 +1,18 @@
1
+ import { FtServiceWithCache } from "../FtServiceWithCache";
2
+ import { ftAppInfoStore } from "../../redux-stores/FtAppInfoStore";
3
+ export class UserAssetLabelsService extends FtServiceWithCache {
4
+ constructor() {
5
+ super(...arguments);
6
+ this.CACHE_DURATION = 3 * 60 * 1000;
7
+ }
8
+ async getUserAssetLabels() {
9
+ if (!this.isAuthenticated()) {
10
+ return [];
11
+ }
12
+ return this.cache.get(`user-asset-labels`, async () => (await this.awaitApi).get(`/internal/api/webapp/user/assets/labels`), this.CACHE_DURATION);
13
+ }
14
+ isAuthenticated() {
15
+ const session = ftAppInfoStore.getState().session;
16
+ return Boolean(session === null || session === void 0 ? void 0 : session.sessionAuthenticated);
17
+ }
18
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/ft-app-context",
3
- "version": "1.3.23",
3
+ "version": "1.3.25",
4
4
  "description": "Global application context for Fluid Topics integrations",
5
5
  "keywords": [
6
6
  "Lit"
@@ -19,11 +19,11 @@
19
19
  "url": "ssh://git@scm.mrs.antidot.net:2222/fluidtopics/ft-web-components.git"
20
20
  },
21
21
  "dependencies": {
22
- "@fluid-topics/ft-wc-utils": "1.3.23",
22
+ "@fluid-topics/ft-wc-utils": "1.3.25",
23
23
  "lit": "3.1.0"
24
24
  },
25
25
  "devDependencies": {
26
- "@fluid-topics/public-api": "1.0.102"
26
+ "@fluid-topics/public-api": "1.0.105"
27
27
  },
28
- "gitHead": "1449ae5b73dbdbe40583d414fc5d8e5395694146"
28
+ "gitHead": "c1db8e8b54f9c8e258d92f0b175253cd7a136afa"
29
29
  }