@streamlayer/feature-gamification 0.20.0 → 0.21.1
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/lib/gamification.d.ts +5 -0
- package/lib/gamification.js +10 -0
- package/package.json +8 -7
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/lib/gamification.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { PlainMessage } from '@bufbuild/protobuf';
|
|
|
6
6
|
import { WritableAtom } from 'nanostores';
|
|
7
7
|
import * as queries from './queries';
|
|
8
8
|
import { leaderboard } from './leaderboard';
|
|
9
|
+
import { LeaderboardItem } from './queries/leaderboard';
|
|
9
10
|
import { GamificationBackground } from './';
|
|
10
11
|
/**
|
|
11
12
|
* Required: in-app should be displayed and questions not available
|
|
@@ -44,6 +45,8 @@ export declare class Gamification extends AbstractFeature<'games', PlainMessage<
|
|
|
44
45
|
onboardingStatus: WritableAtom<OnboardingStatus | undefined>;
|
|
45
46
|
/** opened question */
|
|
46
47
|
openedQuestion: GamificationBackground['openedQuestion'];
|
|
48
|
+
/** pinned leaderboard id */
|
|
49
|
+
openedUser: WritableAtom<LeaderboardItem | undefined>;
|
|
47
50
|
private notifications;
|
|
48
51
|
private transport;
|
|
49
52
|
private closeFeature;
|
|
@@ -66,4 +69,6 @@ export declare class Gamification extends AbstractFeature<'games', PlainMessage<
|
|
|
66
69
|
skipQuestion: (questionId: string) => Promise<void>;
|
|
67
70
|
openQuestion: (questionId: string) => void;
|
|
68
71
|
closeQuestion: (questionId?: string) => void;
|
|
72
|
+
openUser: (userId: string) => void;
|
|
73
|
+
closeUser: () => void;
|
|
69
74
|
}
|
package/lib/gamification.js
CHANGED
|
@@ -46,6 +46,8 @@ export class Gamification extends AbstractFeature {
|
|
|
46
46
|
onboardingStatus;
|
|
47
47
|
/** opened question */
|
|
48
48
|
openedQuestion;
|
|
49
|
+
/** pinned leaderboard id */
|
|
50
|
+
openedUser;
|
|
49
51
|
notifications;
|
|
50
52
|
transport;
|
|
51
53
|
closeFeature;
|
|
@@ -60,6 +62,7 @@ export class Gamification extends AbstractFeature {
|
|
|
60
62
|
this.storage = new GamificationStorage();
|
|
61
63
|
this.userSummary = new ApiStore(queries.$userSummary(this.background.slStreamId, this.background.userId, instance.transport), 'gamification:userSummary');
|
|
62
64
|
this.feedList = this.background.feedList;
|
|
65
|
+
this.openedUser = createSingleStore(undefined);
|
|
63
66
|
this.leaderboardId = new SingleStore(createSingleStore(this.settings.getValue('pinnedLeaderboardId')), 'pinnedLeaderboardId').getStore();
|
|
64
67
|
this.onboardingStatus = new SingleStore(createSingleStore(OnboardingStatus.Unset), 'onboardingStatus').getStore();
|
|
65
68
|
this.notifications = instance.notifications;
|
|
@@ -256,4 +259,11 @@ export class Gamification extends AbstractFeature {
|
|
|
256
259
|
closeQuestion = (questionId) => {
|
|
257
260
|
return this.background.closeQuestion(questionId);
|
|
258
261
|
};
|
|
262
|
+
openUser = (userId) => {
|
|
263
|
+
const user = this.leaderboardList.$store.get().data?.find((item) => item.userId === userId);
|
|
264
|
+
this.openedUser.set(user);
|
|
265
|
+
};
|
|
266
|
+
closeUser = () => {
|
|
267
|
+
this.openedUser.set(undefined);
|
|
268
|
+
};
|
|
259
269
|
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamlayer/feature-gamification",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.1",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@bufbuild/protobuf": "^1.4.2",
|
|
6
6
|
"@streamlayer/sl-eslib": "^5.53.5",
|
|
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-logger": "^0.
|
|
14
|
-
"@streamlayer/sdk-web-notifications": "^0.10.
|
|
10
|
+
"@streamlayer/sdk-web-core": "^0.17.4",
|
|
11
|
+
"@streamlayer/sdk-web-interfaces": "^0.18.11",
|
|
12
|
+
"@streamlayer/sdk-web-logger": "^0.0.1",
|
|
13
|
+
"@streamlayer/sdk-web-notifications": "^0.10.10",
|
|
14
|
+
"@streamlayer/sdk-web-storage": "^0.0.1",
|
|
15
|
+
"@streamlayer/sdk-web-types": "^0.18.1"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|
|
17
18
|
"tslib": "^2.6.2"
|