@streamlayer/feature-gamification 0.21.0 → 0.21.2
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/lib/detail.js +34 -1
- package/package.json +9 -8
package/lib/detail.js
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
import { createMapStore } from '@streamlayer/sdk-web-interfaces';
|
|
2
|
+
import { deepmerge } from '@fastify/deepmerge';
|
|
2
3
|
import { computed } from 'nanostores';
|
|
3
4
|
import { getQuestionByUser } from './queries';
|
|
5
|
+
const mergeArray = (options) => (target, source) => {
|
|
6
|
+
let i = 0;
|
|
7
|
+
const tl = target.length;
|
|
8
|
+
const sl = source.length;
|
|
9
|
+
const il = Math.max(tl, sl);
|
|
10
|
+
const result = new Array(il);
|
|
11
|
+
for (i = 0; i < il; ++i) {
|
|
12
|
+
if (i < sl) {
|
|
13
|
+
result[i] = options.deepmerge(target[i], source[i]);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
result[i] = options.clone(target[i]);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
const mergeQuestion = deepmerge({ mergeArray });
|
|
4
22
|
export const detail = (transport, $openedQuestionId, $feedList) => {
|
|
5
23
|
const $store = computed([$openedQuestionId, $feedList], (openedQuestion, feedList) => {
|
|
6
24
|
if (openedQuestion) {
|
|
@@ -27,7 +45,22 @@ export const detail = (transport, $openedQuestionId, $feedList) => {
|
|
|
27
45
|
$extendedStore.set({ data: undefined, loading: false });
|
|
28
46
|
});
|
|
29
47
|
const updateExtendedQuestion = (question) => {
|
|
30
|
-
$extendedStore.
|
|
48
|
+
const currentQuestion = $extendedStore.get().data;
|
|
49
|
+
if (currentQuestion) {
|
|
50
|
+
/**
|
|
51
|
+
* We do not merge youVoted property, because it
|
|
52
|
+
* can be overwritten by the subscription response,
|
|
53
|
+
* which does not include user-specific data.
|
|
54
|
+
*/
|
|
55
|
+
for (const answer of question?.answers || []) {
|
|
56
|
+
if (answer.youVoted !== true) {
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
delete answer.youVoted;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
$extendedStore.set({ data: mergeQuestion(currentQuestion, question) });
|
|
31
64
|
};
|
|
32
65
|
return { $store, $extendedStore, updateExtendedQuestion };
|
|
33
66
|
};
|
package/package.json
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamlayer/feature-gamification",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.2",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@bufbuild/protobuf": "^1.4.2",
|
|
6
|
-
"@streamlayer/sl-eslib": "^5.53.
|
|
6
|
+
"@streamlayer/sl-eslib": "^5.53.6",
|
|
7
|
+
"@fastify/deepmerge": "*",
|
|
7
8
|
"nanostores": "^0.9.5",
|
|
8
|
-
"@streamlayer/sdk-web-interfaces": "^0.18.10",
|
|
9
|
-
"@streamlayer/sdk-web-core": "^0.17.3",
|
|
10
9
|
"@streamlayer/sdk-web-api": "^0.0.1",
|
|
11
|
-
"@streamlayer/sdk-web-
|
|
12
|
-
"@streamlayer/sdk-web-
|
|
13
|
-
"@streamlayer/sdk-web-
|
|
14
|
-
"@streamlayer/sdk-web-
|
|
10
|
+
"@streamlayer/sdk-web-core": "^0.17.5",
|
|
11
|
+
"@streamlayer/sdk-web-interfaces": "^0.18.12",
|
|
12
|
+
"@streamlayer/sdk-web-logger": "^0.0.2",
|
|
13
|
+
"@streamlayer/sdk-web-notifications": "^0.10.11",
|
|
14
|
+
"@streamlayer/sdk-web-storage": "^0.0.2",
|
|
15
|
+
"@streamlayer/sdk-web-types": "^0.18.2"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|
|
17
18
|
"tslib": "^2.6.2"
|