feat(task wizard): visually show parsed labels from quick add

This commit is contained in:
kolaente 2022-09-22 18:53:46 +02:00
parent a712c2b514
commit 070b629fb6
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B

View file

@ -39,6 +39,14 @@
{{ date ? formatDateShort(date) : t('task.attributes.dueDate') }} {{ date ? formatDateShort(date) : t('task.attributes.dueDate') }}
</XButton> </XButton>
</Datepicker> </Datepicker>
<div>
<span
v-for="label in realLabels"
:style="{'background': label.hexColor, 'color': label.textColor}"
class="tag mr-2">
<span>{{ label.title }}</span>
</span>
</div>
</div> </div>
</CreateEdit> </CreateEdit>
</template> </template>
@ -64,8 +72,14 @@ import {getQuickAddMagicMode} from '@/helpers/quickAddMagicMode'
import {parseTaskText} from '@/modules/parseTaskText' import {parseTaskText} from '@/modules/parseTaskText'
import {findAssignees} from '@/helpers/findAssignees' import {findAssignees} from '@/helpers/findAssignees'
import {formatDateShort} from '@/helpers/time/formatDate' import {formatDateShort} from '@/helpers/time/formatDate'
import {useLabelStore} from '@/stores/labels'
import {useStore} from '@/store'
import type {ILabel} from '@/modelTypes/ILabel'
import LabelModel from '@/models/label'
const listStore = useListStore() const listStore = useListStore()
const labelStore = useLabelStore()
const store = useStore()
const router = useRouter() const router = useRouter()
const {t} = useI18n() const {t} = useI18n()
const props = defineProps<{ const props = defineProps<{
@ -87,9 +101,27 @@ const newTask = ref<ITask>(new TaskModel({}))
const parsedTask = computed(() => parseTaskText(newTask.value.title, getQuickAddMagicMode())) const parsedTask = computed(() => parseTaskText(newTask.value.title, getQuickAddMagicMode()))
watch( watch(
() => parsedTask.value.date, () => parsedTask.value.date,
date => newTask.value.dueDate = date date => newTask.value.dueDate = date,
) )
const labels = ref<string[]>([])
watch(
() => parsedTask.value.labels,
labelTitles => labels.value = labelTitles,
)
const realLabels = computed<ILabel[]>(() => {
const existingLabels = labelStore.getLabelsByExactTitles(labels.value)
const newLabels = labels.value
.filter(l => l !== '' && !(existingLabels.map(le => le.title).includes(l)))
.map(newLabel => new LabelModel({title: newLabel}))
return [
...existingLabels,
...newLabels,
]
})
async function create() { async function create() {
if (newTask.value.title === '') { if (newTask.value.title === '') {
errorMessage.value = t('list.create.addTitleRequired') errorMessage.value = t('list.create.addTitleRequired')
@ -109,6 +141,12 @@ async function create() {
}) })
const task = await taskService.value.create(finalTask) const task = await taskService.value.create(finalTask)
await store.dispatch('tasks/addLabelsToTask', {
task,
parsedLabels: labels,
})
return router.push({name: 'task.detail', params: {id: task.id}}) return router.push({name: 'task.detail', params: {id: task.id}})
} }
</script> </script>