You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SetStatusModal.vue 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <!--
  2. - @copyright Copyright (c) 2020 Georg Ehrke <oc.list@georgehrke.com>
  3. - @author Georg Ehrke <oc.list@georgehrke.com>
  4. -
  5. - @license GNU AGPL version 3 or any later version
  6. -
  7. - This program is free software: you can redistribute it and/or modify
  8. - it under the terms of the GNU Affero General Public License as
  9. - published by the Free Software Foundation, either version 3 of the
  10. - License, or (at your option) any later version.
  11. -
  12. - This program is distributed in the hope that it will be useful,
  13. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. - GNU Affero General Public License for more details.
  16. -
  17. - You should have received a copy of the GNU Affero General Public License
  18. - along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. -
  20. -->
  21. <template>
  22. <Modal
  23. size="normal"
  24. :title="$t('user_status', 'Set a custom status')"
  25. @close="closeModal">
  26. <div class="set-status-modal">
  27. <div class="set-status-modal__header">
  28. <h3>{{ $t('user_status', 'Set a custom status') }}</h3>
  29. </div>
  30. <div class="set-status-modal__custom-input">
  31. <EmojiPicker @select="setIcon">
  32. <button
  33. class="custom-input__emoji-button">
  34. {{ visibleIcon }}
  35. </button>
  36. </EmojiPicker>
  37. <CustomMessageInput
  38. :message="message"
  39. @change="setMessage" />
  40. </div>
  41. <PredefinedStatusesList
  42. @selectStatus="selectPredefinedMessage" />
  43. <ClearAtSelect
  44. :clear-at="clearAt"
  45. @selectClearAt="setClearAt" />
  46. <div class="status-buttons">
  47. <button class="status-buttons__select" @click="clearStatus">
  48. {{ $t('user_status', 'Clear custom status') }}
  49. </button>
  50. <button class="status-buttons__primary primary" @click="saveStatus">
  51. {{ $t('user_status', 'Set status') }}
  52. </button>
  53. </div>
  54. </div>
  55. </Modal>
  56. </template>
  57. <script>
  58. import EmojiPicker from '@nextcloud/vue/dist/Components/EmojiPicker'
  59. import Modal from '@nextcloud/vue/dist/Components/Modal'
  60. import PredefinedStatusesList from './PredefinedStatusesList'
  61. import CustomMessageInput from './CustomMessageInput'
  62. import ClearAtSelect from './ClearAtSelect'
  63. import { showError } from '@nextcloud/dialogs'
  64. export default {
  65. name: 'SetStatusModal',
  66. components: {
  67. EmojiPicker,
  68. Modal,
  69. CustomMessageInput,
  70. PredefinedStatusesList,
  71. ClearAtSelect,
  72. },
  73. data() {
  74. return {
  75. icon: null,
  76. message: null,
  77. clearAt: null,
  78. }
  79. },
  80. computed: {
  81. /**
  82. * Returns the user-set icon or a smiley in case no icon is set
  83. *
  84. * @returns {String}
  85. */
  86. visibleIcon() {
  87. return this.icon || '😀'
  88. },
  89. },
  90. /**
  91. * Loads the current status when a user opens dialog
  92. */
  93. mounted() {
  94. this.messageId = this.$store.state.userStatus.messageId
  95. this.icon = this.$store.state.userStatus.icon
  96. this.message = this.$store.state.userStatus.message
  97. if (this.$store.state.userStatus.clearAt !== null) {
  98. this.clearAt = {
  99. type: '_time',
  100. time: this.$store.state.userStatus.clearAt,
  101. }
  102. }
  103. },
  104. methods: {
  105. /**
  106. * Closes the Set Status modal
  107. */
  108. closeModal() {
  109. this.$emit('close')
  110. },
  111. /**
  112. * Sets a new icon
  113. *
  114. * @param {String} icon The new icon
  115. */
  116. setIcon(icon) {
  117. this.messageId = null
  118. this.icon = icon
  119. },
  120. /**
  121. * Sets a new message
  122. *
  123. * @param {String} message The new message
  124. */
  125. setMessage(message) {
  126. this.messageId = null
  127. this.message = message
  128. },
  129. /**
  130. * Sets a new clearAt value
  131. *
  132. * @param {Object} clearAt The new clearAt object
  133. */
  134. setClearAt(clearAt) {
  135. this.clearAt = clearAt
  136. },
  137. /**
  138. * Sets new icon/message/clearAt based on a predefined message
  139. *
  140. * @param {Object} status The predefined status object
  141. */
  142. selectPredefinedMessage(status) {
  143. this.messageId = status.id
  144. this.clearAt = status.clearAt
  145. this.icon = status.icon
  146. this.message = status.message
  147. },
  148. /**
  149. * Saves the status and closes the
  150. *
  151. * @returns {Promise<void>}
  152. */
  153. async saveStatus() {
  154. try {
  155. this.isSavingStatus = true
  156. if (this.messageId !== null) {
  157. await this.$store.dispatch('setPredefinedMessage', {
  158. messageId: this.messageId,
  159. clearAt: this.clearAt,
  160. })
  161. } else {
  162. await this.$store.dispatch('setCustomMessage', {
  163. message: this.message,
  164. icon: this.icon,
  165. clearAt: this.clearAt,
  166. })
  167. }
  168. } catch (err) {
  169. showError(this.$t('user_status', 'There was an error saving the status'))
  170. console.debug(err)
  171. this.isSavingStatus = false
  172. return
  173. }
  174. this.isSavingStatus = false
  175. this.closeModal()
  176. },
  177. /**
  178. *
  179. * @returns {Promise<void>}
  180. */
  181. async clearStatus() {
  182. try {
  183. this.isSavingStatus = true
  184. await this.$store.dispatch('clearMessage')
  185. } catch (err) {
  186. showError(this.$t('user_status', 'There was an error clearing the status'))
  187. console.debug(err)
  188. this.isSavingStatus = false
  189. return
  190. }
  191. this.isSavingStatus = false
  192. this.closeModal()
  193. },
  194. },
  195. }
  196. </script>
  197. <style lang="scss" scoped>
  198. .set-status-modal {
  199. min-width: 500px;
  200. min-height: 200px;
  201. padding: 8px 20px 20px 20px;
  202. &__custom-input {
  203. display: flex;
  204. width: 100%;
  205. margin-bottom: 10px;
  206. .custom-input__emoji-button {
  207. flex-basis: 40px;
  208. width: 40px;
  209. flex-grow: 0;
  210. border-radius: var(--border-radius) 0 0 var(--border-radius);
  211. height: 34px;
  212. margin-right: 0;
  213. border-right: none;
  214. }
  215. }
  216. .status-buttons {
  217. display: flex;
  218. button {
  219. flex-basis: 50%;
  220. }
  221. }
  222. }
  223. </style>