@vouchfor/embeds 0.0.0-experiment.a499b59 → 0.0.0-experiment.a8aff5d
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/dist/es/browser-21b48b29.js +733 -0
- package/dist/es/browser-21b48b29.js.map +1 -0
- package/dist/es/embeds.js +12 -1592
- package/dist/es/embeds.js.map +1 -1
- package/dist/es/index-c6a46eda.js +4599 -0
- package/dist/es/index-c6a46eda.js.map +1 -0
- package/dist/es/src/components/DialogEmbed/DialogOverlay.d.ts +19 -0
- package/dist/es/src/components/DialogEmbed/DialogPortal.d.ts +35 -0
- package/dist/es/src/components/DialogEmbed/index.d.ts +36 -0
- package/dist/es/src/components/PlayerEmbed/controllers/event-forwarder.d.ts +15 -0
- package/dist/es/src/components/{Embed → PlayerEmbed}/controllers/fetcher.d.ts +5 -4
- package/dist/es/src/components/{Embed/controllers/tracking.d.ts → PlayerEmbed/controllers/tracking/index.d.ts} +14 -11
- package/dist/es/src/components/PlayerEmbed/controllers/tracking/utils.d.ts +17 -0
- package/dist/es/src/components/{Embed → PlayerEmbed}/index.d.ts +27 -20
- package/dist/es/src/components/PlayerEmbed/tests/data.d.ts +3 -0
- package/dist/es/src/index.d.ts +2 -1
- package/dist/iife/dialog-embed/browser-be9f1140.js +433 -0
- package/dist/iife/dialog-embed/browser-be9f1140.js.map +1 -0
- package/dist/iife/dialog-embed/embed.iife.js +1722 -0
- package/dist/iife/dialog-embed/embed.iife.js.map +1 -0
- package/dist/iife/dialog-embed/embed.js +5 -0
- package/dist/iife/dialog-embed/embed.js.map +1 -0
- package/dist/iife/dialog-embed/index-98d379d2.js +27151 -0
- package/dist/iife/dialog-embed/index-98d379d2.js.map +1 -0
- package/dist/iife/dialog-embed/src/components/DialogEmbed/DialogOverlay.d.ts +19 -0
- package/dist/iife/dialog-embed/src/components/DialogEmbed/DialogPortal.d.ts +35 -0
- package/dist/iife/dialog-embed/src/components/DialogEmbed/index.d.ts +36 -0
- package/dist/iife/dialog-embed/src/components/PlayerEmbed/controllers/event-forwarder.d.ts +15 -0
- package/dist/iife/dialog-embed/src/components/PlayerEmbed/controllers/fetcher.d.ts +14 -0
- package/dist/iife/dialog-embed/src/components/PlayerEmbed/controllers/tracking/index.d.ts +36 -0
- package/dist/iife/dialog-embed/src/components/PlayerEmbed/controllers/tracking/utils.d.ts +17 -0
- package/dist/iife/dialog-embed/src/components/PlayerEmbed/index.d.ts +73 -0
- package/dist/iife/dialog-embed/src/components/PlayerEmbed/tests/data.d.ts +3 -0
- package/dist/iife/dialog-embed/src/index.d.ts +2 -0
- package/dist/iife/dialog-embed/src/utils/env.d.ts +12 -0
- package/dist/iife/dialog-embed/src/utils/events.d.ts +2 -0
- package/dist/iife/embeds.iife.js +646 -358
- package/dist/iife/embeds.iife.js.map +1 -1
- package/dist/iife/player-embed/browser-7a9c505e.js +433 -0
- package/dist/iife/player-embed/browser-7a9c505e.js.map +1 -0
- package/dist/iife/player-embed/embed.iife.js +1584 -0
- package/dist/iife/player-embed/embed.iife.js.map +1 -0
- package/dist/iife/player-embed/embed.js +5 -0
- package/dist/iife/player-embed/embed.js.map +1 -0
- package/dist/iife/player-embed/index-530d058f.js +26706 -0
- package/dist/iife/player-embed/index-530d058f.js.map +1 -0
- package/dist/iife/player-embed/src/components/DialogEmbed/DialogOverlay.d.ts +19 -0
- package/dist/iife/player-embed/src/components/DialogEmbed/DialogPortal.d.ts +35 -0
- package/dist/iife/player-embed/src/components/DialogEmbed/index.d.ts +36 -0
- package/dist/iife/player-embed/src/components/PlayerEmbed/controllers/event-forwarder.d.ts +15 -0
- package/dist/iife/player-embed/src/components/PlayerEmbed/controllers/fetcher.d.ts +14 -0
- package/dist/iife/player-embed/src/components/PlayerEmbed/controllers/tracking/index.d.ts +36 -0
- package/dist/iife/player-embed/src/components/PlayerEmbed/controllers/tracking/utils.d.ts +17 -0
- package/dist/iife/player-embed/src/components/PlayerEmbed/index.d.ts +73 -0
- package/dist/iife/player-embed/src/components/PlayerEmbed/tests/data.d.ts +3 -0
- package/dist/iife/player-embed/src/index.d.ts +2 -0
- package/dist/iife/player-embed/src/utils/env.d.ts +12 -0
- package/dist/iife/player-embed/src/utils/events.d.ts +2 -0
- package/package.json +13 -5
- package/src/components/DialogEmbed/Dialog.stories.ts +91 -0
- package/src/components/DialogEmbed/DialogOverlay.ts +131 -0
- package/src/components/DialogEmbed/DialogPortal.ts +126 -0
- package/src/components/DialogEmbed/index.ts +97 -0
- package/src/components/{Embed/Embed.stories.ts → PlayerEmbed/PlayerEmbed.stories.ts} +27 -14
- package/src/components/{Embed → PlayerEmbed}/controllers/event-forwarder.ts +6 -5
- package/src/components/{Embed → PlayerEmbed}/controllers/fetcher.ts +33 -14
- package/src/components/{Embed/controllers/tracking.ts → PlayerEmbed/controllers/tracking/index.ts} +47 -115
- package/src/components/PlayerEmbed/controllers/tracking/utils.ts +95 -0
- package/src/components/{Embed → PlayerEmbed}/index.ts +76 -28
- package/src/components/PlayerEmbed/tests/PlayerEmbed.spec.ts +80 -0
- package/src/components/PlayerEmbed/tests/data.ts +183 -0
- package/src/index.ts +2 -1
@@ -0,0 +1,126 @@
|
|
1
|
+
import { html, LitElement } from 'lit';
|
2
|
+
import { customElement, property, state } from 'lit/decorators.js';
|
3
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
4
|
+
import { createRef, ref } from 'lit/directives/ref.js';
|
5
|
+
import { styleMap } from 'lit/directives/style-map.js';
|
6
|
+
|
7
|
+
import type { DialogEmbedProps } from '.';
|
8
|
+
import type { MediaPlayer } from '@vouchfor/media-player';
|
9
|
+
|
10
|
+
import './DialogOverlay';
|
11
|
+
|
12
|
+
@customElement('vouch-embed-dialog-portal')
|
13
|
+
class DialogPortal extends LitElement {
|
14
|
+
@property({ type: String }) vouchId: DialogEmbedProps['vouchId'];
|
15
|
+
@property({ type: String }) templateId: DialogEmbedProps['templateId'];
|
16
|
+
@property({ type: Array }) questions: DialogEmbedProps['questions'];
|
17
|
+
|
18
|
+
@property({ type: String }) env: DialogEmbedProps['env'] = 'prod';
|
19
|
+
@property({ type: String }) apiKey: DialogEmbedProps['apiKey'] = '';
|
20
|
+
@property({ type: Boolean }) disableTracking: DialogEmbedProps['disableTracking'] = false;
|
21
|
+
@property({ type: String }) trackingSource: DialogEmbedProps['trackingSource'] = 'embedded_player';
|
22
|
+
|
23
|
+
@property({ type: Array }) controls: DialogEmbedProps['controls'];
|
24
|
+
@property({ type: String }) preload: DialogEmbedProps['preload'] = 'none';
|
25
|
+
@property({ type: Boolean }) disableAutoplay: DialogEmbedProps['disableAutoplay'] = false;
|
26
|
+
@property({ type: Number }) aspectRatio: DialogEmbedProps['aspectRatio'] = 0;
|
27
|
+
|
28
|
+
private _mediaPlayerRef = createRef<MediaPlayer>();
|
29
|
+
|
30
|
+
@state() open = false;
|
31
|
+
|
32
|
+
private _handleToggle = ({ detail }: CustomEvent<string>) => {
|
33
|
+
// Because we have to attach this listener to the document since this element is portalled outside of the button,
|
34
|
+
// we also have to make sure that this player is actually the one we want to open and play by passing in an ID
|
35
|
+
// from the button wrapper parent and checking against that same ID we pass as the event detail
|
36
|
+
if (this.id === detail) {
|
37
|
+
this.open = !this.open;
|
38
|
+
|
39
|
+
if (this.open) {
|
40
|
+
if (!this.disableAutoplay && this._mediaPlayerRef?.value) {
|
41
|
+
this._mediaPlayerRef.value.muted = false;
|
42
|
+
this._mediaPlayerRef.value.play();
|
43
|
+
}
|
44
|
+
} else {
|
45
|
+
this._mediaPlayerRef?.value?.pause();
|
46
|
+
}
|
47
|
+
}
|
48
|
+
};
|
49
|
+
|
50
|
+
// We could do the same thing on close and check for the correct ID but it doesn't really matter
|
51
|
+
private _handleClose = () => {
|
52
|
+
this.open = false;
|
53
|
+
this._mediaPlayerRef?.value?.pause();
|
54
|
+
};
|
55
|
+
|
56
|
+
private _handleDocumentKeyUp = (e: KeyboardEvent) => {
|
57
|
+
if (e.key === 'Escape') {
|
58
|
+
this._handleClose();
|
59
|
+
}
|
60
|
+
};
|
61
|
+
|
62
|
+
connectedCallback(): void {
|
63
|
+
super.connectedCallback();
|
64
|
+
document.addEventListener('dialogembed:click', this._handleToggle);
|
65
|
+
document.addEventListener('keyup', this._handleDocumentKeyUp);
|
66
|
+
document.addEventListener('close:click', this._handleClose);
|
67
|
+
document.addEventListener('overlay:click', this._handleClose);
|
68
|
+
}
|
69
|
+
|
70
|
+
disconnectedCallback(): void {
|
71
|
+
super.disconnectedCallback();
|
72
|
+
document.removeEventListener('dialogembed:click', this._handleToggle);
|
73
|
+
document.removeEventListener('keyup', this._handleDocumentKeyUp);
|
74
|
+
document.removeEventListener('close:click', this._handleClose);
|
75
|
+
document.removeEventListener('overlay:click', this._handleClose);
|
76
|
+
}
|
77
|
+
|
78
|
+
protected createRenderRoot(): HTMLElement | DocumentFragment {
|
79
|
+
// We must create a new node here because portalling into the same node (document.body) causes the second
|
80
|
+
// element to overwrite the first for some reason (not behaviour really stated in the docs)
|
81
|
+
// I am fairly certain this function is only run once as the default behaviour creates the open shadow root
|
82
|
+
// and returns that shadow root in this function: https://lit.dev/docs/components/shadow-dom/#implementing-createrenderroot
|
83
|
+
const newNode = document.createElement('div');
|
84
|
+
document.body.appendChild(newNode);
|
85
|
+
return newNode;
|
86
|
+
}
|
87
|
+
|
88
|
+
render() {
|
89
|
+
return html`
|
90
|
+
<vouch-embed-dialog-overlay ?open=${this.open} aspectRatio=${this.aspectRatio}>
|
91
|
+
<vouch-embed-player
|
92
|
+
${ref(this._mediaPlayerRef)}
|
93
|
+
style=${styleMap({
|
94
|
+
maxWidth: '100%',
|
95
|
+
maxHeight: '100%'
|
96
|
+
})}
|
97
|
+
?autoplay=${false}
|
98
|
+
vouchId=${ifDefined(this.vouchId)}
|
99
|
+
templateId=${ifDefined(this.templateId)}
|
100
|
+
.questions=${this.questions}
|
101
|
+
.controls=${this.controls}
|
102
|
+
env=${ifDefined(this.env)}
|
103
|
+
apiKey=${ifDefined(this.apiKey)}
|
104
|
+
?disableTracking=${this.disableTracking}
|
105
|
+
trackingSource=${ifDefined(this.trackingSource)}
|
106
|
+
preload=${ifDefined(this.preload)}
|
107
|
+
aspectRatio=${this.aspectRatio}
|
108
|
+
></vouch-embed-player>
|
109
|
+
</vouch-embed-dialog-overlay>
|
110
|
+
`;
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
declare global {
|
115
|
+
interface HTMLElementTagNameMap {
|
116
|
+
'vouch-embed-dialog-portal': DialogPortal;
|
117
|
+
}
|
118
|
+
|
119
|
+
namespace JSX {
|
120
|
+
interface IntrinsicElements {
|
121
|
+
'vouch-embed-dialog-portal': DialogPortal;
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
export { DialogPortal };
|
@@ -0,0 +1,97 @@
|
|
1
|
+
import { css, html, LitElement } from 'lit';
|
2
|
+
import { customElement, property } from 'lit/decorators.js';
|
3
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
4
|
+
import { v4 as uuidv4 } from 'uuid';
|
5
|
+
|
6
|
+
import type { PlayerEmbedProps } from '../PlayerEmbed';
|
7
|
+
|
8
|
+
import '../PlayerEmbed';
|
9
|
+
import './DialogPortal';
|
10
|
+
|
11
|
+
type DialogEmbedProps = Omit<PlayerEmbedProps, 'data'> & {
|
12
|
+
disableAutoplay?: boolean;
|
13
|
+
};
|
14
|
+
|
15
|
+
@customElement('vouch-embed-dialog')
|
16
|
+
class DialogEmbed extends LitElement {
|
17
|
+
static styles = [
|
18
|
+
css`
|
19
|
+
:host {
|
20
|
+
--vu-button-padding: 10px 20px;
|
21
|
+
--vu-button-background: #287179;
|
22
|
+
--vu-button-background-hover: #4faab2;
|
23
|
+
|
24
|
+
display: flex;
|
25
|
+
width: fit-content;
|
26
|
+
height: fit-content;
|
27
|
+
}
|
28
|
+
`
|
29
|
+
];
|
30
|
+
|
31
|
+
@property({ type: String }) vouchId: DialogEmbedProps['vouchId'];
|
32
|
+
@property({ type: String }) templateId: DialogEmbedProps['templateId'];
|
33
|
+
@property({ type: Array }) questions: DialogEmbedProps['questions'];
|
34
|
+
|
35
|
+
@property({ type: String }) env: DialogEmbedProps['env'] = 'prod';
|
36
|
+
@property({ type: String }) apiKey: DialogEmbedProps['apiKey'] = '';
|
37
|
+
@property({ type: Boolean }) disableTracking: DialogEmbedProps['disableTracking'] = false;
|
38
|
+
@property({ type: String }) trackingSource: DialogEmbedProps['trackingSource'] = 'embedded_player';
|
39
|
+
|
40
|
+
@property({ type: Array }) controls: DialogEmbedProps['controls'];
|
41
|
+
@property({ type: String }) preload: DialogEmbedProps['preload'] = 'none';
|
42
|
+
@property({ type: Boolean }) disableAutoplay: DialogEmbedProps['disableAutoplay'] = false;
|
43
|
+
@property({ type: Number }) aspectRatio: DialogEmbedProps['aspectRatio'] = 0;
|
44
|
+
|
45
|
+
private _id = uuidv4();
|
46
|
+
|
47
|
+
private _handleRootClick = () => {
|
48
|
+
this.dispatchEvent(new CustomEvent('dialogembed:click', { detail: this._id, bubbles: true, composed: true }));
|
49
|
+
};
|
50
|
+
|
51
|
+
connectedCallback(): void {
|
52
|
+
super.connectedCallback();
|
53
|
+
this.addEventListener('click', this._handleRootClick);
|
54
|
+
}
|
55
|
+
|
56
|
+
disconnectedCallback(): void {
|
57
|
+
super.disconnectedCallback();
|
58
|
+
this.removeEventListener('click', this._handleRootClick);
|
59
|
+
}
|
60
|
+
|
61
|
+
render() {
|
62
|
+
return html`
|
63
|
+
<slot>
|
64
|
+
<vmp-button size="large">Play</vmp-button>
|
65
|
+
</slot>
|
66
|
+
<vouch-embed-dialog-portal
|
67
|
+
id=${this._id}
|
68
|
+
?autoplay=${false}
|
69
|
+
vouchId=${ifDefined(this.vouchId)}
|
70
|
+
templateId=${ifDefined(this.templateId)}
|
71
|
+
.questions=${this.questions}
|
72
|
+
.controls=${this.controls}
|
73
|
+
env=${ifDefined(this.env)}
|
74
|
+
apiKey=${ifDefined(this.apiKey)}
|
75
|
+
?disableTracking=${this.disableTracking}
|
76
|
+
trackingSource=${ifDefined(this.trackingSource)}
|
77
|
+
preload=${ifDefined(this.preload)}
|
78
|
+
aspectRatio=${this.aspectRatio}
|
79
|
+
></vouch-embed-dialog-portal>
|
80
|
+
`;
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
declare global {
|
85
|
+
interface HTMLElementTagNameMap {
|
86
|
+
'vouch-embed-dialog': DialogEmbed;
|
87
|
+
}
|
88
|
+
|
89
|
+
namespace JSX {
|
90
|
+
interface IntrinsicElements {
|
91
|
+
'vouch-embed-dialog': DialogEmbed;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
export { DialogEmbed };
|
97
|
+
export type { DialogEmbedProps };
|
@@ -1,48 +1,61 @@
|
|
1
1
|
import { html } from 'lit';
|
2
2
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
3
3
|
|
4
|
-
import type {
|
4
|
+
import type { PlayerEmbedProps } from '.';
|
5
5
|
import type { Meta, StoryObj } from '@storybook/web-components';
|
6
6
|
|
7
|
-
import '
|
7
|
+
import '.';
|
8
8
|
|
9
|
-
type
|
9
|
+
type PlayerEmbedArgs = PlayerEmbedProps & {
|
10
10
|
showVouch?: boolean;
|
11
11
|
};
|
12
12
|
|
13
|
-
const
|
13
|
+
const _PlayerEmbed = ({
|
14
|
+
vouchId,
|
15
|
+
templateId,
|
16
|
+
questions,
|
17
|
+
preload,
|
18
|
+
autoplay,
|
19
|
+
env,
|
20
|
+
apiKey,
|
21
|
+
controls,
|
22
|
+
aspectRatio
|
23
|
+
}: PlayerEmbedArgs) => {
|
14
24
|
return html`
|
15
25
|
<div style="height: 100vh">
|
16
|
-
<vouch-embed
|
26
|
+
<vouch-embed-player
|
17
27
|
env=${ifDefined(env)}
|
18
28
|
apiKey=${ifDefined(apiKey)}
|
19
29
|
vouchId=${ifDefined(vouchId)}
|
20
30
|
templateId=${ifDefined(templateId)}
|
31
|
+
.questions=${questions}
|
21
32
|
.controls=${controls}
|
22
33
|
?autoplay=${autoplay}
|
23
34
|
preload=${ifDefined(preload)}
|
24
35
|
aspectRatio=${ifDefined(aspectRatio)}
|
25
|
-
|
36
|
+
@error=${console.log}
|
37
|
+
></vouch-embed-player>
|
26
38
|
</div>
|
27
39
|
`;
|
28
40
|
};
|
29
41
|
|
30
42
|
// More on how to set up stories at: https://storybook.js.org/docs/web-components/writing-stories/introduction
|
31
43
|
const meta = {
|
32
|
-
title: '
|
44
|
+
title: 'Embeds',
|
33
45
|
tags: ['autodocs'],
|
34
|
-
render: (args) =>
|
35
|
-
component: 'vouch-embed'
|
36
|
-
} satisfies Meta<
|
46
|
+
render: (args) => _PlayerEmbed(args),
|
47
|
+
component: 'vouch-embed-player'
|
48
|
+
} satisfies Meta<PlayerEmbedProps>;
|
37
49
|
|
38
|
-
type Story = StoryObj<
|
50
|
+
type Story = StoryObj<PlayerEmbedArgs>;
|
39
51
|
|
40
|
-
const
|
52
|
+
const Player: Story = {
|
41
53
|
args: {
|
42
|
-
env: '
|
54
|
+
env: 'dev',
|
43
55
|
apiKey: 'TVik9uTMgE-PD25UTHIS6gyl0hMBWC7AT4dkpdlLBT4VIfDWZJrQiCk6Ak7m1',
|
44
56
|
vouchId: '6JQEIPeStt',
|
45
57
|
templateId: '357fc118-e179-4171-9446-ff2b8e9d1b29',
|
58
|
+
questions: [],
|
46
59
|
aspectRatio: 0,
|
47
60
|
preload: 'none',
|
48
61
|
autoplay: false
|
@@ -63,4 +76,4 @@ const Embed: Story = {
|
|
63
76
|
};
|
64
77
|
|
65
78
|
export default meta;
|
66
|
-
export {
|
79
|
+
export { Player };
|
@@ -1,27 +1,28 @@
|
|
1
1
|
import { createRef, ref } from 'lit/directives/ref.js';
|
2
2
|
|
3
|
-
import type {
|
3
|
+
import type { PlayerEmbed } from '..';
|
4
4
|
import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
5
|
+
import type { DirectiveResult } from 'lit/directive.js';
|
5
6
|
import type { Ref } from 'lit/directives/ref.js';
|
6
7
|
|
7
8
|
import { forwardEvent } from '~/utils/events';
|
8
9
|
|
9
|
-
type
|
10
|
+
type PlayerEmbedHost = ReactiveControllerHost & PlayerEmbed;
|
10
11
|
|
11
12
|
class EventForwardController implements ReactiveController {
|
12
|
-
host:
|
13
|
+
host: PlayerEmbedHost;
|
13
14
|
|
14
15
|
private _events: string[] = [];
|
15
16
|
private _cleanup: (() => void)[] = [];
|
16
17
|
private _forwardElementRef: Ref<HTMLElement> = createRef();
|
17
18
|
|
18
|
-
constructor(host:
|
19
|
+
constructor(host: PlayerEmbedHost, events: string[]) {
|
19
20
|
this.host = host;
|
20
21
|
this._events = events;
|
21
22
|
host.addController(this);
|
22
23
|
}
|
23
24
|
|
24
|
-
register() {
|
25
|
+
register(): DirectiveResult {
|
25
26
|
return ref(this._forwardElementRef);
|
26
27
|
}
|
27
28
|
|
@@ -1,26 +1,29 @@
|
|
1
1
|
import { Task } from '@lit/task';
|
2
2
|
import { v4 as uuidv4 } from 'uuid';
|
3
3
|
|
4
|
-
import type {
|
4
|
+
import type { PlayerEmbed, PlayerEmbedProps } from '..';
|
5
5
|
import type { ReactiveControllerHost } from 'lit';
|
6
6
|
import type { Environment } from '~/utils/env';
|
7
7
|
|
8
8
|
import { getEnvUrls } from '~/utils/env';
|
9
9
|
|
10
|
-
type
|
10
|
+
type PlayerEmbedHost = ReactiveControllerHost & PlayerEmbed;
|
11
11
|
|
12
|
-
type
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
type FetchTaskDeps = [
|
13
|
+
PlayerEmbedProps['env'],
|
14
|
+
PlayerEmbedProps['apiKey'],
|
15
|
+
PlayerEmbedProps['data'],
|
16
|
+
PlayerEmbedProps['vouchId'],
|
17
|
+
PlayerEmbedProps['templateId']
|
18
18
|
];
|
19
19
|
|
20
|
+
type FilterTaskDeps = [PlayerEmbedProps['data'], PlayerEmbedProps['questions']];
|
21
|
+
|
20
22
|
class FetcherController {
|
21
|
-
host:
|
23
|
+
host: PlayerEmbedHost;
|
22
24
|
|
23
25
|
private _fetching = false;
|
26
|
+
private _vouch: PlayerEmbedProps['data'];
|
24
27
|
|
25
28
|
set fetching(value) {
|
26
29
|
if (this._fetching !== value) {
|
@@ -94,11 +97,11 @@ class FetcherController {
|
|
94
97
|
return template;
|
95
98
|
};
|
96
99
|
|
97
|
-
constructor(host:
|
100
|
+
constructor(host: PlayerEmbedHost) {
|
98
101
|
this.host = host;
|
99
|
-
new Task<
|
102
|
+
new Task<FetchTaskDeps, void>(
|
100
103
|
this.host,
|
101
|
-
async ([env, apiKey, data, vouchId, templateId]:
|
104
|
+
async ([env, apiKey, data, vouchId, templateId]: FetchTaskDeps) => {
|
102
105
|
try {
|
103
106
|
host.vouch = undefined;
|
104
107
|
host.template = undefined;
|
@@ -109,7 +112,7 @@ class FetcherController {
|
|
109
112
|
this.fetching = true;
|
110
113
|
template = await this.getTemplate(env, apiKey, templateId);
|
111
114
|
}
|
112
|
-
|
115
|
+
this._vouch = data;
|
113
116
|
host.template = template ?? data?.settings?.template?.instance;
|
114
117
|
} else if (vouchId) {
|
115
118
|
this.fetching = true;
|
@@ -118,7 +121,7 @@ class FetcherController {
|
|
118
121
|
this.getVouch(env, apiKey, vouchId),
|
119
122
|
templateId ? this.getTemplate(env, apiKey, templateId) : null
|
120
123
|
]);
|
121
|
-
|
124
|
+
this._vouch = vouch;
|
122
125
|
host.template = template ?? vouch?.settings?.template?.instance;
|
123
126
|
}
|
124
127
|
} finally {
|
@@ -127,6 +130,22 @@ class FetcherController {
|
|
127
130
|
},
|
128
131
|
() => [host.env, host.apiKey, host.data, host.vouchId, host.templateId]
|
129
132
|
);
|
133
|
+
|
134
|
+
// This second task is to be able to filter the vouch without fetching it again if only the questions changed
|
135
|
+
new Task<FilterTaskDeps, void>(
|
136
|
+
this.host,
|
137
|
+
([vouch, questions]: FilterTaskDeps) => {
|
138
|
+
host.vouch = vouch
|
139
|
+
? {
|
140
|
+
...vouch,
|
141
|
+
questions: {
|
142
|
+
items: vouch?.questions.items.filter((_, index) => !questions?.length || questions?.includes(index + 1))
|
143
|
+
}
|
144
|
+
}
|
145
|
+
: undefined;
|
146
|
+
},
|
147
|
+
() => [this._vouch, host.questions]
|
148
|
+
);
|
130
149
|
}
|
131
150
|
}
|
132
151
|
|