Fix setting a default color when none was saved

This commit is contained in:
kolaente 2021-04-18 19:16:53 +02:00
parent 7ace71ad2e
commit 603345b326
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
2 changed files with 13 additions and 9 deletions

View file

@ -77,8 +77,8 @@
done: t.done, done: t.done,
'is-current-edit': 'is-current-edit':
taskToEdit !== null && taskToEdit.id === t.id, taskToEdit !== null && taskToEdit.id === t.id,
'has-light-text': !colorIsDark(t.hexColor), 'has-light-text': !colorIsDark(t.getHexColor()),
'has-dark-text': colorIsDark(t.hexColor), 'has-dark-text': colorIsDark(t.getHexColor()),
}" }"
:gridX="dayWidth" :gridX="dayWidth"
:h="31" :h="31"
@ -89,8 +89,8 @@
:snapToGrid="true" :snapToGrid="true"
:sticks="['mr', 'ml']" :sticks="['mr', 'ml']"
:style="{ :style="{
'border-color': t.hexColor, 'border-color': t.getHexColor(),
'background-color': t.hexColor, 'background-color': t.getHexColor(),
}" }"
:w="t.durationDays * dayWidth" :w="t.durationDays * dayWidth"
:x="t.offsetDays * dayWidth - 6" :x="t.offsetDays * dayWidth - 6"

View file

@ -47,11 +47,7 @@ export default class TaskModel extends AbstractModel {
return new LabelModel(l) return new LabelModel(l)
}) })
// Set the default color if (this.hexColor !== '' && this.hexColor.substring(0, 1) !== '#') {
if (this.hexColor === '') {
this.hexColor = this.defaultColor
}
if (this.hexColor.substring(0, 1) !== '#') {
this.hexColor = '#' + this.hexColor this.hexColor = '#' + this.hexColor
} }
@ -124,6 +120,14 @@ export default class TaskModel extends AbstractModel {
return this.identifier return this.identifier
} }
getHexColor() {
if (this.hexColor === '') {
return `#${this.defaultColor}`
}
return this.hexColor
}
///////////////// /////////////////
// Helper functions // Helper functions
/////////////// ///////////////