logo

pleroma-fe

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

emoji_editing_popover.vue (6159B)


  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: {
  108. type: String,
  109. required: true
  110. },
  111. disabled: {
  112. type: Boolean,
  113. default: false
  114. },
  115. newUpload: Boolean,
  116. title: {
  117. type: String,
  118. required: true
  119. },
  120. packName: {
  121. type: String,
  122. required: true
  123. },
  124. shortcode: {
  125. type: String,
  126. // Only exists when this is not a new upload
  127. default: ''
  128. },
  129. file: {
  130. type: String,
  131. // Only exists when this is not a new upload
  132. default: ''
  133. }
  134. },
  135. emits: ['updatePackFiles', 'displayError'],
  136. data () {
  137. return {
  138. uploadFile: [],
  139. editedShortcode: this.shortcode,
  140. editedFile: this.file,
  141. deleteModalVisible: false
  142. }
  143. },
  144. computed: {
  145. emojiPreview () {
  146. if (this.newUpload && this.uploadFile.length > 0) {
  147. return URL.createObjectURL(this.uploadFile[0])
  148. } else if (!this.newUpload) {
  149. return this.emojiAddr(this.file)
  150. }
  151. return null
  152. },
  153. isEdited () {
  154. return !this.newUpload && (this.editedShortcode !== this.shortcode || this.editedFile !== this.file)
  155. }
  156. },
  157. methods: {
  158. saveEditedEmoji () {
  159. if (!this.isEdited) return
  160. this.$store.state.api.backendInteractor.updateEmojiFile(
  161. { packName: this.packName, shortcode: this.shortcode, newShortcode: this.editedShortcode, newFilename: this.editedFile, force: false }
  162. ).then(resp => {
  163. if (resp.error !== undefined) {
  164. this.$emit('displayError', resp.error)
  165. return Promise.reject(resp.error)
  166. }
  167. return resp.json()
  168. }).then(resp => this.$emit('updatePackFiles', resp))
  169. },
  170. uploadEmoji () {
  171. this.$store.state.api.backendInteractor.addNewEmojiFile({
  172. packName: this.packName,
  173. file: this.uploadFile[0],
  174. shortcode: this.editedShortcode,
  175. filename: this.editedFile
  176. }).then(resp => resp.json()).then(resp => {
  177. if (resp.error !== undefined) {
  178. this.$emit('displayError', resp.error)
  179. return
  180. }
  181. this.$emit('updatePackFiles', resp)
  182. this.$refs.emojiPopover.hidePopover()
  183. this.editedFile = ''
  184. this.editedShortcode = ''
  185. this.uploadFile = []
  186. })
  187. },
  188. revertEmoji () {
  189. this.editedFile = this.file
  190. this.editedShortcode = this.shortcode
  191. },
  192. deleteEmoji () {
  193. this.deleteModalVisible = false
  194. this.$store.state.api.backendInteractor.deleteEmojiFile(
  195. { packName: this.packName, shortcode: this.shortcode }
  196. ).then(resp => resp.json()).then(resp => {
  197. if (resp.error !== undefined) {
  198. this.$emit('displayError', resp.error)
  199. return
  200. }
  201. this.$emit('updatePackFiles', resp)
  202. })
  203. }
  204. }
  205. }
  206. </script>
  207. <style lang="scss">
  208. .emoji-tab-edit-popover {
  209. padding-left: 0.5em;
  210. padding-right: 0.5em;
  211. padding-bottom: 0.5em;
  212. .emoji {
  213. width: 32px;
  214. height: 32px;
  215. }
  216. }
  217. </style>