@@ -61,6 +61,7 @@ import DeleteTagModal from './DeleteTagModal.vue'
6161import TagItem from ' ./TagItem.vue'
6262import logger from ' ../logger.js'
6363import useMainStore from ' ../store/mainStore.js'
64+ import { validateTag } from ' ../util/tag.js'
6465import { hiddenTags } from ' ./tags.js'
6566
6667function randomColor () {
@@ -99,8 +100,6 @@ export default {
99100 tagLabel: true ,
100101 tagInput: false ,
101102 showSaving: false ,
102- renameTagLabel: true ,
103- renameTagInput: false ,
104103 deleteTagModal: false ,
105104 tagToDelete: null ,
106105 color: randomColor (),
@@ -161,19 +160,13 @@ export default {
161160 return
162161 }
163162
164- const displayName = event .target .querySelector (' input[type=text]' ).value
165- if (displayName .toLowerCase () in hiddenTags) {
166- showError (this .t (' mail' , ' Tag name is a hidden system tag' ))
167- return
168- }
169- if (this .mainStore .getTags .some ((tag ) => tag .displayName === displayName)) {
170- showError (this .t (' mail' , ' Tag already exists' ))
171- return
172- }
173- if (displayName .trim () === ' ' ) {
174- showError (this .t (' mail' , ' Tag name cannot be empty' ))
163+ const displayName = event .target .querySelector (' input[type=text]' ).value .trim ()
164+ const valid = validateTag (null , displayName)
165+ if (valid !== true ) {
166+ showError (valid)
175167 return
176168 }
169+
177170 try {
178171 await this .mainStore .createTag ({
179172 displayName,
@@ -188,49 +181,6 @@ export default {
188181 }
189182 },
190183
191- convertHex (color , opacity ) {
192- if (color .length === 4 ) {
193- const r = parseInt (color .substring (1 , 2 ), 16 )
194- const g = parseInt (color .substring (2 , 3 ), 16 )
195- const b = parseInt (color .substring (3 , 4 ), 16 )
196- return ` rgba(${ r} , ${ g} , ${ b} , ${ opacity} )`
197- } else {
198- const r = parseInt (color .substring (1 , 3 ), 16 )
199- const g = parseInt (color .substring (3 , 5 ), 16 )
200- const b = parseInt (color .substring (5 , 7 ), 16 )
201- return ` rgba(${ r} , ${ g} , ${ b} , ${ opacity} )`
202- }
203- },
204-
205- openEditTag () {
206- this .renameTagLabel = false
207- this .renameTagInput = true
208- this .showSaving = false
209- },
210-
211- async renameTag (tag , event ) {
212- this .renameTagInput = false
213- this .showSaving = false
214- const displayName = event .target .querySelector (' input[type=text]' ).value
215-
216- try {
217- await this .mainStore .updateTag ({
218- tag,
219- displayName,
220- color: tag .color ,
221- })
222- this .renameTagLabel = true
223- this .renameTagInput = false
224- this .showSaving = false
225- } catch (error) {
226- showInfo (t (' mail' , ' An error occurred, unable to rename the tag.' ))
227- logger .error (' could not rename tag' , { error })
228- this .renameTagLabel = false
229- this .renameTagInput = false
230- this .showSaving = true
231- }
232- },
233-
234184 deleteTag (tag ) {
235185 this .tagToDelete = tag
236186 this .deleteTagModal = true
0 commit comments