diff --git a/source/app.tsx b/source/app.tsx index f91c434..c2cc47c 100644 --- a/source/app.tsx +++ b/source/app.tsx @@ -1,11 +1,10 @@ import React, {useState, useEffect, useCallback} from 'react'; import {Box, Text, useApp} from 'ink'; -import TextInput from 'ink-text-input'; import {TodoistApi, type Task} from '@doist/todoist-api-typescript'; import {type View, commands} from './commands.js'; -import {priorityColor} from './utils.js'; import {loadConfig, configPath} from './config.js'; import EditView from './edit-view.js'; +import TaskListView from './task-list-view.js'; const config = loadConfig(); const apiToken = config?.apiToken ?? process.env['TODOIST_API_TOKEN']; @@ -117,60 +116,14 @@ export default function App() { {viewLabel} - {tasks.map((task, i) => ( - - {i + 1}. {task.content} - {projects.get(task.projectId) ? ( - - {' '} - #{projects.get(task.projectId)} - - ) : ( - '' - )} - {task.labels.length > 0 ? ( - - {' '} - {task.labels.map(l => `@${l}`).join(' ')} - - ) : ( - '' - )} - {task.due?.date ? ( - - {' '} - {task.due.date} - - ) : ( - '' - )} - {task.priority > 1 ? ( - - {' '} - p{5 - task.priority} - - ) : ( - '' - )} - - ))} - {message && {message}} - - - {'> '} - - - - - {input && - commands - .filter(c => c.prefix.startsWith(input)) - .map(c => ( - - {' '} - {c.hint} - - ))} + ); } diff --git a/source/task-list-view.tsx b/source/task-list-view.tsx new file mode 100644 index 0000000..1f92689 --- /dev/null +++ b/source/task-list-view.tsx @@ -0,0 +1,82 @@ +import React from 'react'; +import {Box, Text} from 'ink'; +import TextInput from 'ink-text-input'; +import {type Task} from '@doist/todoist-api-typescript'; +import {commands} from './commands.js'; +import {priorityColor} from './utils.js'; + +type TaskListViewProps = { + tasks: Task[]; + projects: Map; + message: string; + input: string; + setInput: (value: string) => void; + onSubmit: (value: string) => Promise; +}; + +export default function TaskListView({ + tasks, + projects, + message, + input, + setInput, + onSubmit, +}: TaskListViewProps) { + return ( + <> + {tasks.map((task, i) => ( + + {i + 1}. {task.content} + {projects.get(task.projectId) ? ( + + {' '} + #{projects.get(task.projectId)} + + ) : ( + '' + )} + {task.labels.length > 0 ? ( + + {' '} + {task.labels.map(l => `@${l}`).join(' ')} + + ) : ( + '' + )} + {task.due?.date ? ( + + {' '} + {task.due.date} + + ) : ( + '' + )} + {task.priority > 1 ? ( + + {' '} + p{5 - task.priority} + + ) : ( + '' + )} + + ))} + {message && {message}} + + + {'> '} + + + + {input && + commands + .filter(c => c.prefix.startsWith(input)) + .map(c => ( + + {' '} + {c.hint} + + ))} + + ); +}