@@ -177,12 +177,12 @@ async function buildSubmindHTML(promptID, submindID, submindUserData, submindRes
177177 }
178178
179179 const phaseDataObjectMapping = {
180- 'response' : submindResponse ,
181- 'vote' : submindVote
180+ 'response' : submindResponse || emptyAnswer ,
181+ 'vote' : submindVote || emptyAnswer
182182 }
183183 let promptParticipantTemplate ;
184184 // Fallback to the single-discussion rounds
185- if ( ! Array . isArray ( submindOpinions ) ) {
185+ if ( ! discussionRounds || discussionRounds === 1 ) {
186186 phaseDataObjectMapping [ 'opinion' ] = submindOpinions ;
187187 promptParticipantTemplate = 'prompt_participant'
188188 } else {
@@ -213,13 +213,16 @@ async function buildSubmindHTML(promptID, submindID, submindUserData, submindRes
213213 */
214214function buildSubmindDiscussionHTML ( promptID , userNickname , submindOpinions , discussionRounds ) {
215215 let html = '' ;
216- for ( let i = 0 ; i < discussionRounds ; i ++ ) {
216+ if ( ! submindOpinions ) {
217+ submindOpinions = [ ] ;
218+ }
219+ for ( let i = 1 ; i <= discussionRounds ; i ++ ) {
217220 let opinion ;
218221 // means that discussion phases were skipped
219- if ( i > submindOpinions . length - 1 ) {
222+ if ( i > submindOpinions . length ) {
220223 opinion = { }
221224 } else {
222- opinion = submindOpinions [ i ] ;
225+ opinion = submindOpinions [ i - 1 ] ;
223226 }
224227
225228 const createdOnTS = opinion ?. created_on
@@ -243,15 +246,25 @@ function buildSubmindDiscussionHTML(promptID, userNickname, submindOpinions, dis
243246 * @param winner_response - shout of the winner
244247 */
245248async function buildPromptWinnerHTML ( nickname , winner_response ) {
246- return `
247- <div class="d-flex flex-column align-items-center justify-content-center">
248- <span class="mt-2 mb-3 font-weight-bold">Selected winner</span>
249- ${ await buildPromptParticipantIcon ( nickname ) }
250- <div style="max-width: 400px; margin-top: 20px;">
251- ${ winner_response }
252- </div>
253- </div>
254- `
249+ let html ;
250+ if ( nickname ) {
251+ html = `
252+ <div class="d-flex flex-column align-items-center justify-content-center">
253+ <span class="mt-2 mb-3 font-weight-bold">Selected winner</span>
254+ ${ await buildPromptParticipantIcon ( nickname ) }
255+ <div style="max-width: 400px; margin-top: 20px;">
256+ ${ winner_response }
257+ </div>
258+ </div>
259+ `
260+ } else {
261+ html = `
262+ <div class="d-flex flex-column align-items-center justify-content-center" style="font-weight: normal">
263+ Consensus not reached.
264+ </div>
265+ `
266+ }
267+ return html ;
255268}
256269
257270/**
@@ -369,6 +382,12 @@ async function buildPromptHTML(prompt) {
369382 promptData [ 'winner' ] = 'Consensus not reached.'
370383 }
371384
385+ let tableRowLength = 4 ;
386+
387+ if ( discussionRounds ) {
388+ tableRowLength += discussionRounds - 1 ;
389+ }
390+
372391 const discussionsHeader = ! discussionRounds
373392 ? `<th data-rtc-resizable="discussion">Discussion</th>`
374393 : Array . from ( { length : discussionRounds } , ( _ , i ) =>
@@ -381,7 +400,8 @@ async function buildPromptHTML(prompt) {
381400 'prompt_id' : prompt [ '_id' ] ,
382401 'cid' : prompt [ 'cid' ] ,
383402 'discussions_header' : discussionsHeader ,
384- 'message_time' : prompt [ 'created_on' ]
403+ 'message_time' : prompt [ 'created_on' ] ,
404+ 'tr_length' : tableRowLength
385405 } ) ;
386406}
387407
0 commit comments