@@ -69,55 +69,6 @@ async function setOrder({state, data: {order}, options, api, dispatchAction}: {s
6969 }
7070}
7171
72- async function loadMoreReplies ( { state, api, data : { comment, limit} , isReply} : { state : EditableAppContext , api : GhostApi , data : { comment : Comment , limit ?: number | 'all' } , isReply : boolean } ) : Promise < Partial < EditableAppContext > > {
73- const fetchReplies = async ( afterReplyId : string | undefined , requestLimit : number ) => {
74- if ( state . admin && state . adminApi && ! isReply ) { // we don't want the admin api to load reply data for replying to a reply, so we pass isReply: true
75- return await state . adminApi . replies ( { commentId : comment . id , afterReplyId, limit : requestLimit , memberUuid : state . member ?. uuid } ) ;
76- } else {
77- return await api . comments . replies ( { commentId : comment . id , afterReplyId, limit : requestLimit } ) ;
78- }
79- } ;
80-
81- let afterReplyId : string | undefined = comment . replies && comment . replies . length > 0
82- ? comment . replies [ comment . replies . length - 1 ] ?. id
83- : undefined ;
84-
85- let allComments : Comment [ ] = [ ] ;
86-
87- if ( limit === 'all' ) {
88- let hasMore = true ;
89-
90- while ( hasMore ) {
91- const data = await fetchReplies ( afterReplyId , 100 ) ;
92- allComments . push ( ...data . comments ) ;
93- hasMore = ! ! data . meta ?. pagination ?. next ;
94-
95- if ( data . comments && data . comments . length > 0 ) {
96- afterReplyId = data . comments [ data . comments . length - 1 ] ?. id ;
97- } else {
98- // If no comments returned, stop pagination to prevent infinite loop
99- hasMore = false ;
100- }
101- }
102- } else {
103- const data = await fetchReplies ( afterReplyId , limit as number || 100 ) ;
104- allComments = data . comments ;
105- }
106-
107- // Note: we store the comments from new to old, and show them in reverse order
108- return {
109- comments : state . comments . map ( ( c ) => {
110- if ( c . id === comment . id ) {
111- return {
112- ...comment ,
113- replies : [ ...comment . replies , ...allComments ]
114- } ;
115- }
116- return c ;
117- } )
118- } ;
119- }
120-
12172async function addComment ( { state, api, data : comment } : { state : EditableAppContext , api : GhostApi , data : AddComment } ) {
12273 const data = await api . comments . add ( { comment} ) ;
12374 const newComment = data . comments [ 0 ] ;
@@ -699,27 +650,7 @@ function closePopup() {
699650 } ;
700651}
701652
702- async function openCommentForm ( { data : newForm , api, state} : { data : OpenCommentForm , api : GhostApi , state : EditableAppContext } ) {
703- let otherStateChanges = { } ;
704-
705- // When opening a reply form, load all replies for the parent comment so the
706- // reply appears in the correct position after posting
707- const topLevelCommentId = newForm . parent_id || newForm . id ;
708- if ( newForm . type === 'reply' && ! state . openCommentForms . some ( f => f . id === topLevelCommentId || f . parent_id === topLevelCommentId ) ) {
709- const comment = state . comments . find ( c => c . id === topLevelCommentId ) ;
710-
711- if ( comment ) {
712- try {
713- const newCommentsState = await loadMoreReplies ( { state, api, data : { comment, limit : 'all' } , isReply : true } ) ;
714- otherStateChanges = { ...otherStateChanges , ...newCommentsState } ;
715- } catch ( e ) {
716- // If loading replies fails, continue anyway - the form should still open
717- // and replies will be loaded when the user submits
718- console . error ( '[Comments] Failed to load replies before opening form:' , e ) ; // eslint-disable-line no-console
719- }
720- }
721- }
722-
653+ function openCommentForm ( { data : newForm , state} : { data : OpenCommentForm , state : EditableAppContext } ) {
723654 // We want to keep the number of displayed forms to a minimum so when opening a
724655 // new form, we close any existing forms that are empty or have had no changes
725656 const openFormsAfterAutoclose = state . openCommentForms . filter ( form => form . hasUnsavedChanges ) ;
@@ -729,9 +660,9 @@ async function openCommentForm({data: newForm, api, state}: {data: OpenCommentFo
729660 const openFormIndexForId = openFormsAfterAutoclose . findIndex ( form => form . id === newForm . id ) ;
730661 if ( openFormIndexForId > - 1 ) {
731662 openFormsAfterAutoclose [ openFormIndexForId ] = newForm ;
732- return { openCommentForms : openFormsAfterAutoclose , ... otherStateChanges } ;
663+ return { openCommentForms : openFormsAfterAutoclose } ;
733664 } else {
734- return { openCommentForms : [ ...openFormsAfterAutoclose , newForm ] , ... otherStateChanges } ;
665+ return { openCommentForms : [ ...openFormsAfterAutoclose , newForm ] } ;
735666 }
736667}
737668
@@ -809,7 +740,6 @@ export const Actions = {
809740 reportComment,
810741 addReply,
811742 loadMoreComments,
812- loadMoreReplies,
813743 openCommentForm,
814744 updateMember,
815745 setOrder,
0 commit comments