Skip to content

Commit a1030fe

Browse files
authored
Merge pull request #572 from talkjs/chore/update-getting-started-data-api
Update Vue, Angular, Svelte getting started examples to use the JS Data API
2 parents e202b43 + b57f1fe commit a1030fe

File tree

9 files changed

+1555
-1551
lines changed

9 files changed

+1555
-1551
lines changed

angular/angular-getting-started/package-lock.json

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

angular/angular-getting-started/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"@angular/platform-browser-dynamic": "^18.0.0",
1919
"@angular/router": "^18.0.0",
2020
"rxjs": "~7.8.0",
21-
"talkjs": "^0.20.0",
21+
"talkjs": "^0.36.0",
2222
"tslib": "^2.3.0",
2323
"zone.js": "~0.14.3"
2424
},

angular/angular-getting-started/src/app/app.component.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Component } from "@angular/core";
2-
import { TalkjsChatComponent } from "./talkjs-chat/talkjs-chat.component";
2+
import { ChatComponent } from "./chat/chat.component";
33

44
@Component({
55
selector: "app-root",
66
standalone: true,
7-
imports: [TalkjsChatComponent],
8-
template: ` <app-talkjs-chat></app-talkjs-chat> `,
7+
imports: [ChatComponent],
8+
template: ` <app-chat></app-chat> `,
99
styles: [],
1010
})
1111
export class AppComponent {

angular/angular-getting-started/src/app/talkjs-chat/talkjs-chat.component.ts renamed to angular/angular-getting-started/src/app/chat/chat.component.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,42 @@ import { Component } from "@angular/core";
33
import Talk from "talkjs";
44

55
@Component({
6-
selector: "app-talkjs-chat",
6+
selector: "app-chat",
77
standalone: true,
88
imports: [],
99
template: `
1010
<div id="talkjs-container" style="height: 600px">Loading chats..</div>
1111
`,
1212
styles: ``,
1313
})
14-
export class TalkjsChatComponent {
14+
export class ChatComponent {
1515
constructor() {
1616
Talk.ready.then(function () {
17-
const me = new Talk.User({
18-
id: "nina",
17+
const session = new Talk.Session({
18+
appId: "<APP_ID>",
19+
userId: "nina",
20+
});
21+
session.currentUser.createIfNotExists({
1922
name: "Nina",
2023
2124
photoUrl: "https://talkjs.com/new-web/avatar-7.jpg",
2225
welcomeMessage: "Hi!",
2326
});
24-
const session = new Talk.Session({
25-
appId: "<APP_ID>",
26-
me: me,
27-
});
28-
const other = new Talk.User({
29-
id: "frank",
27+
28+
const otherRef = session.user("frank");
29+
otherRef.createIfNotExists({
3030
name: "Frank",
3131
3232
photoUrl: "https://talkjs.com/new-web/avatar-8.jpg",
3333
welcomeMessage: "Hey, how can I help?",
3434
});
3535

36-
const conversation = session.getOrCreateConversation("new_conversation");
37-
conversation.setParticipant(me);
38-
conversation.setParticipant(other);
36+
const conversationRef = session.conversation("new_conversation");
37+
conversationRef.createIfNotExists();
38+
conversationRef.participant(otherRef).createIfNotExists();
3939

4040
const chatbox = session.createChatbox();
41-
chatbox.select(conversation);
41+
chatbox.select(conversationRef);
4242
chatbox.mount(document.getElementById("talkjs-container"));
4343
});
4444
}

svelte/svelte/src/App.svelte

+11-8
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@
77
88
onMount(async () => {
99
Talk.ready.then(() => {
10-
const me = new Talk.User(oliver);
11-
const other = new Talk.User(abby);
10+
const session = new Talk.Session({
11+
appId: appId,
12+
userId: oliver.id,
13+
});
14+
session.currentUser.createIfNotExists(oliver);
1215
13-
const session = new Talk.Session({ appId, me });
16+
const otherRef = session.user(abby.id);
17+
otherRef.createIfNotExists(abby);
1418
15-
const conversationId = Talk.oneOnOneId(me, other);
16-
const conversation = session.getOrCreateConversation(conversationId);
17-
conversation.setParticipant(me);
18-
conversation.setParticipant(other);
19+
const conversationRef = session.conversation('svelte_example_conversation');
20+
conversationRef.createIfNotExists();
21+
conversationRef.participant(otherRef).createIfNotExists();
1922
2023
const chatbox = session.createChatbox();
21-
chatbox.select(conversation);
24+
chatbox.select(conversationRef);
2225
chatbox.mount(element);
2326
});
2427
});

0 commit comments

Comments
 (0)