|
9 | 9 | * @since 4.0.0 |
10 | 10 | */ |
11 | 11 |
|
12 | | -use Tutor\Components\Sorting; |
13 | | -use TUTOR\Input; |
14 | | -use TUTOR\Lesson; |
| 12 | +use Tutor\Components\Avatar; |
| 13 | +use Tutor\Components\Button; |
| 14 | +use Tutor\Components\Constants\InputType; |
| 15 | +use Tutor\Components\Constants\Size; |
| 16 | +use Tutor\Components\Constants\Variant; |
| 17 | +use Tutor\Components\InputField; |
| 18 | +use TUTOR\Icon; |
15 | 19 |
|
16 | 20 | defined( 'ABSPATH' ) || exit; |
17 | 21 |
|
18 | | -$item_per_page = tutor_utils()->get_option( 'pagination_per_page', 10 ); |
19 | | -$current_page = max( 1, Input::post( 'current_page', 0, Input::TYPE_INT ) ); |
20 | | -$lesson_id = Input::post( 'comment_post_ID', get_the_ID(), Input::TYPE_INT ); |
21 | | -$order_filter = Input::get( 'order' ) ?? Input::post( 'order' ) ?? 'DESC'; |
22 | | - |
23 | | -$comments_list_args = array( |
24 | | - 'post_id' => $lesson_id, |
25 | | - 'parent' => 0, |
26 | | - 'paged' => $current_page, |
27 | | - 'number' => $item_per_page, |
28 | | - 'order' => $order_filter, |
29 | | -); |
| 22 | +if ( empty( $comment_list ) ) { |
| 23 | + return; |
| 24 | +} |
| 25 | +?> |
| 26 | +<?php foreach ( $comment_list as $comment_item ) : ?> |
| 27 | + <div class="tutor-comment" x-data="{showReplyForm: false, repliesExpanded: false}"> |
| 28 | + <?php Avatar::make()->user( $comment_item->user_id )->size( Size::SIZE_40 )->render(); ?> |
| 29 | + <div class="tutor-flex-1"> |
| 30 | + <div class="tutor-flex tutor-items-center tutor-gap-5 tutor-mb-2 tutor-small"> |
| 31 | + <span class="tutor-discussion-card-author"> |
| 32 | + <?php echo esc_html( $comment_item->comment_author ); ?> |
| 33 | + </span> |
| 34 | + <span class="tutor-text-subdued"> |
| 35 | + <?php |
| 36 | + // Translators: %s is the time of comment. |
| 37 | + echo esc_html( sprintf( __( '%s ago', 'tutor' ), human_time_diff( strtotime( $comment_item->comment_date_gmt ) ) ) ); |
| 38 | + ?> |
| 39 | + </span> |
| 40 | + </div> |
| 41 | + <div class="tutor-p2 tutor-text-secondary"> |
| 42 | + <?php echo wp_kses_post( $comment_item->comment_content ); ?> |
| 43 | + </div> |
| 44 | + <div class="tutor-mt-6"> |
| 45 | + <button class="tutor-comment-action-btn tutor-comment-action-btn-reply" @click="showReplyForm = !showReplyForm"> |
| 46 | + <?php tutor_utils()->render_svg_icon( Icon::COMMENTS ); ?> |
| 47 | + <?php esc_html_e( 'Reply', 'tutor' ); ?> |
| 48 | + </button> |
| 49 | + </div> |
| 50 | + <form |
| 51 | + class="tutor-comment-reply-form tutor-mt-6" |
| 52 | + x-show="showReplyForm" |
| 53 | + x-collapse |
| 54 | + x-data="{ ...tutorForm({ id: 'lesson-comment-reply-form' }), focused: false }" |
| 55 | + x-bind="getFormBindings()" |
| 56 | + @submit.prevent="handleSubmit((data) => replyCommentMutation?.mutate({ ...data, comment_post_ID: <?php echo esc_html( $lesson_id ); ?>, comment_parent: <?php echo esc_html( $comment_item->comment_ID ); ?>, order: currentOrder }))($event)" |
| 57 | + > |
| 58 | + <?php |
| 59 | + InputField::make() |
| 60 | + ->type( InputType::TEXTAREA ) |
| 61 | + ->name( 'comment' ) |
| 62 | + ->placeholder( __( 'Write your reply', 'tutor' ) ) |
| 63 | + ->attr( 'x-bind', "register('comment', { required: '" . esc_js( __( 'Please enter a reply', 'tutor' ) ) . "' })" ) |
| 64 | + ->attr( '@focus', 'focused = true' ) |
| 65 | + ->attr( '@keydown', 'handleKeydown($event)' ) |
| 66 | + ->render(); |
| 67 | + ?> |
| 68 | + <div class="tutor-flex tutor-items-center tutor-justify-between tutor-mt-5" x-cloak :class="{ 'tutor-hidden': !focused }"> |
| 69 | + <div class="tutor-tiny tutor-text-subdued tutor-flex tutor-items-center tutor-gap-2"> |
| 70 | + <?php tutor_utils()->render_svg_icon( Icon::COMMAND, 12, 12 ); ?> |
| 71 | + <?php esc_html_e( 'Cmd/Ctrl +', 'tutor' ); ?> |
| 72 | + <?php tutor_utils()->render_svg_icon( Icon::ENTER, 12, 12 ); ?> |
| 73 | + <?php esc_html_e( 'Enter to Save ', 'tutor' ); ?> |
| 74 | + </div> |
| 75 | + <div class="tutor-flex tutor-items-center tutor-gap-4"> |
| 76 | + <?php |
| 77 | + Button::make() |
| 78 | + ->label( __( 'Cancel', 'tutor' ) ) |
| 79 | + ->variant( Variant::GHOST ) |
| 80 | + ->size( Size::X_SMALL ) |
| 81 | + ->attr( 'type', 'button' ) |
| 82 | + ->attr( '@click', 'reset(); focused = false; showReplyForm = false' ) |
| 83 | + ->attr( ':disabled', 'replyCommentMutation?.isPending' ) |
| 84 | + ->render(); |
30 | 85 |
|
31 | | -$comment_count_args = array( |
32 | | - 'post_id' => $lesson_id, |
33 | | - 'parent' => 0, |
34 | | - 'count' => true, |
35 | | -); |
| 86 | + Button::make() |
| 87 | + ->label( __( 'Save', 'tutor' ) ) |
| 88 | + ->variant( Variant::PRIMARY_SOFT ) |
| 89 | + ->size( Size::X_SMALL ) |
| 90 | + ->attr( 'type', 'submit' ) |
| 91 | + ->attr( ':disabled', 'replyCommentMutation?.isPending' ) |
| 92 | + ->attr( ':class', "{ 'tutor-btn-loading': replyCommentMutation?.isPending }" ) |
| 93 | + ->render(); |
| 94 | + ?> |
| 95 | + </div> |
| 96 | + </div> |
| 97 | + </form> |
36 | 98 |
|
37 | | -$comments_count = Lesson::get_comments( $comment_count_args ); |
38 | | -$comment_list = Lesson::get_comments( $comments_list_args ); |
39 | | -?> |
40 | | -<?php if ( ! empty( $comment_list ) ) : ?> |
41 | | -<div x-ref="commentList"> |
42 | | - <div |
43 | | - class="tutor-flex tutor-items-center tutor-justify-between tutor-px-6 tutor-py-5 tutor-border-t" |
44 | | - :class="{ 'tutor-loading-spinner': isReloading }" |
45 | | - > |
46 | | - <div class="tutor-small tutor-text-secondary"> |
47 | | - <?php esc_html_e( 'Comments', 'tutor' ); ?> |
48 | | - <span class="tutor-text-primary tutor-font-medium">(<?php echo esc_html( $comments_count ); ?>)</span> |
| 99 | + <!-- Display Comment Replies --> |
| 100 | + <?php |
| 101 | + tutor_load_template( |
| 102 | + 'learning-area.lesson.comment-replies', |
| 103 | + array( |
| 104 | + 'lesson_id' => $lesson_id, |
| 105 | + 'comment_item' => $comment_item, |
| 106 | + ) |
| 107 | + ); |
| 108 | + ?> |
49 | 109 | </div> |
50 | | - <?php |
51 | | - Sorting::make() |
52 | | - ->order( $order_filter ) |
53 | | - ->on_change( 'handleChangeOrder' ) |
54 | | - ->bind_active_order( 'currentOrder' ) |
55 | | - ->render(); |
56 | | - ?> |
57 | | - </div> |
58 | | - <div x-ref="commentItems" class="tutor-comments-list tutor-border-t"> |
59 | | - <?php tutor_load_template( 'learning-area.lesson.comment-items', compact( 'comment_list', 'lesson_id' ) ); ?> |
60 | 110 | </div> |
61 | | -</div> |
62 | | -<?php endif; ?> |
| 111 | +<?php endforeach; ?> |
0 commit comments