Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add due date and NLP parsing to todo list extension #16897

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions extensions/todo-list/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Todo List Changelog

## [Enhancements] - {PR_MERGE_DATE}

- Added an action to set a due date for a todo item.
- Added optional natural language parsing of items to extract due date and tags automatically.
- Added configuration option to order tasks by title.

## [New Action] - 2024-07-28

- Added an action to set a tag for a todo item.
Expand Down
21 changes: 21 additions & 0 deletions extensions/todo-list/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 24 additions & 4 deletions extensions/todo-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@
"bkeys818",
"pernielsentikaer",
"telmen",
"ridemountainpig"
"ridemountainpig",
"dedalusj"
],
"scripts": {
"build": "ray build -e dist",
"dev": "ray develop",
"fix-lint": "ray lint --fix",
"lint": "ray lint"
"lint": "ray lint",
"publish": "npx @raycast/api@latest publish"
},
"dependencies": {
"@raycast/api": "^1.52.1",
"@raycast/utils": "^1.1.0",
"chrono-node": "^2.7.8",
"dayjs": "^1.10.7",
"jotai": "^1.4.0",
"lodash": "^4.17.21",
Expand Down Expand Up @@ -89,17 +92,34 @@
"required": false,
"title": "Task sorting",
"description": "The order in which task are sorted.",
"default": "creation_date_accending",
"default": "creation_date_ascending",
"data": [
{
"title": "Creation Date (ascending)",
"value": "creation_date_accending"
"value": "creation_date_ascending"
},
{
"title": "Creation Date (descending)",
"value": "creation_date_descending"
},
{
"title": "Title (ascending)",
"value": "title_ascending"
},
{
"title": "Title (descending)",
"value": "title_descending"
}
]
},
{
"name": "nlpParsing",
"type": "checkbox",
"required": false,
"title": "Natural language parsing",
"description": "Automatically parse dates and tags",
"default": false,
"label": "Automatically parse dates and tags"
}
],
"title": "Todo List"
Expand Down
9 changes: 9 additions & 0 deletions extensions/todo-list/src/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface TodoSections {
export interface TodoItem {
title: string;
tag?: string;
dueDate?: number;
completed: boolean;
priority?: 1 | 2 | 3;
timeAdded: number;
Expand Down Expand Up @@ -64,6 +65,7 @@ export const searchModeAtom = atom(false);
export const searchBarTextAtom = atom("");
export const newTodoTextAtom = atom((get) => get(searchBarTextAtom).trim());
export const editingTagNameAtom = atom("");
export const editingDueDateValueAtom = atom(0);
export const editingAtom = atom<
| false
| {
Expand All @@ -78,5 +80,12 @@ export const editingTagAtom = atom<
index: number;
}
>(false);
export const editingDueDateAtom = atom<
| false
| {
sectionKey: keyof TodoSections;
index: number;
}
>(false);

export const selectedTagAtom = atom("All");
6 changes: 6 additions & 0 deletions extensions/todo-list/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ export const priorityDescriptions = {
2: "mid",
3: "high",
};

export const priorityShortInputs: Record<string, 1 | 2 | 3> = {
"!h": 3,
"!m": 2,
"!l": 1,
};
13 changes: 13 additions & 0 deletions extensions/todo-list/src/hooks/useTodo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
editingTagNameAtom,
searchBarTextAtom,
todoAtom,
editingDueDateAtom,
editingDueDateValueAtom,
} from "../atoms";
import { compare, insertIntoSection } from "../utils";

Expand All @@ -17,6 +19,8 @@ export const useTodo = ({ item, idx, sectionKey }: { item: TodoItem; idx: number
const [, setEditing] = useAtom(editingAtom);
const [, setEditingTag] = useAtom(editingTagAtom);
const [, setEditingTagName] = useAtom(editingTagNameAtom);
const [, setEditingDueDate] = useAtom(editingDueDateAtom);
const [, setEditingDueDateValue] = useAtom(editingDueDateValueAtom);
const [, setSearchBarText] = useAtom(searchBarTextAtom);

const setClone = () => {
Expand Down Expand Up @@ -91,6 +95,14 @@ export const useTodo = ({ item, idx, sectionKey }: { item: TodoItem; idx: number
setEditingTagName(item.tag ?? "");
};

const editTodoDueDate = () => {
setEditingDueDate({
sectionKey,
index: idx,
});
setEditingDueDateValue(item.dueDate ?? 0);
};

const setPriority = (priority?: 1 | 2 | 3) => {
item.priority = priority;
setClone();
Expand All @@ -99,6 +111,7 @@ export const useTodo = ({ item, idx, sectionKey }: { item: TodoItem; idx: number
return {
editTodo,
editTodoTag,
editTodoDueDate,
deleteTodo,
markTodo,
markCompleted,
Expand Down
3 changes: 1 addition & 2 deletions extensions/todo-list/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { List } from "@raycast/api";
import { editingAtom, editingTagAtom, selectedTagAtom, searchBarTextAtom, searchModeAtom } from "./atoms";
import { editingAtom, selectedTagAtom, searchBarTextAtom, searchModeAtom } from "./atoms";
import { useAtom } from "jotai";
import TodoSection from "./todo_section";
import ListActions from "./list_actions";
Expand All @@ -9,7 +9,6 @@ export default function TodoList() {
const [searchMode] = useAtom(searchModeAtom);
const [searchBarText, setSearchBarText] = useAtom(searchBarTextAtom);
const [editing] = useAtom(editingAtom);
const [editingTag] = useAtom(editingTagAtom);
const [selectedTag] = useAtom(selectedTagAtom);

return (
Expand Down
15 changes: 3 additions & 12 deletions extensions/todo-list/src/list_actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import _ from "lodash";
import { editingAtom, newTodoTextAtom, searchBarTextAtom, searchModeAtom, todoAtom } from "./atoms";
import DeleteAllAction from "./delete_all";
import SearchModeAction from "./search_mode_action";
import { compare, insertIntoSection } from "./utils";
import { compare, insertIntoSection, parseTodoItem } from "./utils";

const ListActions = () => {
const [searchMode] = useAtom(searchModeAtom);
Expand All @@ -18,17 +18,8 @@ const ListActions = () => {
await showToast(Toast.Style.Failure, "Empty todo", "Todo items cannot be empty.");
return;
}
todoSections.todo = [
...insertIntoSection(
todoSections.todo,
{
title: newTodoText,
completed: false,
timeAdded: Date.now(),
},
compare
),
];
const newItem = parseTodoItem(newTodoText);
todoSections.todo = [...insertIntoSection(todoSections.todo, newItem, compare)];
await clearSearchBar();
setTodoSections(_.cloneDeep(todoSections));
};
Expand Down
43 changes: 43 additions & 0 deletions extensions/todo-list/src/todo_due_date_form.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { useAtom } from "jotai";
import _ from "lodash";
import { todoAtom, editingDueDateAtom, editingDueDateValueAtom } from "./atoms";
import { ActionPanel, Form, Action, useNavigation } from "@raycast/api";
import { useState } from "react";

const TodoDueDateForm = () => {
const { pop } = useNavigation();
const [todoSections, setTodoSections] = useAtom(todoAtom);
const [editingDueDate] = useAtom(editingDueDateAtom);
const [editingDueDateValue] = useAtom(editingDueDateValueAtom);
const [dueDate, setDueDate] = useState<Date | null>(editingDueDateValue > 0 ? new Date(editingDueDateValue) : null);

const editTodoDueDate = async () => {
if (!editingDueDate) return;

todoSections[editingDueDate.sectionKey].splice(editingDueDate.index, 1, {
...todoSections[editingDueDate.sectionKey][editingDueDate.index],
dueDate: dueDate ? dueDate.getTime() : undefined,
});
setTodoSections(_.cloneDeep(todoSections));
};

return (
<Form
actions={
<ActionPanel>
<Action.SubmitForm
onSubmit={() => {
editTodoDueDate();
pop();
}}
/>
<Action onAction={() => pop()} title="Cancel" />
</ActionPanel>
}
>
<Form.DatePicker id="dueDate" onChange={setDueDate} title="Due date" value={dueDate} />
</Form>
);
};

export default TodoDueDateForm;
Loading
Loading