11import ( '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