@fluid-topics/ft-app-context 1.3.39 → 1.3.41
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,4 +1,4 @@
|
|
|
1
|
-
import { FtBookmark, FtMySearch, FtUserAssetCount, FtUserAssetLabel, FtUserAssetType } from "@fluid-topics/public-api";
|
|
1
|
+
import { FtBookmark, FtCollection, 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
4
|
import { UserAssetLabelsService } from "../services/user-assets/UserAssetLabelsService";
|
|
@@ -15,6 +15,7 @@ export interface FtUserAssetsState {
|
|
|
15
15
|
assetCounts: AssetCounts;
|
|
16
16
|
assetLabels: Array<FtUserAssetLabel>;
|
|
17
17
|
}
|
|
18
|
+
type FtUserAsset = FtBookmark | FtMySearch | FtCollection;
|
|
18
19
|
declare const reducers: {
|
|
19
20
|
setAssetCount: (state: FtUserAssetsState, action: {
|
|
20
21
|
payload: {
|
|
@@ -34,11 +35,18 @@ declare const reducers: {
|
|
|
34
35
|
addAsset: (state: FtUserAssetsState, action: {
|
|
35
36
|
payload: {
|
|
36
37
|
assetType: FtUserAssetType;
|
|
37
|
-
asset:
|
|
38
|
+
asset: FtUserAsset;
|
|
38
39
|
mapId?: string | undefined;
|
|
39
40
|
};
|
|
40
41
|
type: string;
|
|
41
42
|
}) => void;
|
|
43
|
+
editAsset: (state: FtUserAssetsState, action: {
|
|
44
|
+
payload: {
|
|
45
|
+
assetType: FtUserAssetType;
|
|
46
|
+
asset: FtUserAsset;
|
|
47
|
+
};
|
|
48
|
+
type: string;
|
|
49
|
+
}) => void;
|
|
42
50
|
removeAsset: (state: FtUserAssetsState, action: {
|
|
43
51
|
payload: {
|
|
44
52
|
assetType: FtUserAssetType;
|
|
@@ -25,58 +25,60 @@ const reducers = {
|
|
|
25
25
|
},
|
|
26
26
|
addAsset: (state, action) => {
|
|
27
27
|
const { assetType, mapId, asset } = action.payload;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
break;
|
|
37
|
-
case FtUserAssetType.SEARCHES:
|
|
38
|
-
if (state.savedSearches) {
|
|
39
|
-
state.savedSearches.push(asset);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
state.savedSearches = [asset];
|
|
43
|
-
}
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
const currentCount = state.assetCounts.allAsset[assetType];
|
|
47
|
-
if (currentCount !== undefined) {
|
|
48
|
-
state.assetCounts.allAsset[assetType] = currentCount + 1;
|
|
49
|
-
}
|
|
50
|
-
if (assetType === FtUserAssetType.BOOKMARKS && mapId !== undefined) {
|
|
51
|
-
const currentMapCount = state.assetCounts.bookmarkByMap[mapId];
|
|
52
|
-
if (currentMapCount !== undefined) {
|
|
53
|
-
state.assetCounts.bookmarkByMap[mapId] = currentMapCount + 1;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
28
|
+
updateAssetsByType(state, assetType, [...getAssetsByType(state, assetType), asset]);
|
|
29
|
+
updateAssetCount(state, assetType, +1, mapId);
|
|
30
|
+
updateAssetLabels(state, asset);
|
|
31
|
+
},
|
|
32
|
+
editAsset: (state, action) => {
|
|
33
|
+
const { assetType, asset } = action.payload;
|
|
34
|
+
updateAssetsByType(state, assetType, getAssetsByType(state, assetType).map((a) => a.id === asset.id ? asset : a));
|
|
35
|
+
updateAssetLabels(state, asset);
|
|
56
36
|
},
|
|
57
37
|
removeAsset: (state, action) => {
|
|
58
|
-
var _a, _b;
|
|
59
38
|
const { assetType, mapId, assetId } = action.payload;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
state.bookmarks = (_a = state.bookmarks) === null || _a === void 0 ? void 0 : _a.filter((b) => b.id !== assetId);
|
|
63
|
-
break;
|
|
64
|
-
case FtUserAssetType.SEARCHES:
|
|
65
|
-
state.savedSearches = (_b = state.savedSearches) === null || _b === void 0 ? void 0 : _b.filter((s) => s.id !== assetId);
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
const currentCount = state.assetCounts.allAsset[assetType];
|
|
69
|
-
if (currentCount !== undefined && currentCount > 0) {
|
|
70
|
-
state.assetCounts.allAsset[assetType] = currentCount - 1;
|
|
71
|
-
}
|
|
72
|
-
if (assetType === FtUserAssetType.BOOKMARKS && mapId !== undefined) {
|
|
73
|
-
const currentMapCount = state.assetCounts.bookmarkByMap[mapId];
|
|
74
|
-
if (currentMapCount !== undefined && currentMapCount > 0) {
|
|
75
|
-
state.assetCounts.bookmarkByMap[mapId] = currentMapCount - 1;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
39
|
+
updateAssetsByType(state, assetType, getAssetsByType(state, assetType).filter((a) => a.id !== assetId));
|
|
40
|
+
updateAssetCount(state, assetType, -1, mapId);
|
|
78
41
|
},
|
|
79
42
|
};
|
|
43
|
+
const assetTypeToStateKey = {
|
|
44
|
+
// Refactor Optional<UserAssetsKey> to UserAssetsKey as soon as all asset arrays are present in store
|
|
45
|
+
[FtUserAssetType.SEARCHES]: "savedSearches",
|
|
46
|
+
[FtUserAssetType.BOOKMARKS]: "bookmarks",
|
|
47
|
+
[FtUserAssetType.BOOKS]: undefined,
|
|
48
|
+
[FtUserAssetType.COLLECTIONS]: undefined,
|
|
49
|
+
};
|
|
50
|
+
const getAssetsByType = (state, assetType) => {
|
|
51
|
+
var _a;
|
|
52
|
+
const stateKey = assetTypeToStateKey[assetType];
|
|
53
|
+
return stateKey
|
|
54
|
+
? (_a = state[stateKey]) !== null && _a !== void 0 ? _a : []
|
|
55
|
+
: [];
|
|
56
|
+
};
|
|
57
|
+
const updateAssetsByType = (state, assetType, assets) => {
|
|
58
|
+
const stateKey = assetTypeToStateKey[assetType];
|
|
59
|
+
if (stateKey) {
|
|
60
|
+
state[stateKey] = assets;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const updateAssetCount = (state, assetType, delta, mapId) => {
|
|
64
|
+
const currentCount = state.assetCounts.allAsset[assetType];
|
|
65
|
+
if (currentCount === undefined) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
// We use the Math.max to ensure we don’t go under 0 whether we increment or decrement
|
|
69
|
+
state.assetCounts.allAsset[assetType] = Math.max(0, currentCount + delta);
|
|
70
|
+
if (assetType === FtUserAssetType.BOOKMARKS && mapId) {
|
|
71
|
+
const currentMapCount = state.assetCounts.bookmarkByMap[mapId];
|
|
72
|
+
state.assetCounts.bookmarkByMap[mapId] = Math.max(0, currentMapCount + delta);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const updateAssetLabels = (state, asset) => {
|
|
76
|
+
const existingLabels = state.assetLabels.map((l) => l.title);
|
|
77
|
+
const newLabels = asset.labels
|
|
78
|
+
.filter((l) => !existingLabels.includes(l))
|
|
79
|
+
.map((l) => ({ title: l }));
|
|
80
|
+
state.assetLabels.push(...newLabels);
|
|
81
|
+
};
|
|
80
82
|
export const ftUserAssetsStore = FtReduxStore.get({
|
|
81
83
|
name: FtUserAssetsStoreName,
|
|
82
84
|
reducers: reducers,
|
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.41",
|
|
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.41",
|
|
23
23
|
"lit": "3.1.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@fluid-topics/public-api": "1.0.
|
|
26
|
+
"@fluid-topics/public-api": "1.0.108"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "befd5a39e849a1ef18dc1cf85da953e419ce520f"
|
|
29
29
|
}
|