@streamlayer/feature-gamification 0.31.0 → 0.33.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.
- package/lib/deepLink.d.ts +7 -2
- package/lib/deepLink.js +21 -4
- package/lib/leaderboard.js +30 -23
- package/lib/onboarding.js +1 -1
- package/lib/queries/deepLink.d.ts +4 -0
- package/lib/queries/deepLink.js +5 -0
- package/package.json +6 -6
package/lib/deepLink.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { Transport } from '@streamlayer/sdk-web-api';
|
|
2
2
|
import { ReadableAtom } from 'nanostores';
|
|
3
|
+
type DeepLinkData = {
|
|
4
|
+
data?: string;
|
|
5
|
+
loading?: boolean;
|
|
6
|
+
error?: string;
|
|
7
|
+
};
|
|
3
8
|
export declare const deepLink: (transport: Transport, $eventId: ReadableAtom<string | undefined>, $userId: ReadableAtom<string | undefined>) => {
|
|
4
|
-
$store: import("
|
|
9
|
+
$store: import("nanostores").MapStore<DeepLinkData>;
|
|
5
10
|
fetch: typeof fetch;
|
|
6
|
-
desktopLink: string;
|
|
7
11
|
};
|
|
12
|
+
export {};
|
package/lib/deepLink.js
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createMapStore } from '@streamlayer/sdk-web-interfaces';
|
|
2
|
+
import { onMount } from 'nanostores';
|
|
3
|
+
import { $deepLink, generateShortLink } from './queries/deepLink';
|
|
2
4
|
export const deepLink = (transport, $eventId, $userId) => {
|
|
3
|
-
const $store =
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
const $store = createMapStore({});
|
|
6
|
+
onMount($store, () => {
|
|
7
|
+
const $branchLink = $deepLink(transport, [$eventId]);
|
|
8
|
+
const cancel = $branchLink.subscribe(async ({ data }) => {
|
|
9
|
+
const mobileDeepLink = data?.url;
|
|
10
|
+
if (mobileDeepLink) {
|
|
11
|
+
$store.setKey('loading', true);
|
|
12
|
+
const desktopLink = `${window.location.host + window.location.pathname}%23sl_eid=${$eventId.get()}&sl_uid=${$userId.get()}`;
|
|
13
|
+
const shortLink = await generateShortLink(transport, { web: desktopLink, mobile: mobileDeepLink });
|
|
14
|
+
$store.set({
|
|
15
|
+
data: shortLink.data?.link,
|
|
16
|
+
loading: false,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return cancel;
|
|
21
|
+
});
|
|
22
|
+
return { $store, fetch };
|
|
6
23
|
};
|
package/lib/leaderboard.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createSingleStore, createMapStore } from '@streamlayer/sdk-web-interfaces';
|
|
2
|
+
import { onMount } from 'nanostores';
|
|
2
3
|
import { createLeaderboardListFetch } from './queries/leaderboard';
|
|
3
4
|
const defaultOptions = {
|
|
4
5
|
pageSize: 10,
|
|
@@ -30,32 +31,9 @@ export const leaderboard = (transport, $eventId, options) => {
|
|
|
30
31
|
$pagination.set(request.pagination);
|
|
31
32
|
}
|
|
32
33
|
};
|
|
33
|
-
$eventId.listen(refetch);
|
|
34
34
|
const invalidate = () => {
|
|
35
35
|
void refetch($eventId.get());
|
|
36
36
|
};
|
|
37
|
-
$pagination.listen(async (pagination) => {
|
|
38
|
-
const eventId = $eventId.get();
|
|
39
|
-
if (pagination.page > 0 && eventId) {
|
|
40
|
-
if (pagination.page < maxPage) {
|
|
41
|
-
$store.setKey('loading', true);
|
|
42
|
-
const request = {
|
|
43
|
-
eventId: eventId,
|
|
44
|
-
pagination,
|
|
45
|
-
};
|
|
46
|
-
const newData = await fetch(request);
|
|
47
|
-
const prevData = $store.get().data || [];
|
|
48
|
-
$store.set({
|
|
49
|
-
data: [...prevData, ...newData.data.map((item) => item.attributes)],
|
|
50
|
-
loading: false,
|
|
51
|
-
hasMore: true,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
$store.setKey('hasMore', false);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
37
|
/**
|
|
60
38
|
* Whether there is more data to fetch
|
|
61
39
|
*/
|
|
@@ -66,5 +44,34 @@ export const leaderboard = (transport, $eventId, options) => {
|
|
|
66
44
|
$pagination.set({ ...pagination, page: nextPage });
|
|
67
45
|
}
|
|
68
46
|
};
|
|
47
|
+
onMount($store, () => {
|
|
48
|
+
const cancelRefetchListener = $eventId.listen(refetch);
|
|
49
|
+
const cancelPaginationListener = $pagination.listen(async (pagination) => {
|
|
50
|
+
const eventId = $eventId.get();
|
|
51
|
+
if (pagination.page > 0 && eventId) {
|
|
52
|
+
if (pagination.page < maxPage) {
|
|
53
|
+
$store.setKey('loading', true);
|
|
54
|
+
const request = {
|
|
55
|
+
eventId: eventId,
|
|
56
|
+
pagination,
|
|
57
|
+
};
|
|
58
|
+
const newData = await fetch(request);
|
|
59
|
+
const prevData = $store.get().data || [];
|
|
60
|
+
$store.set({
|
|
61
|
+
data: [...prevData, ...newData.data.map((item) => item.attributes)],
|
|
62
|
+
loading: false,
|
|
63
|
+
hasMore: true,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
$store.setKey('hasMore', false);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return () => {
|
|
72
|
+
cancelRefetchListener();
|
|
73
|
+
cancelPaginationListener();
|
|
74
|
+
};
|
|
75
|
+
});
|
|
69
76
|
return { $store, fetchMore, invalidate };
|
|
70
77
|
};
|
package/lib/onboarding.js
CHANGED
|
@@ -25,7 +25,7 @@ export const onboarding = (service, background, transport, notifications) => {
|
|
|
25
25
|
const showOnboardingInApp = () => {
|
|
26
26
|
const { inplayGame } = service.featureSettings.get();
|
|
27
27
|
const notificationId = background.getCurrentSessionId({ prefix: 'onboarding' });
|
|
28
|
-
if (inplayGame) {
|
|
28
|
+
if (inplayGame && inplayGame.enable) {
|
|
29
29
|
notifications.add({
|
|
30
30
|
type: NotificationType.ONBOARDING,
|
|
31
31
|
id: notificationId,
|
|
@@ -3,4 +3,8 @@ import { ReadableAtom } from 'nanostores';
|
|
|
3
3
|
import { DeepLink } from '@streamlayer/sl-eslib/sdkSettings/client/client_pb';
|
|
4
4
|
type EventId = ReadableAtom<string | undefined>;
|
|
5
5
|
export declare const $deepLink: (transport: Transport, params: [EventId]) => import("@nanostores/query").FetcherStore<DeepLink | undefined, any>;
|
|
6
|
+
export declare const generateShortLink: (transport: Transport, { web, mobile }: {
|
|
7
|
+
web: string;
|
|
8
|
+
mobile: string;
|
|
9
|
+
}) => Promise<import("@streamlayer/sl-eslib/shortLinks/client_pb").GenerateResponse>;
|
|
6
10
|
export {};
|
package/lib/queries/deepLink.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Client } from '@streamlayer/sl-eslib/sdkSettings/client/client_connect';
|
|
2
|
+
import { Client as ShortLinkClient } from '@streamlayer/sl-eslib/shortLinks/client_connect';
|
|
2
3
|
export const $deepLink = (transport, params) => {
|
|
3
4
|
const { client, queryKey } = transport.createPromiseClient(Client, {
|
|
4
5
|
method: 'generateDeepLink',
|
|
@@ -14,3 +15,7 @@ export const $deepLink = (transport, params) => {
|
|
|
14
15
|
},
|
|
15
16
|
});
|
|
16
17
|
};
|
|
18
|
+
export const generateShortLink = (transport, { web, mobile }) => {
|
|
19
|
+
const { client } = transport.createPromiseClient(ShortLinkClient, { method: 'generate' });
|
|
20
|
+
return client.generate({ web, mobile });
|
|
21
|
+
};
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamlayer/feature-gamification",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.0",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@bufbuild/protobuf": "^1.4.2",
|
|
6
|
-
"@streamlayer/sl-eslib": "^5.61.
|
|
6
|
+
"@streamlayer/sl-eslib": "^5.61.1",
|
|
7
7
|
"@fastify/deepmerge": "*",
|
|
8
8
|
"nanostores": "^0.9.5",
|
|
9
|
-
"@streamlayer/sdk-web-api": "^0.1
|
|
10
|
-
"@streamlayer/sdk-web-core": "^0.1
|
|
11
|
-
"@streamlayer/sdk-web-interfaces": "^0.18.
|
|
9
|
+
"@streamlayer/sdk-web-api": "^0.0.1",
|
|
10
|
+
"@streamlayer/sdk-web-core": "^0.0.1",
|
|
11
|
+
"@streamlayer/sdk-web-interfaces": "^0.18.21",
|
|
12
12
|
"@streamlayer/sdk-web-logger": "^0.0.1",
|
|
13
|
-
"@streamlayer/sdk-web-notifications": "^0.0.
|
|
13
|
+
"@streamlayer/sdk-web-notifications": "^0.0.5",
|
|
14
14
|
"@streamlayer/sdk-web-storage": "^0.0.4",
|
|
15
15
|
"@streamlayer/sdk-web-types": "^0.1.0"
|
|
16
16
|
},
|