@fluid-topics/ft-app-context 1.3.6 → 1.3.8
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.
- package/build/ft-app-context.light.js +4 -4
- package/build/ft-app-context.min.js +14 -14
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/redux-stores/FtUserAssetsStore.d.ts +41 -5
- package/build/redux-stores/FtUserAssetsStore.js +59 -2
- package/build/redux-stores/selectors/UserAssetSelectors.d.ts +2 -0
- package/build/redux-stores/selectors/UserAssetSelectors.js +23 -0
- package/build/services/user-assets/UserAssetCountService.d.ts +8 -0
- package/build/services/user-assets/UserAssetCountService.js +24 -0
- package/package.json +3 -3
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./mixins/withDateFormat";
|
|
2
2
|
export * from "./redux-stores/FtAppInfoStore";
|
|
3
3
|
export * from "./redux-stores/FtUserAssetsStore";
|
|
4
|
+
export * from "./redux-stores/selectors/UserAssetSelectors";
|
|
4
5
|
export * from "./services";
|
|
5
6
|
export * from "./ft-app-context.styles";
|
|
6
7
|
export * from "./ft-app-context.properties";
|
package/build/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { FtAppContext } from "./ft-app-context";
|
|
|
3
3
|
export * from "./mixins/withDateFormat";
|
|
4
4
|
export * from "./redux-stores/FtAppInfoStore";
|
|
5
5
|
export * from "./redux-stores/FtUserAssetsStore";
|
|
6
|
+
export * from "./redux-stores/selectors/UserAssetSelectors";
|
|
6
7
|
export * from "./services";
|
|
7
8
|
export * from "./ft-app-context.styles";
|
|
8
9
|
export * from "./ft-app-context.properties";
|
|
@@ -1,26 +1,62 @@
|
|
|
1
|
-
import { FtBookmark, FtMySearch } from "@fluid-topics/public-api";
|
|
2
|
-
import {
|
|
1
|
+
import { FtBookmark, FtMySearch, FtUserAssetCount, FtUserAssetType } from "@fluid-topics/public-api";
|
|
2
|
+
import { FtReduxStore, Optional } from "@fluid-topics/ft-wc-utils";
|
|
3
|
+
import { UserAssetsCountService } from "../services/user-assets/UserAssetCountService";
|
|
3
4
|
export declare const FtUserAssetsStoreName = "ft-user-assets";
|
|
5
|
+
export interface AssetCounts {
|
|
6
|
+
allAsset: Record<FtUserAssetType, number | undefined>;
|
|
7
|
+
bookmarkByMap: {
|
|
8
|
+
[mapId: string]: number;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
4
11
|
export interface FtUserAssetsState {
|
|
5
12
|
savedSearches: Optional<Array<FtMySearch>>;
|
|
6
13
|
bookmarks: Optional<Array<FtBookmark>>;
|
|
14
|
+
assetCounts: AssetCounts;
|
|
7
15
|
}
|
|
8
|
-
|
|
16
|
+
declare const reducers: {
|
|
17
|
+
setAssetCount: (state: FtUserAssetsState, action: {
|
|
18
|
+
payload: {
|
|
19
|
+
assetCount: FtUserAssetCount;
|
|
20
|
+
};
|
|
21
|
+
type: string;
|
|
22
|
+
}) => void;
|
|
23
|
+
clearAssetCount: (state: FtUserAssetsState) => void;
|
|
24
|
+
setBookmarkCountByMap: (state: FtUserAssetsState, action: {
|
|
25
|
+
payload: {
|
|
26
|
+
count: number;
|
|
27
|
+
mapId: string;
|
|
28
|
+
};
|
|
29
|
+
type: string;
|
|
30
|
+
}) => void;
|
|
31
|
+
clearBookmarkCountByMap: (state: FtUserAssetsState) => void;
|
|
32
|
+
};
|
|
33
|
+
export type FtUserAssetsStateReducers = typeof reducers;
|
|
34
|
+
export type FtUserAssetsStore = FtReduxStore<FtUserAssetsState, FtUserAssetsStateReducers>;
|
|
9
35
|
export declare const ftUserAssetsStore: FtUserAssetsStore;
|
|
10
|
-
declare class UserAssetsActions {
|
|
36
|
+
export declare class UserAssetsActions {
|
|
37
|
+
private assetCountsService;
|
|
11
38
|
private currentSession;
|
|
12
39
|
private bookmarksAreUsed;
|
|
13
40
|
private bookmarksService;
|
|
14
41
|
private savedSearchesService;
|
|
15
|
-
constructor();
|
|
42
|
+
constructor(assetCountsService?: UserAssetsCountService);
|
|
16
43
|
private reloadWhenUserSessionChanges;
|
|
44
|
+
clearUserAssetCounts(): void;
|
|
17
45
|
clear(): void;
|
|
18
46
|
clearMySearches(): void;
|
|
19
47
|
private clearMyBookmarks;
|
|
20
48
|
reloadMySearches(): Promise<void>;
|
|
21
49
|
reloadBookmarks(): Promise<void>;
|
|
50
|
+
loadAssetCount(assetType: FtUserAssetType): Promise<void>;
|
|
51
|
+
loadBookmarkByMapId(mapId: string): Promise<void>;
|
|
52
|
+
reloadAssetCount(assetType: FtUserAssetType): Promise<void>;
|
|
22
53
|
registerBookmarkComponent(): Promise<void>;
|
|
23
54
|
private updateBookmarksIfUsed;
|
|
24
55
|
}
|
|
56
|
+
declare global {
|
|
57
|
+
interface Window {
|
|
58
|
+
FluidTopicsUserAssetsActions: UserAssetsActions;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
25
61
|
export declare const userAssetsActions: UserAssetsActions;
|
|
26
62
|
export {};
|
|
@@ -1,17 +1,42 @@
|
|
|
1
|
+
import { FtUserAssetType } from "@fluid-topics/public-api";
|
|
1
2
|
import { deepEqual, FtReduxStore } from "@fluid-topics/ft-wc-utils";
|
|
2
3
|
import { SavedSearchesService } from "../services/SavedSearchesService";
|
|
3
4
|
import { BookmarksService } from "../services/BookmarksService";
|
|
4
5
|
import { ftAppInfoStore } from "./FtAppInfoStore";
|
|
6
|
+
import { UserAssetsCountService } from "../services/user-assets/UserAssetCountService";
|
|
5
7
|
export const FtUserAssetsStoreName = "ft-user-assets";
|
|
8
|
+
const reducers = {
|
|
9
|
+
setAssetCount: (state, action) => {
|
|
10
|
+
const { userAssetType, count } = action.payload.assetCount;
|
|
11
|
+
state.assetCounts.allAsset[userAssetType] = count;
|
|
12
|
+
},
|
|
13
|
+
clearAssetCount: (state) => {
|
|
14
|
+
Object.values(FtUserAssetType).forEach(type => {
|
|
15
|
+
state.assetCounts.allAsset[type] = undefined;
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
setBookmarkCountByMap: (state, action) => {
|
|
19
|
+
const mapId = action.payload.mapId;
|
|
20
|
+
state.assetCounts.bookmarkByMap[mapId] = action.payload.count;
|
|
21
|
+
},
|
|
22
|
+
clearBookmarkCountByMap: (state) => {
|
|
23
|
+
state.assetCounts.bookmarkByMap = {};
|
|
24
|
+
},
|
|
25
|
+
};
|
|
6
26
|
export const ftUserAssetsStore = FtReduxStore.get({
|
|
7
27
|
name: FtUserAssetsStoreName,
|
|
28
|
+
reducers: reducers,
|
|
8
29
|
initialState: {
|
|
9
30
|
savedSearches: undefined,
|
|
10
31
|
bookmarks: undefined,
|
|
32
|
+
assetCounts: {
|
|
33
|
+
allAsset: Object.fromEntries(Object.values(FtUserAssetType).map(key => [key, undefined])), bookmarkByMap: {},
|
|
34
|
+
},
|
|
11
35
|
},
|
|
12
36
|
});
|
|
13
|
-
class UserAssetsActions {
|
|
14
|
-
constructor() {
|
|
37
|
+
export class UserAssetsActions {
|
|
38
|
+
constructor(assetCountsService = new UserAssetsCountService()) {
|
|
39
|
+
this.assetCountsService = assetCountsService;
|
|
15
40
|
this.currentSession = ftAppInfoStore.getState().session;
|
|
16
41
|
this.bookmarksAreUsed = false;
|
|
17
42
|
this.bookmarksService = new BookmarksService();
|
|
@@ -25,8 +50,13 @@ class UserAssetsActions {
|
|
|
25
50
|
this.currentSession = session;
|
|
26
51
|
this.clearMySearches(); // The search context automatically reload
|
|
27
52
|
this.reloadBookmarks();
|
|
53
|
+
this.clearUserAssetCounts();
|
|
28
54
|
}
|
|
29
55
|
}
|
|
56
|
+
clearUserAssetCounts() {
|
|
57
|
+
ftUserAssetsStore.actions.clearAssetCount();
|
|
58
|
+
ftUserAssetsStore.actions.clearBookmarkCountByMap();
|
|
59
|
+
}
|
|
30
60
|
clear() {
|
|
31
61
|
this.clearMySearches();
|
|
32
62
|
this.clearMyBookmarks();
|
|
@@ -48,6 +78,30 @@ class UserAssetsActions {
|
|
|
48
78
|
this.bookmarksService.clearCache();
|
|
49
79
|
await this.updateBookmarksIfUsed();
|
|
50
80
|
}
|
|
81
|
+
async loadAssetCount(assetType) {
|
|
82
|
+
const assetCount = await this.assetCountsService.getUserAssetCount(assetType);
|
|
83
|
+
if (assetCount) {
|
|
84
|
+
ftUserAssetsStore.actions.setAssetCount({ assetCount: assetCount });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async loadBookmarkByMapId(mapId) {
|
|
88
|
+
const bookmarkCount = await this.assetCountsService.getUserBookmarkCountByMap(mapId);
|
|
89
|
+
if (bookmarkCount) {
|
|
90
|
+
ftUserAssetsStore.actions.setBookmarkCountByMap({ count: bookmarkCount.count, mapId: mapId });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// Used in GWT
|
|
94
|
+
async reloadAssetCount(assetType) {
|
|
95
|
+
this.assetCountsService.clearCache();
|
|
96
|
+
const isBookmarkByMapStored = Object.keys(ftUserAssetsStore.getState().assetCounts.bookmarkByMap).length !== 0;
|
|
97
|
+
if (assetType === FtUserAssetType.BOOKMARKS && isBookmarkByMapStored) {
|
|
98
|
+
ftUserAssetsStore.actions.clearBookmarkCountByMap();
|
|
99
|
+
}
|
|
100
|
+
const isAssetCountStored = ftUserAssetsStore.getState().assetCounts.allAsset[assetType] !== undefined;
|
|
101
|
+
if (isAssetCountStored) {
|
|
102
|
+
await this.loadAssetCount(assetType);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
51
105
|
async registerBookmarkComponent() {
|
|
52
106
|
this.bookmarksAreUsed = true;
|
|
53
107
|
await this.updateBookmarksIfUsed();
|
|
@@ -61,3 +115,6 @@ class UserAssetsActions {
|
|
|
61
115
|
}
|
|
62
116
|
}
|
|
63
117
|
export const userAssetsActions = new UserAssetsActions();
|
|
118
|
+
if (window.FluidTopicsUserAssetsActions == null) {
|
|
119
|
+
window.FluidTopicsUserAssetsActions = userAssetsActions;
|
|
120
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FtUserAssetType } from "@fluid-topics/public-api";
|
|
2
|
+
import { ftUserAssetsStore } from "../FtUserAssetsStore";
|
|
3
|
+
export const selectAssetCount = (type, mapId) => {
|
|
4
|
+
if (type === undefined) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
if (type === FtUserAssetType.BOOKMARKS && mapId) {
|
|
8
|
+
return resolveBookmarkByMapCount(mapId);
|
|
9
|
+
}
|
|
10
|
+
return resolveAssetCount(type);
|
|
11
|
+
};
|
|
12
|
+
const resolveBookmarkByMapCount = (mapId) => {
|
|
13
|
+
if (ftUserAssetsStore.getState().assetCounts.bookmarkByMap[mapId] === undefined) {
|
|
14
|
+
window.FluidTopicsUserAssetsActions.loadBookmarkByMapId(mapId);
|
|
15
|
+
}
|
|
16
|
+
return ftUserAssetsStore.getState().assetCounts.bookmarkByMap[mapId];
|
|
17
|
+
};
|
|
18
|
+
const resolveAssetCount = (type) => {
|
|
19
|
+
if (ftUserAssetsStore.getState().assetCounts.allAsset[type] === undefined) {
|
|
20
|
+
window.FluidTopicsUserAssetsActions.loadAssetCount(type);
|
|
21
|
+
}
|
|
22
|
+
return ftUserAssetsStore.getState().assetCounts.allAsset[type];
|
|
23
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FtUserAssetCount, FtUserAssetType } from "@fluid-topics/public-api";
|
|
2
|
+
import { FtServiceWithCache } from "../FtServiceWithCache";
|
|
3
|
+
export declare class UserAssetsCountService extends FtServiceWithCache {
|
|
4
|
+
private readonly CACHE_DURATION;
|
|
5
|
+
getUserAssetCount(userAssetType: FtUserAssetType): Promise<FtUserAssetCount | undefined>;
|
|
6
|
+
getUserBookmarkCountByMap(mapId: string): Promise<FtUserAssetCount | undefined>;
|
|
7
|
+
private isAuthenticated;
|
|
8
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ftAppInfoStore } from "../../redux-stores/FtAppInfoStore";
|
|
2
|
+
import { FtServiceWithCache } from "../FtServiceWithCache";
|
|
3
|
+
export class UserAssetsCountService extends FtServiceWithCache {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.CACHE_DURATION = 3 * 60 * 1000;
|
|
7
|
+
}
|
|
8
|
+
async getUserAssetCount(userAssetType) {
|
|
9
|
+
if (!this.isAuthenticated()) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
return this.cache.get(`user-asset-count-${userAssetType}`, async () => (await this.awaitApi).get(`/internal/api/webapp/user/assets/count/${userAssetType}`), this.CACHE_DURATION);
|
|
13
|
+
}
|
|
14
|
+
async getUserBookmarkCountByMap(mapId) {
|
|
15
|
+
if (!this.isAuthenticated()) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
return this.cache.get(`user-bookmark-count-by-map-${mapId}`, async () => (await this.awaitApi).get(`/internal/api/webapp/user/assets/count/BOOKMARKS/${mapId}`), this.CACHE_DURATION);
|
|
19
|
+
}
|
|
20
|
+
isAuthenticated() {
|
|
21
|
+
const session = ftAppInfoStore.getState().session;
|
|
22
|
+
return Boolean(session === null || session === void 0 ? void 0 : session.sessionAuthenticated);
|
|
23
|
+
}
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-topics/ft-app-context",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.8",
|
|
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.
|
|
22
|
+
"@fluid-topics/ft-wc-utils": "1.3.8",
|
|
23
23
|
"lit": "3.1.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@fluid-topics/public-api": "1.0.99"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "cafb3e5814e9a916392cb95050a9e0f36d30227f"
|
|
29
29
|
}
|