note_header.vue 2.6 KB
Newer Older
1
<script>
2
  import { mapActions } from 'vuex';
3
  import timeAgoTooltip from '../../vue_shared/components/time_ago_tooltip.vue';
4

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
  export default {
    props: {
      author: {
        type: Object,
        required: true,
      },
      createdAt: {
        type: String,
        required: true,
      },
      actionText: {
        type: String,
        required: false,
        default: '',
      },
      actionTextHtml: {
        type: String,
        required: false,
        default: '',
      },
      noteId: {
        type: Number,
        required: true,
      },
      includeToggle: {
        type: Boolean,
        required: false,
        default: false,
      },
34
    },
35 36 37 38
    data() {
      return {
        isExpanded: true,
      };
39
    },
40 41
    components: {
      timeAgoTooltip,
42
    },
43 44 45 46 47 48 49
    computed: {
      toggleChevronClass() {
        return this.isExpanded ? 'fa-chevron-up' : 'fa-chevron-down';
      },
      noteTimestampLink() {
        return `#note_${this.noteId}`;
      },
50
    },
51
    methods: {
52
      ...mapActions([
F
Filipa Lacerda 已提交
53
        'setTargetNoteHash',
54
      ]),
55 56
      handleToggle() {
        this.isExpanded = !this.isExpanded;
F
Filipa Lacerda 已提交
57
        this.$emit('toggleHandler');
58 59 60 61
      },
      updateTargetNoteHash() {
        this.setTargetNoteHash(this.noteTimestampLink);
      },
62
    },
63
  };
64 65 66 67 68 69 70 71 72 73 74 75 76 77
</script>

<template>
  <div class="note-header-info">
    <a :href="author.path">
      <span class="note-header-author-name">
        {{author.name}}
      </span>
      <span class="note-headline-light">
        @{{author.username}}
      </span>
    </a>
    <span class="note-headline-light">
      <span class="note-headline-meta">
78 79 80 81 82 83
        <template v-if="actionText">
          {{actionText}}
        </template>
        <span
          v-if="actionTextHtml"
          v-html="actionTextHtml"
84 85
          class="system-note-message">
        </span>
86 87
        <a
          :href="noteTimestampLink"
88 89
          @click="updateTargetNoteHash"
          class="note-timestamp">
90 91
          <time-ago-tooltip
            :time="createdAt"
92
            tooltip-placement="bottom"
93
            />
94
        </a>
95 96 97 98 99
        <i
          class="fa fa-spinner fa-spin editing-spinner"
          aria-label="Comment is being updated"
          aria-hidden="true">
        </i>
100 101 102 103 104 105
      </span>
    </span>
    <div
      v-if="includeToggle"
      class="discussion-actions">
      <button
106
        @click="handleToggle"
107
        class="note-action-button discussion-toggle-button js-vue-toggle-button"
108 109
        type="button">
          <i
110 111
            :class="toggleChevronClass"
            class="fa"
112 113
            aria-hidden="true">
          </i>
114 115 116 117 118
          Toggle discussion
      </button>
    </div>
  </div>
</template>