replies.php
103 lines
| 1 | <?php |
| 2 | /** |
| 3 | * QnA replies list template. |
| 4 | * |
| 5 | * @package Tutor\Templates |
| 6 | * @subpackage Dashboard |
| 7 | * @author Themeum <support@themeum.com> |
| 8 | * @link https://themeum.com |
| 9 | * @since 4.0.0 |
| 10 | */ |
| 11 | |
| 12 | defined( 'ABSPATH' ) || exit; |
| 13 | |
| 14 | use Tutor\Components\Avatar; |
| 15 | use Tutor\Components\Constants\Size; |
| 16 | use Tutor\Components\Sorting; |
| 17 | use TUTOR\Icon; |
| 18 | use Tutor\Components\SvgIcon; |
| 19 | use Tutor\Components\Constants\Color; |
| 20 | |
| 21 | ?> |
| 22 | <?php if ( ! empty( $replies ) ) : ?> |
| 23 | <div class="tutor-flex tutor-items-center tutor-justify-between tutor-px-6 tutor-py-5 tutor-border-t" :class="{ 'tutor-loading-spinner': loadingReplies }"> |
| 24 | <div class="tutor-small tutor-text-secondary"> |
| 25 | <?php esc_html_e( 'Replies', 'tutor' ); ?> |
| 26 | <span class="tutor-text-primary tutor-font-medium">(<?php echo (int) count( $replies ); ?>)</span> |
| 27 | </div> |
| 28 | <?php |
| 29 | Sorting::make() |
| 30 | ->order( $replies_order ) |
| 31 | // ->on_change( 'reloadReplies' ) |
| 32 | // ->bind_active_order( 'repliesOrder' ) |
| 33 | ->render(); |
| 34 | ?> |
| 35 | </div> |
| 36 | |
| 37 | <div class="tutor-discussion-single-reply-list tutor-border-t"> |
| 38 | <?php foreach ( $replies as $reply ) : ?> |
| 39 | <div class="tutor-discussion-reply-list-item"> |
| 40 | <div class="tutor-flex tutor-gap-5 tutor-w-full" x-show="editingId !== <?php echo (int) $reply->comment_ID; ?>"> |
| 41 | <?php Avatar::make()->user( $reply->user_id )->size( Size::SIZE_40 )->render(); ?> |
| 42 | <div class="tutor-flex-1"> |
| 43 | <div class="tutor-flex tutor-items-center tutor-gap-5 tutor-mb-2 tutor-small"> |
| 44 | <span class="tutor-discussion-card-author"> |
| 45 | <?php echo esc_html( $reply->comment_author ); ?> |
| 46 | </span> |
| 47 | <span class="tutor-text-secondary"> |
| 48 | <?php |
| 49 | /* translators: %s human-readable time difference. */ |
| 50 | echo esc_html( sprintf( __( '%s ago', 'tutor' ), human_time_diff( strtotime( $reply->comment_date_gmt ) ) ) ); |
| 51 | ?> |
| 52 | </span> |
| 53 | </div> |
| 54 | <div class="tutor-p2 tutor-text-secondary" id="tutor-qna-text-<?php echo (int) $reply->comment_ID; ?>"> |
| 55 | <?php echo wp_kses_post( $reply->comment_content ); ?> |
| 56 | </div> |
| 57 | </div> |
| 58 | <?php if ( $user_id === (int) $reply->user_id ) : ?> |
| 59 | <div x-data="tutorPopover({ placement: 'bottom-end' })" class="tutor-ml-auto"> |
| 60 | <button x-ref="trigger" @click="toggle()" class="tutor-btn tutor-btn-ghost tutor-btn-x-small tutor-btn-icon"> |
| 61 | <?php SvgIcon::make()->name( Icon::ELLIPSES )->size( 16 )->color( Color::SECONDARY )->render(); ?> |
| 62 | </button> |
| 63 | <div x-ref="content" x-show="open" x-cloak @click.outside="handleClickOutside()" class="tutor-popover"> |
| 64 | <div class="tutor-popover-menu" style="min-width: 110px;"> |
| 65 | <button class="tutor-popover-menu-item tutor-gap-5" @click="setEditing(<?php echo (int) $reply->comment_ID; ?>); hide()"> |
| 66 | <?php SvgIcon::make()->name( Icon::EDIT_2 )->size( 20 )->render(); ?> |
| 67 | <?php esc_html_e( 'Edit', 'tutor' ); ?> |
| 68 | </button> |
| 69 | <button |
| 70 | class="tutor-popover-menu-item tutor-gap-5" |
| 71 | @click="TutorCore.modal.showModal('tutor-qna-delete-modal', { question_id: <?php echo esc_html( $reply->comment_ID ); ?>, context: 'reply' }); hide()"> |
| 72 | <?php SvgIcon::make()->name( Icon::DELETE_2 )->size( 20 )->render(); ?> |
| 73 | <?php esc_html_e( 'Delete', 'tutor' ); ?> |
| 74 | </button> |
| 75 | </div> |
| 76 | </div> |
| 77 | </div> |
| 78 | <?php endif; ?> |
| 79 | </div> |
| 80 | |
| 81 | <?php if ( $user_id === (int) $reply->user_id ) : ?> |
| 82 | <div x-show="editingId === <?php echo (int) $reply->comment_ID; ?>" x-cloak class="tutor-mt-5 tutor-w-full"> |
| 83 | <?php |
| 84 | tutor_load_template( |
| 85 | 'learning-area.subpages.qna.form', |
| 86 | array( |
| 87 | 'form_id' => 'qna-edit-' . (int) $reply->comment_ID, |
| 88 | 'default_value' => $reply->comment_content, |
| 89 | 'submit_handler' => '(data) => updateQnAMutation?.mutate({ ...data, question_id: ' . (int) $reply->comment_ID . ' })', |
| 90 | 'cancel_handler' => 'setEditing(null)', |
| 91 | 'is_pending' => 'updateQnAMutation?.isPending', |
| 92 | 'placeholder' => __( 'Write your answer', 'tutor' ), |
| 93 | 'keep_footer_visible' => true, |
| 94 | ) |
| 95 | ); |
| 96 | ?> |
| 97 | </div> |
| 98 | <?php endif; ?> |
| 99 | </div> |
| 100 | <?php endforeach; ?> |
| 101 | </div> |
| 102 | <?php endif; ?> |
| 103 |