feat(user): save quick add magic mode in api
This commit is contained in:
parent
77ee1bfc3e
commit
d8ad934643
@ -71,10 +71,10 @@ import {useBaseStore} from '@/stores/base'
|
||||
import {useProjectStore} from '@/stores/projects'
|
||||
import {useLabelStore} from '@/stores/labels'
|
||||
import {useTaskStore} from '@/stores/tasks'
|
||||
import {useAuthStore} from '@/stores/auth'
|
||||
|
||||
import {getHistory} from '@/modules/projectHistory'
|
||||
import {parseTaskText, PrefixMode, PREFIXES} from '@/modules/parseTaskText'
|
||||
import {getQuickAddMagicMode} from '@/helpers/quickAddMagicMode'
|
||||
import {success} from '@/message'
|
||||
|
||||
import type {ITeam} from '@/modelTypes/ITeam'
|
||||
@ -88,6 +88,7 @@ const baseStore = useBaseStore()
|
||||
const projectStore = useProjectStore()
|
||||
const labelStore = useLabelStore()
|
||||
const taskStore = useTaskStore()
|
||||
const authStore = useAuthStore()
|
||||
|
||||
type DoAction<Type = any> = { type: ACTION_TYPE } & Type
|
||||
|
||||
@ -242,7 +243,7 @@ const hintText = computed(() => {
|
||||
}
|
||||
}
|
||||
const prefixes =
|
||||
PREFIXES[getQuickAddMagicMode()] ?? PREFIXES[PrefixMode.Default]
|
||||
PREFIXES[authStore.settings.frontendSettings.quickAddMagicMode] ?? PREFIXES[PrefixMode.Default]
|
||||
return t('quickActions.hint', prefixes)
|
||||
})
|
||||
|
||||
@ -255,7 +256,7 @@ const availableCmds = computed(() => {
|
||||
return cmds
|
||||
})
|
||||
|
||||
const parsedQuery = computed(() => parseTaskText(query.value, getQuickAddMagicMode()))
|
||||
const parsedQuery = computed(() => parseTaskText(query.value, authStore.settings.frontendSettings.quickAddMagicMode))
|
||||
|
||||
const searchMode = computed(() => {
|
||||
if (query.value === '') {
|
||||
|
@ -116,12 +116,12 @@ async function addTask() {
|
||||
// This allows us to find the tasks with the title they had before being parsed
|
||||
// by quick add magic.
|
||||
const createdTasks: { [key: ITask['title']]: ITask } = {}
|
||||
const tasksToCreate = parseSubtasksViaIndention(newTaskTitle.value)
|
||||
const tasksToCreate = parseSubtasksViaIndention(newTaskTitle.value, authStore.settings.frontendSettings.quickAddMagicMode)
|
||||
|
||||
// We ensure all labels exist prior to passing them down to the create task method
|
||||
// In the store it will only ever see one task at a time so there's no way to reliably
|
||||
// check if a new label was created before (because everything happens async).
|
||||
const allLabels = tasksToCreate.map(({title}) => getLabelsFromPrefix(title) ?? [])
|
||||
const allLabels = tasksToCreate.map(({title}) => getLabelsFromPrefix(title, authStore.settings.frontendSettings.quickAddMagicMode) ?? [])
|
||||
await taskStore.ensureLabelsExist(allLabels.flat())
|
||||
|
||||
const newTasks = tasksToCreate.map(async ({title, project}) => {
|
||||
|
@ -99,11 +99,13 @@ import {ref, computed} from 'vue'
|
||||
|
||||
import BaseButton from '@/components/base/BaseButton.vue'
|
||||
|
||||
import {getQuickAddMagicMode} from '@/helpers/quickAddMagicMode'
|
||||
import {PREFIXES} from '@/modules/parseTaskText'
|
||||
import {useAuthStore} from '@/stores/auth'
|
||||
|
||||
const authStore = useAuthStore()
|
||||
|
||||
const visible = ref(false)
|
||||
const mode = ref(getQuickAddMagicMode())
|
||||
const mode = computed(() => authStore.settings.frontendSettings.quickAddMagicMode)
|
||||
|
||||
defineProps<{
|
||||
highlightHintIcon: boolean,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {getProjectFromPrefix} from '@/modules/parseTaskText'
|
||||
import {getProjectFromPrefix, PrefixMode} from '@/modules/parseTaskText'
|
||||
|
||||
export interface TaskWithParent {
|
||||
title: string,
|
||||
@ -16,7 +16,7 @@ const spaceRegex = /^ */
|
||||
* @param taskTitles should be multiple lines of task tiles with indention to declare their parent/subtask
|
||||
* relation between each other.
|
||||
*/
|
||||
export function parseSubtasksViaIndention(taskTitles: string): TaskWithParent[] {
|
||||
export function parseSubtasksViaIndention(taskTitles: string, prefixMode: PrefixMode): TaskWithParent[] {
|
||||
const titles = taskTitles.split(/[\r\n]+/)
|
||||
|
||||
return titles.map((title, index) => {
|
||||
@ -26,7 +26,7 @@ export function parseSubtasksViaIndention(taskTitles: string): TaskWithParent[]
|
||||
project: null,
|
||||
}
|
||||
|
||||
task.project = getProjectFromPrefix(task.title)
|
||||
task.project = getProjectFromPrefix(task.title, prefixMode)
|
||||
|
||||
if (index === 0) {
|
||||
return task
|
||||
@ -49,7 +49,7 @@ export function parseSubtasksViaIndention(taskTitles: string): TaskWithParent[]
|
||||
task.parent = task.parent.replace(spaceRegex, '')
|
||||
if (task.project === null) {
|
||||
// This allows to specify a project once for the parent task and inherit it to all subtasks
|
||||
task.project = getProjectFromPrefix(task.parent)
|
||||
task.project = getProjectFromPrefix(task.parent, prefixMode)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,15 +2,6 @@ import popSoundFile from '@/assets/audio/pop.mp3'
|
||||
|
||||
export const playSoundWhenDoneKey = 'playSoundWhenTaskDone'
|
||||
|
||||
export function playPop() {
|
||||
const enabled = localStorage.getItem(playSoundWhenDoneKey) === 'true'
|
||||
if (!enabled) {
|
||||
return
|
||||
}
|
||||
|
||||
playPopSound()
|
||||
}
|
||||
|
||||
export function playPopSound() {
|
||||
const popSound = new Audio(popSoundFile)
|
||||
popSound.play()
|
||||
|
@ -1,21 +0,0 @@
|
||||
import {PrefixMode} from '@/modules/parseTaskText'
|
||||
|
||||
const key = 'quickAddMagicMode'
|
||||
|
||||
export const setQuickAddMagicMode = (mode: PrefixMode) => {
|
||||
localStorage.setItem(key, mode)
|
||||
}
|
||||
|
||||
export const getQuickAddMagicMode = (): PrefixMode => {
|
||||
const mode = localStorage.getItem(key)
|
||||
|
||||
switch (mode) {
|
||||
case null:
|
||||
case PrefixMode.Default:
|
||||
return PrefixMode.Default
|
||||
case PrefixMode.Todoist:
|
||||
return PrefixMode.Todoist
|
||||
}
|
||||
|
||||
return PrefixMode.Disabled
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
import {parseDate} from '../helpers/time/parseDate'
|
||||
import {PRIORITIES} from '@/constants/priorities'
|
||||
import {REPEAT_TYPES, type IRepeatAfter, type IRepeatType} from '@/types/IRepeatAfter'
|
||||
import {getQuickAddMagicMode} from '@/helpers/quickAddMagicMode'
|
||||
|
||||
const VIKUNJA_PREFIXES: Prefixes = {
|
||||
label: '*',
|
||||
@ -72,10 +71,10 @@ export const parseTaskText = (text: string, prefixesMode: PrefixMode = PrefixMod
|
||||
return result
|
||||
}
|
||||
|
||||
result.labels = getLabelsFromPrefix(text, prefixes.label) ?? []
|
||||
result.labels = getLabelsFromPrefix(text, prefixesMode) ?? []
|
||||
result.text = cleanupItemText(result.text, result.labels, prefixes.label)
|
||||
|
||||
result.project = getProjectFromPrefix(result.text, prefixes.project)
|
||||
result.project = getProjectFromPrefix(result.text, prefixesMode)
|
||||
result.text = result.project !== null ? cleanupItemText(result.text, [result.project], prefixes.project) : result.text
|
||||
|
||||
result.priority = getPriority(result.text, prefixes.priority)
|
||||
@ -131,25 +130,19 @@ const getItemsFromPrefix = (text: string, prefix: string): string[] => {
|
||||
return Array.from(new Set(items))
|
||||
}
|
||||
|
||||
export const getProjectFromPrefix = (text: string, projectPrefix: string | null = null): string | null => {
|
||||
if (projectPrefix === null) {
|
||||
const prefixes = PREFIXES[getQuickAddMagicMode()]
|
||||
if (prefixes === undefined) {
|
||||
return null
|
||||
}
|
||||
projectPrefix = prefixes.project
|
||||
export const getProjectFromPrefix = (text: string, prefixMode: PrefixMode): string | null => {
|
||||
const projectPrefix = PREFIXES[prefixMode]?.project
|
||||
if(typeof projectPrefix === 'undefined') {
|
||||
return null
|
||||
}
|
||||
const projects: string[] = getItemsFromPrefix(text, projectPrefix)
|
||||
return projects.length > 0 ? projects[0] : null
|
||||
}
|
||||
|
||||
export const getLabelsFromPrefix = (text: string, projectPrefix: string | null = null): string[] | null => {
|
||||
if (projectPrefix === null) {
|
||||
const prefixes = PREFIXES[getQuickAddMagicMode()]
|
||||
if (prefixes === undefined) {
|
||||
return null
|
||||
}
|
||||
projectPrefix = prefixes.label
|
||||
export const getLabelsFromPrefix = (text: string, prefixMode: PrefixMode): string[] | null => {
|
||||
const projectPrefix = PREFIXES[prefixMode]?.project
|
||||
if(typeof projectPrefix === 'undefined') {
|
||||
return null
|
||||
}
|
||||
return getItemsFromPrefix(text, projectPrefix)
|
||||
}
|
||||
|
@ -6,8 +6,7 @@ import TaskService from '@/services/task'
|
||||
import TaskAssigneeService from '@/services/taskAssignee'
|
||||
import LabelTaskService from '@/services/labelTask'
|
||||
|
||||
import {playPop} from '@/helpers/playPop'
|
||||
import {getQuickAddMagicMode} from '@/helpers/quickAddMagicMode'
|
||||
import {playPopSound} from '@/helpers/playPop'
|
||||
import {cleanupItemText, parseTaskText, PREFIXES} from '@/modules/parseTaskText'
|
||||
|
||||
import TaskAssigneeModel from '@/models/taskAssignee'
|
||||
@ -29,6 +28,7 @@ import {useAttachmentStore} from '@/stores/attachments'
|
||||
import {useKanbanStore} from '@/stores/kanban'
|
||||
import {useBaseStore} from '@/stores/base'
|
||||
import ProjectUserService from '@/services/projectUsers'
|
||||
import {useAuthStore} from '@/stores/auth'
|
||||
|
||||
interface MatchedAssignee extends IUser {
|
||||
match: string,
|
||||
@ -106,6 +106,7 @@ export const useTaskStore = defineStore('task', () => {
|
||||
const attachmentStore = useAttachmentStore()
|
||||
const labelStore = useLabelStore()
|
||||
const projectStore = useProjectStore()
|
||||
const authStore = useAuthStore()
|
||||
|
||||
const tasks = ref<{ [id: ITask['id']]: ITask }>({}) // TODO: or is this ITask[]
|
||||
const isLoading = ref(false)
|
||||
@ -142,8 +143,8 @@ export const useTaskStore = defineStore('task', () => {
|
||||
try {
|
||||
const updatedTask = await taskService.update(task)
|
||||
kanbanStore.setTaskInBucket(updatedTask)
|
||||
if (task.done) {
|
||||
playPop()
|
||||
if (task.done && useAuthStore().settings.frontendSettings.playSoundWhenDone) {
|
||||
playPopSound()
|
||||
}
|
||||
return updatedTask
|
||||
} finally {
|
||||
@ -398,7 +399,7 @@ export const useTaskStore = defineStore('task', () => {
|
||||
Partial<ITask>,
|
||||
) {
|
||||
const cancel = setModuleLoading(setIsLoading)
|
||||
const quickAddMagicMode = getQuickAddMagicMode()
|
||||
const quickAddMagicMode = authStore.settings.frontendSettings.quickAddMagicMode
|
||||
const parsedTask = parseTaskText(title, quickAddMagicMode)
|
||||
|
||||
const foundProjectId = await findProjectId({
|
||||
|
@ -97,7 +97,7 @@
|
||||
{{ $t('user.settings.quickAddMagic.title') }}
|
||||
</span>
|
||||
<div class="select ml-2">
|
||||
<select v-model="quickAddMagicMode">
|
||||
<select v-model="settings.frontendSettings.quickAddMagicMode">
|
||||
<option v-for="set in PrefixMode" :key="set" :value="set">
|
||||
{{ $t(`user.settings.quickAddMagic.${set}`) }}
|
||||
</option>
|
||||
@ -160,7 +160,6 @@ import ProjectSearch from '@/components/tasks/partials/projectSearch.vue'
|
||||
|
||||
import {SUPPORTED_LOCALES} from '@/i18n'
|
||||
import {playSoundWhenDoneKey, playPopSound} from '@/helpers/playPop'
|
||||
import {getQuickAddMagicMode, setQuickAddMagicMode} from '@/helpers/quickAddMagicMode'
|
||||
import {createRandomID} from '@/helpers/randomId'
|
||||
import {success} from '@/message'
|
||||
import {AuthenticatedHTTPFactory} from '@/helpers/fetcher'
|
||||
@ -259,9 +258,6 @@ const loading = computed(() => authStore.isLoadingGeneralSettings)
|
||||
// )
|
||||
|
||||
async function updateSettings() {
|
||||
localStorage.setItem(playSoundWhenDoneKey, playSoundWhenDone.value ? 'true' : 'false')
|
||||
setQuickAddMagicMode(quickAddMagicMode.value)
|
||||
|
||||
await authStore.saveUserSettings({
|
||||
settings: {...settings.value},
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user