Skip to content

Commit faff9c0

Browse files
sarupbanskotaclaude
andcommitted
feat: add second public Lobbyside widget alongside existing ones
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 31c101d commit faff9c0

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{{#if this.shouldShow}}
2+
<div {{did-insert this.insertScript}} {{will-destroy this.removeScript}}></div>
3+
{{/if}}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import Component from '@glimmer/component';
2+
import { service } from '@ember/service';
3+
import { action } from '@ember/object';
4+
import type AuthenticatorService from 'codecrafters-frontend/services/authenticator';
5+
6+
const LOBBYSIDE_SCRIPT_ID = 'lobbyside-secondary-widget-script';
7+
8+
export default class LobbysideSecondaryWidgetComponent extends Component {
9+
@service declare authenticator: AuthenticatorService;
10+
11+
get shouldShow(): boolean {
12+
return true;
13+
}
14+
15+
@action
16+
insertScript(): void {
17+
if (document.getElementById(LOBBYSIDE_SCRIPT_ID)) {
18+
this.syncVisitorData();
19+
20+
return;
21+
}
22+
23+
const script = document.createElement('script');
24+
script.id = LOBBYSIDE_SCRIPT_ID;
25+
script.src = 'https://lobbyside.com/widget.js';
26+
script.dataset['widgetId'] = 'b0d7150e-77e2-431c-a57c-765e080d9c72';
27+
script.onload = () => this.syncVisitorData();
28+
document.body.appendChild(script);
29+
}
30+
31+
@action
32+
removeScript(): void {
33+
const script = document.getElementById(LOBBYSIDE_SCRIPT_ID);
34+
35+
if (script) {
36+
script.remove();
37+
}
38+
}
39+
40+
private syncVisitorData(): void {
41+
const user = this.authenticator.currentUser;
42+
43+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
44+
if (!user || !(window as any)['Lobbyside']) {
45+
return;
46+
}
47+
48+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
49+
const lobbyside = (window as any).Lobbyside;
50+
51+
lobbyside.setVisitor({
52+
email: user.primaryEmailAddress || '',
53+
name: user.name || user.githubName || '',
54+
github: user.githubUsername || '',
55+
});
56+
}
57+
}

app/templates/application.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
{{/if}}
2424

2525
<LobbysideWidget />
26+
<LobbysideSecondaryWidget />
2627
<LobbysideStaffWidget />
2728

2829
{{! Enable this to debug ember-animated animations }}

0 commit comments

Comments
 (0)