logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

emoji_editing_popover.vue (6033B)


  1. <template>
  2. <Popover
  3. ref="emojiPopover"
  4. trigger="click"
  5. :placement="placement"
  6. bound-to-selector=".emoji-list"
  7. popover-class="emoji-tab-edit-popover popover-default"
  8. :bound-to="{ x: 'container' }"
  9. :offset="{ y: 5 }"
  10. :disabled="disabled"
  11. :class="{'emoji-unsaved': isEdited}"
  12. >
  13. <template #trigger>
  14. <slot name="trigger" />
  15. </template>
  16. <template #content>
  17. <h3>
  18. {{ title }}
  19. </h3>
  20. <StillImage
  21. v-if="emojiPreview"
  22. class="emoji"
  23. :src="emojiPreview"
  24. />
  25. <div
  26. v-else
  27. class="emoji"
  28. />
  29. <div
  30. v-if="newUpload"
  31. class="emoji-tab-popover-input"
  32. >
  33. <input
  34. type="file"
  35. accept="image/*"
  36. class="emoji-tab-popover-file input"
  37. @change="uploadFile = $event.target.files"
  38. >
  39. </div>
  40. <div>
  41. <div class="emoji-tab-popover-input">
  42. <label>
  43. {{ $t('admin_dash.emoji.shortcode') }}
  44. <input
  45. v-model="editedShortcode"
  46. class="emoji-data-input input"
  47. :placeholder="$t('admin_dash.emoji.new_shortcode')"
  48. >
  49. </label>
  50. </div>
  51. <div class="emoji-tab-popover-input">
  52. <label>
  53. {{ $t('admin_dash.emoji.filename') }}
  54. <input
  55. v-model="editedFile"
  56. class="emoji-data-input input"
  57. :placeholder="$t('admin_dash.emoji.new_filename')"
  58. >
  59. </label>
  60. </div>
  61. <button
  62. class="button button-default btn"
  63. type="button"
  64. :disabled="newUpload ? uploadFile.length == 0 : !isEdited"
  65. @click="newUpload ? uploadEmoji() : saveEditedEmoji()"
  66. >
  67. {{ $t('admin_dash.emoji.save') }}
  68. </button>
  69. <template v-if="!newUpload">
  70. <button
  71. class="button button-default btn emoji-tab-popover-button"
  72. type="button"
  73. @click="deleteModalVisible = true"
  74. >
  75. {{ $t('admin_dash.emoji.delete') }}
  76. </button>
  77. <button
  78. class="button button-default btn emoji-tab-popover-button"
  79. type="button"
  80. @click="revertEmoji"
  81. >
  82. {{ $t('admin_dash.emoji.revert') }}
  83. </button>
  84. <ConfirmModal
  85. v-if="deleteModalVisible"
  86. :title="$t('admin_dash.emoji.delete_title')"
  87. :cancel-text="$t('status.delete_confirm_cancel_button')"
  88. :confirm-text="$t('status.delete_confirm_accept_button')"
  89. @cancelled="deleteModalVisible = false"
  90. @accepted="deleteEmoji"
  91. >
  92. {{ $t('admin_dash.emoji.delete_confirm', [shortcode]) }}
  93. </ConfirmModal>
  94. </template>
  95. </div>
  96. </template>
  97. </Popover>
  98. </template>
  99. <script>
  100. import Popover from 'components/popover/popover.vue'
  101. import ConfirmModal from 'components/confirm_modal/confirm_modal.vue'
  102. import StillImage from 'components/still-image/still-image.vue'
  103. export default {
  104. components: { Popover, ConfirmModal, StillImage },
  105. inject: ['emojiAddr'],
  106. props: {
  107. placement: String,
  108. disabled: {
  109. type: Boolean,
  110. default: false
  111. },
  112. newUpload: Boolean,
  113. title: String,
  114. packName: String,
  115. shortcode: {
  116. type: String,
  117. // Only exists when this is not a new upload
  118. default: ''
  119. },
  120. file: {
  121. type: String,
  122. // Only exists when this is not a new upload
  123. default: ''
  124. }
  125. },
  126. emits: ['updatePackFiles', 'displayError'],
  127. data () {
  128. return {
  129. uploadFile: [],
  130. editedShortcode: this.shortcode,
  131. editedFile: this.file,
  132. deleteModalVisible: false
  133. }
  134. },
  135. computed: {
  136. emojiPreview () {
  137. if (this.newUpload && this.uploadFile.length > 0) {
  138. return URL.createObjectURL(this.uploadFile[0])
  139. } else if (!this.newUpload) {
  140. return this.emojiAddr(this.file)
  141. }
  142. return null
  143. },
  144. isEdited () {
  145. return !this.newUpload && (this.editedShortcode !== this.shortcode || this.editedFile !== this.file)
  146. }
  147. },
  148. methods: {
  149. saveEditedEmoji () {
  150. if (!this.isEdited) return
  151. this.$store.state.api.backendInteractor.updateEmojiFile(
  152. { packName: this.packName, shortcode: this.shortcode, newShortcode: this.editedShortcode, newFilename: this.editedFile, force: false }
  153. ).then(resp => {
  154. if (resp.error !== undefined) {
  155. this.$emit('displayError', resp.error)
  156. return Promise.reject(resp.error)
  157. }
  158. return resp.json()
  159. }).then(resp => this.$emit('updatePackFiles', resp))
  160. },
  161. uploadEmoji () {
  162. this.$store.state.api.backendInteractor.addNewEmojiFile({
  163. packName: this.packName,
  164. file: this.uploadFile[0],
  165. shortcode: this.editedShortcode,
  166. filename: this.editedFile
  167. }).then(resp => resp.json()).then(resp => {
  168. if (resp.error !== undefined) {
  169. this.$emit('displayError', resp.error)
  170. return
  171. }
  172. this.$emit('updatePackFiles', resp)
  173. this.$refs.emojiPopover.hidePopover()
  174. this.editedFile = ''
  175. this.editedShortcode = ''
  176. this.uploadFile = []
  177. })
  178. },
  179. revertEmoji () {
  180. this.editedFile = this.file
  181. this.editedShortcode = this.shortcode
  182. },
  183. deleteEmoji () {
  184. this.deleteModalVisible = false
  185. this.$store.state.api.backendInteractor.deleteEmojiFile(
  186. { packName: this.packName, shortcode: this.shortcode }
  187. ).then(resp => resp.json()).then(resp => {
  188. if (resp.error !== undefined) {
  189. this.$emit('displayError', resp.error)
  190. return
  191. }
  192. this.$emit('updatePackFiles', resp)
  193. })
  194. }
  195. }
  196. }
  197. </script>
  198. <style lang="scss">
  199. .emoji-tab-edit-popover {
  200. padding-left: 0.5em;
  201. padding-right: 0.5em;
  202. padding-bottom: 0.5em;
  203. .emoji {
  204. width: 32px;
  205. height: 32px;
  206. }
  207. }
  208. </style>