@streamlayer/feature-gamification 0.24.0 → 0.25.0

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.
@@ -0,0 +1,6 @@
1
+ import type { Transport } from '@streamlayer/sdk-web-api';
2
+ import { ReadableAtom } from 'nanostores';
3
+ export declare const deepLink: (transport: Transport, $eventId: ReadableAtom<string | undefined>) => {
4
+ $store: import("@nanostores/query").FetcherStore<import("@streamlayer/sl-eslib/sdkSettings/client/client_pb").DeepLink | undefined, any>;
5
+ fetch: typeof fetch;
6
+ };
@@ -0,0 +1,5 @@
1
+ import { $deepLink } from './queries/deepLink';
2
+ export const deepLink = (transport, $eventId) => {
3
+ const $store = $deepLink(transport, [$eventId]);
4
+ return { $store, fetch };
5
+ };
@@ -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 { deepLink } from './deepLink';
9
10
  import { OnboardingStatus } from './onboarding';
10
11
  import { LeaderboardItem } from './queries/leaderboard';
11
12
  import { GamificationBackground } from './';
@@ -27,6 +28,7 @@ export declare class Gamification extends AbstractFeature<'games', PlainMessage<
27
28
  leaderboardId: WritableAtom<string | undefined>;
28
29
  /** leaderboard list */
29
30
  leaderboardList: ReturnType<typeof leaderboard>;
31
+ deepLink: ReturnType<typeof deepLink>;
30
32
  /** onboarding status */
31
33
  onboardingStatus: {
32
34
  $store: WritableAtom<OnboardingStatus | undefined>;
@@ -6,6 +6,7 @@ import * as queries from './queries';
6
6
  import * as actions from './queries/actions';
7
7
  import { GamificationStorage } from './storage';
8
8
  import { leaderboard } from './leaderboard';
9
+ import { deepLink } from './deepLink';
9
10
  import { onboarding } from './onboarding';
10
11
  import { gamificationBackground } from './';
11
12
  const GamificationQuestionTypes = new Set([QuestionType.POLL, QuestionType.PREDICTION, QuestionType.TRIVIA]);
@@ -27,6 +28,7 @@ export class Gamification extends AbstractFeature {
27
28
  leaderboardId;
28
29
  /** leaderboard list */
29
30
  leaderboardList;
31
+ deepLink;
30
32
  /** onboarding status */
31
33
  onboardingStatus;
32
34
  /** opened question */
@@ -55,6 +57,7 @@ export class Gamification extends AbstractFeature {
55
57
  this.closeFeature = instance.sdk.closeFeature;
56
58
  this.openFeature = () => instance.sdk.openFeature(FeatureType.GAMES);
57
59
  this.openedQuestion = this.background.openedQuestion;
60
+ this.deepLink = deepLink(this.transport, this.background.slStreamId);
58
61
  this.leaderboardList = leaderboard(this.transport, this.background.slStreamId);
59
62
  this.status.subscribe((status) => {
60
63
  if (status === FeatureStatus.Ready) {
@@ -137,11 +140,12 @@ export class Gamification extends AbstractFeature {
137
140
  });
138
141
  const question = await queries.getQuestionByUser(id, transport);
139
142
  const correctAnswer = question?.answers.find(({ correct }) => correct);
143
+ const votedAnswer = question?.answers.find(({ youVoted }) => youVoted);
140
144
  this.notifications.add({
141
145
  type: NotificationType.QUESTION_RESOLVED,
142
146
  action: () => this.openQuestion(id),
143
147
  close: () => this.closeQuestion(id),
144
- autoHideDuration: 5000,
148
+ autoHideDuration: 35000,
145
149
  id: notificationId,
146
150
  data: {
147
151
  questionType: QuestionType.PREDICTION,
@@ -149,6 +153,13 @@ export class Gamification extends AbstractFeature {
149
153
  title: correctAnswer?.youVoted
150
154
  ? `Congratulations! You answered correctly! You won ${correctAnswer.points} pts!`
151
155
  : `Better luck next time! Correct: ${correctAnswer?.text}!`,
156
+ votedAnswer: {
157
+ title: votedAnswer?.text,
158
+ points: votedAnswer?.points,
159
+ },
160
+ correctAnswerTitle: correctAnswer?.text,
161
+ correct: correctAnswer?.youVoted,
162
+ predictionResult: status === QuestionStatus.RESOLVED,
152
163
  },
153
164
  },
154
165
  });
@@ -0,0 +1,6 @@
1
+ import type { Transport } from '@streamlayer/sdk-web-api';
2
+ import { ReadableAtom } from 'nanostores';
3
+ import { DeepLink } from '@streamlayer/sl-eslib/sdkSettings/client/client_pb';
4
+ type EventId = ReadableAtom<string | undefined>;
5
+ export declare const $deepLink: (transport: Transport, params: [EventId]) => import("@nanostores/query").FetcherStore<DeepLink | undefined, any>;
6
+ export {};
@@ -0,0 +1,16 @@
1
+ import { Client } from '@streamlayer/sl-eslib/sdkSettings/client/client_connect';
2
+ export const $deepLink = (transport, params) => {
3
+ const { client, queryKey } = transport.createPromiseClient(Client, {
4
+ method: 'generateDeepLink',
5
+ params,
6
+ });
7
+ return transport.nanoquery.createFetcherStore(queryKey, {
8
+ fetcher: async (_, __, eventId) => {
9
+ if (!eventId) {
10
+ return {};
11
+ }
12
+ const res = await client.generateDeepLink({ data: { eventId: eventId } });
13
+ return res.data?.attributes;
14
+ },
15
+ });
16
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamlayer/feature-gamification",
3
- "version": "0.24.0",
3
+ "version": "0.25.0",
4
4
  "peerDependencies": {
5
5
  "@bufbuild/protobuf": "^1.4.2",
6
6
  "@streamlayer/sl-eslib": "^5.53.6",