Add HelpPanel and TodoItemTouch components, extend task commands, and refactor task and view logic
- Introduced `HelpPanel.vue` for displaying keyboard shortcuts and command descriptions. - Added `TodoItemTouch.vue`, a mobile-friendly task item component with updated bindings and improved actions. - Extended task commands with support for tagging, due date parsing, and dynamic text formatting. - Implemented `useActions` utility for parsing and executing command-based task modifications. - Streamlined task editing and creation in `useTasks` for consistency and API integration. - Updated `ListScreen` to support collapsible, categorized task lists with visual enhancements. - Refactored `App.vue` for adaptive input handling on mobile versus desktop views. - Enhanced API communication in `useApi` with cleaner header generation and error handling.
This commit is contained in:
109
src/composables/useActions.ts
Normal file
109
src/composables/useActions.ts
Normal file
@@ -0,0 +1,109 @@
|
||||
import type { Task } from '../types.ts'
|
||||
import {
|
||||
archiveCommand,
|
||||
beginCommand,
|
||||
checkCommand,
|
||||
deleteCommand,
|
||||
dueCommand,
|
||||
editTaskCommand,
|
||||
flagCommand,
|
||||
insertTaskCommand,
|
||||
moveCommand,
|
||||
restoreCommand,
|
||||
stopCommand,
|
||||
switchCommand,
|
||||
tagRenameCommand,
|
||||
} from '../utils/actions.ts'
|
||||
import { parseCommand } from '../utils/parser.ts'
|
||||
import { useTasks } from './useTasks.ts'
|
||||
|
||||
export default function useActions() {
|
||||
const { tasks: tasksOriginal, createTask, updateTask } = useTasks()
|
||||
const run = (value: string) => {
|
||||
const cmd = parseCommand(value)
|
||||
let tasksToUpdate: Task[] = []
|
||||
let taskToCreate: Pick<Task, 'tag' | 'title' | 'dueDate'> | null = null
|
||||
const tasks = JSON.parse(JSON.stringify(tasksOriginal.value)) as Task[]
|
||||
if (cmd) {
|
||||
const ids = cmd.id
|
||||
? (cmd.id.match(/\d+/g) || []).map(s => Number.parseInt(s))
|
||||
: []
|
||||
switch (cmd.command.toLowerCase()) {
|
||||
case 'mv':
|
||||
case 'move':
|
||||
tasksToUpdate = moveCommand(tasks, ids, cmd)
|
||||
break
|
||||
case 'b':
|
||||
case 'begin':
|
||||
tasksToUpdate = beginCommand(tasks, ids)
|
||||
break
|
||||
case 'c':
|
||||
case 'check':
|
||||
tasksToUpdate = checkCommand(tasks, ids)
|
||||
break
|
||||
case 'd':
|
||||
case 'delete':
|
||||
tasksToUpdate = deleteCommand(ids, cmd, tasks)
|
||||
break
|
||||
case 'fl':
|
||||
case 'flag':
|
||||
tasksToUpdate = flagCommand(tasks, ids)
|
||||
break
|
||||
case 'st':
|
||||
case 'stop':
|
||||
tasksToUpdate = stopCommand(tasks, ids)
|
||||
break
|
||||
case 'sw':
|
||||
case 'switch':
|
||||
tasksToUpdate = switchCommand(tasks, ids)
|
||||
break
|
||||
case 'a':
|
||||
case 'archive':
|
||||
tasksToUpdate = archiveCommand(ids, cmd, tasks)
|
||||
break
|
||||
case 're':
|
||||
case 'restore':
|
||||
tasksToUpdate = restoreCommand(ids, cmd, tasks)
|
||||
break
|
||||
case 't':
|
||||
case 'task':
|
||||
taskToCreate = insertTaskCommand(cmd)
|
||||
break
|
||||
case 'e':
|
||||
case 'edit':
|
||||
tasksToUpdate = editTaskCommand(ids, cmd, tasks)
|
||||
break
|
||||
case 'due':
|
||||
tasksToUpdate = dueCommand(ids, cmd, tasks)
|
||||
break
|
||||
case 'tr':
|
||||
case 'tagre':
|
||||
case 'tagrename':
|
||||
tasksToUpdate = tagRenameCommand(cmd, tasks)
|
||||
break
|
||||
/* Visibility */
|
||||
// case 'hide':
|
||||
// updateCandidate = hideCommand(updateCandidate, cmd)
|
||||
// break
|
||||
// case 'show':
|
||||
// updateCandidate = showCommand(updateCandidate, cmd)
|
||||
// break
|
||||
// /* Single command */
|
||||
// case 'search':
|
||||
// updateCandidate = searchCommand(updateCandidate, cmd)
|
||||
// break
|
||||
// default:
|
||||
// updateCandidate = otherCommand(updateCandidate, cmd, state)
|
||||
// break
|
||||
}
|
||||
}
|
||||
// console.log(tasksToUpdate, taskToCreate)
|
||||
if (tasksToUpdate) {
|
||||
updateTask(tasksToUpdate)
|
||||
}
|
||||
if (taskToCreate) {
|
||||
createTask(taskToCreate)
|
||||
}
|
||||
}
|
||||
return { run }
|
||||
}
|
||||
Reference in New Issue
Block a user