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
  export default {
F
Filipa Lacerda 已提交
6 7 8
    components: {
      timeAgoTooltip,
    },
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 34 35 36
    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,
      },
37 38 39 40 41
      expanded: {
        type: Boolean,
        required: false,
        default: true,
      },
42
    },
43 44
    computed: {
      toggleChevronClass() {
45
        return this.expanded ? 'fa-chevron-up' : 'fa-chevron-down';
46 47 48 49
      },
      noteTimestampLink() {
        return `#note_${this.noteId}`;
      },
50
    },
51
    methods: {
52
      ...mapActions([
F
Filipa Lacerda 已提交
53
        'setTargetNoteHash',
54
      ]),
55
      handleToggle() {
F
Filipa Lacerda 已提交
56
        this.$emit('toggleHandler');
57 58 59 60
      },
      updateTargetNoteHash() {
        this.setTargetNoteHash(this.noteTimestampLink);
      },
61
    },
62
  };
63 64 65 66 67
</script>

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