Skip to content

Commit bac3a5b

Browse files
committed
DOC-3246: Update interactive examples on comments-with-mentions page
1 parent 461d4e1 commit bac3a5b

File tree

2 files changed

+43
-29
lines changed
  • modules/ROOT/examples/live-demos

2 files changed

+43
-29
lines changed

modules/ROOT/examples/live-demos/comments-callback-with-mentions/index.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,6 @@ import ('https://cdn.jsdelivr.net/npm/@faker-js/faker@9/dist/index.min.js').then
320320
});
321321
setTimeout(() => done({ conversations: fetchedConversations }), fakeDelay);
322322
};
323-
324-
// Read the above `getAuthorInfo` function to see how this could be implemented
325-
const tinycomments_fetch_author_info = (done) => done(getAuthorInfo(currentUid));
326323

327324
tinymce.init({
328325
selector: 'textarea#comments-callback-with-mentions',
@@ -350,9 +347,18 @@ import ('https://cdn.jsdelivr.net/npm/@faker-js/faker@9/dist/index.min.js').then
350347
mentions_select,
351348

352349
tinycomments_mode: 'callback',
353-
tinycomments_author: currentUser.id,
354-
tinycomments_author_name: currentUser.fullName,
355-
tinycomments_avatar: currentUser.image,
350+
user_id: currentUser.id,
351+
fetch_users: (userIds) => {
352+
const results = userIds.map((id) => {
353+
const user = Object.values(userDb).find((user) => user.id === id);
354+
if (user) {
355+
return user;
356+
} else {
357+
throw new Error(`User ${id} not found`);
358+
}
359+
});
360+
return Promise.resolve(results);
361+
},
356362
tinycomments_create,
357363
tinycomments_reply,
358364
tinycomments_delete,
@@ -362,6 +368,5 @@ import ('https://cdn.jsdelivr.net/npm/@faker-js/faker@9/dist/index.min.js').then
362368
tinycomments_delete_comment,
363369
tinycomments_edit_comment,
364370
tinycomments_fetch,
365-
tinycomments_fetch_author_info
366371
});
367372
});

modules/ROOT/examples/live-demos/comments-embedded-with-mentions/index.js

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
import ('https://cdn.jsdelivr.net/npm/@faker-js/faker@9/dist/index.min.js').then(({ faker }) => {
2-
const adminUser = {
3-
id: 'johnsmith',
4-
name: 'John Smith',
5-
fullName: 'John Smith',
6-
description: 'Company Founder',
7-
image: "https://i.pravatar.cc/150?img=11"
8-
};
2+
/* This represents a database of users on the server */
3+
const userDb = {
4+
'johnsmith': {
5+
id: 'johnsmith',
6+
name: 'John Smith',
7+
fullName: 'John Smith',
8+
description: 'Company Founder',
9+
image: "https://i.pravatar.cc/150?img=11"
10+
},
11+
'jennynichols': {
12+
id: 'jennynichols',
13+
name: 'Jenny Nichols',
14+
fullName: 'Jenny Nichols',
15+
description: 'Marketing Director',
16+
image: "https://i.pravatar.cc/150?img=10"
17+
}
18+
}
919

10-
const currentUser = {
11-
id: 'jennynichols',
12-
name: 'Jenny Nichols',
13-
fullName: 'Jenny Nichols',
14-
description: 'Marketing Director',
15-
image: "https://i.pravatar.cc/150?img=10"
16-
};
20+
const adminUser = userDb['johnsmith'];
21+
const currentUser = userDb['jennynichols'];
1722

1823
const fakeDelay = 500;
1924
const numberOfUsers = 200;
@@ -32,11 +37,6 @@ import ('https://cdn.jsdelivr.net/npm/@faker-js/faker@9/dist/index.min.js').then
3237
userNames.push(`${faker.person.firstName()} ${faker.person.lastName()}`);
3338
}
3439

35-
/* This represents a database of users on the server */
36-
const userDb = {
37-
[adminUser.id]: adminUser,
38-
[currentUser.id]: currentUser
39-
};
4040
userNames.map((fullName) => {
4141
if ((fullName !== currentUser.fullName) && (fullName !== adminUser.fullName)) {
4242
const id = fullName.toLowerCase().replace(/ /g, '');
@@ -155,9 +155,18 @@ import ('https://cdn.jsdelivr.net/npm/@faker-js/faker@9/dist/index.min.js').then
155155

156156
tinycomments_mode: 'embedded',
157157
sidebar_show: 'showcomments',
158-
tinycomments_author: currentUser.id,
159-
tinycomments_author_name: currentUser.fullName,
160-
tinycomments_avatar: currentUser.image,
158+
user_id: currentUser.id,
159+
fetch_users: (userIds) => {
160+
const results = userIds.map((id) => {
161+
const user = Object.values(userDb).find((user) => user.id === id);
162+
if (user) {
163+
return user;
164+
} else {
165+
throw new Error(`User ${id} not found`);
166+
}
167+
});
168+
return Promise.resolve(results);
169+
},
161170
tinycomments_can_resolve,
162171
});
163172
});

0 commit comments

Comments
 (0)