@@ -1389,6 +1389,7 @@ const translations = {
13891389 } ,
13901390 showAuthDialog : false ,
13911391 pendingAction : null ,
1392+ pollListNeedsRefresh : false ,
13921393 errorMessage : "" ,
13931394 successMessage : "" ,
13941395 successFeedbackTimerId : null ,
@@ -2577,6 +2578,9 @@ const translations = {
25772578 this . focusPollFormInitialField ( "create" ) ;
25782579 }
25792580 } ) ;
2581+ if ( section === "list" ) {
2582+ void this . refreshPollListOnReturnIfNeeded ( ) ;
2583+ }
25802584 } ,
25812585 resetFormValidation ( scope = "create" ) {
25822586 this . formErrors [ scope ] = { } ;
@@ -3793,6 +3797,65 @@ const translations = {
37933797 }
37943798 this . voteDraft = nextDraft ;
37953799 } ,
3800+ pollSummaryFromDetail ( poll ) {
3801+ if ( ! poll || typeof poll !== "object" ) {
3802+ return null ;
3803+ }
3804+ const options = Array . isArray ( poll . options ) ? poll . options : [ ] ;
3805+ let myVoteCount = 0 ;
3806+ for ( const option of options ) {
3807+ if ( this . normalizeVoteValue ( option && option . my_vote ) ) {
3808+ myVoteCount += 1 ;
3809+ }
3810+ }
3811+ return {
3812+ id : poll . id ,
3813+ identifier : typeof poll . identifier === "string" ? poll . identifier : "" ,
3814+ title : typeof poll . title === "string" ? poll . title : "" ,
3815+ description : typeof poll . description === "string" ? poll . description : "" ,
3816+ window_starts_at : poll . window_starts_at || "" ,
3817+ window_ends_at : poll . window_ends_at || "" ,
3818+ start_date : typeof poll . start_date === "string" ? poll . start_date : "" ,
3819+ end_date : typeof poll . end_date === "string" ? poll . end_date : "" ,
3820+ slot_minutes : Number . isInteger ( poll . slot_minutes ) ? poll . slot_minutes : 60 ,
3821+ daily_start_hour : Number . isInteger ( poll . daily_start_hour ) ? poll . daily_start_hour : 0 ,
3822+ daily_end_hour : Number . isInteger ( poll . daily_end_hour ) ? poll . daily_end_hour : 24 ,
3823+ allowed_weekdays : Array . isArray ( poll . allowed_weekdays ) ? [ ...poll . allowed_weekdays ] : [ ] ,
3824+ timezone : typeof poll . timezone === "string" ? poll . timezone : "" ,
3825+ is_closed : Boolean ( poll . is_closed ) ,
3826+ created_at : poll . created_at || "" ,
3827+ closed_at : poll . closed_at || null ,
3828+ creator : poll . creator || null ,
3829+ option_count : options . length ,
3830+ participant_count : Number . isInteger ( poll . participant_count ) ? poll . participant_count : 0 ,
3831+ my_vote_count : myVoteCount ,
3832+ can_close : Boolean ( poll . can_close ) ,
3833+ can_reopen : Boolean ( poll . can_reopen ) ,
3834+ can_delete : Boolean ( poll . can_delete ) ,
3835+ can_edit : Boolean ( poll . can_edit )
3836+ } ;
3837+ } ,
3838+ patchPollSummaryFromDetail ( poll ) {
3839+ const summary = this . pollSummaryFromDetail ( poll ) ;
3840+ if ( ! summary ) {
3841+ return ;
3842+ }
3843+ const pollId = String ( summary . id || "" ) ;
3844+ const existingIndex = this . polls . findIndex ( ( item ) => String ( item && item . id || "" ) === pollId ) ;
3845+ if ( existingIndex >= 0 ) {
3846+ const nextPolls = [ ...this . polls ] ;
3847+ nextPolls . splice ( existingIndex , 1 , summary ) ;
3848+ this . polls = nextPolls ;
3849+ return ;
3850+ }
3851+ this . polls = [ ...this . polls , summary ] ;
3852+ } ,
3853+ async refreshPollListOnReturnIfNeeded ( ) {
3854+ if ( this . activeSection !== "list" || ! this . pollListNeedsRefresh ) {
3855+ return ;
3856+ }
3857+ await this . fetchPolls ( ) ;
3858+ } ,
37963859 async waitForPendingVoteSync ( ) {
37973860 if ( ! this . selectedPoll || this . selectedPoll . is_closed ) {
37983861 return ;
@@ -3853,7 +3916,8 @@ const translations = {
38533916 this . selectedPoll = data . poll ;
38543917 this . applyVoteDraft ( { preserveLocalChanges : true } ) ;
38553918 }
3856- await this . fetchPolls ( ) ;
3919+ this . patchPollSummaryFromDetail ( data . poll ) ;
3920+ this . pollListNeedsRefresh = true ;
38573921 } catch ( error ) {
38583922 if (
38593923 generation === Number ( this . _voteSyncGeneration || 0 )
@@ -4506,6 +4570,7 @@ const translations = {
45064570 try {
45074571 const data = await apiFetch ( "/api/polls/" ) ;
45084572 this . polls = data . polls || [ ] ;
4573+ this . pollListNeedsRefresh = false ;
45094574 } catch ( error ) {
45104575 this . setError ( this . resolveError ( error . payload , "Could not load polls." ) ) ;
45114576 }
0 commit comments