Pick project and model when creating a task
This commit is contained in:
+19
-7
@@ -2,7 +2,7 @@ import { post } from "./api.js";
|
||||
import { errorText, h, replace, showAlert } from "./dom.js";
|
||||
import { focusLead } from "./panes.js";
|
||||
import { activeTasks, focusedProject, focusProject, focusTab, focusTask, lastVisits, onEach, state, taskState } from "./state.js";
|
||||
import { confirmMerge } from "./task.js";
|
||||
import { confirmMerge, models } from "./task.js";
|
||||
import { taskStyle } from "./taskcolor.js";
|
||||
|
||||
export function bindShortcuts(): void {
|
||||
@@ -48,6 +48,7 @@ const shortcuts: [string, [string, string][]][] = [
|
||||
[
|
||||
["↑ ↓", "Move the highlight"],
|
||||
["Enter", "Pick the highlighted row"],
|
||||
["name: title", "Create the task in the project whose name starts with name"],
|
||||
],
|
||||
],
|
||||
[
|
||||
@@ -128,12 +129,18 @@ export function openSwitcher(): void {
|
||||
};
|
||||
|
||||
const render = () => {
|
||||
const title = input.value.trim();
|
||||
const typed = input.value.trim();
|
||||
const prefix = /^([^:\s]+):\s*(.*)$/.exec(typed);
|
||||
const named = prefix ? state.projects.filter((p) => p.name.toLowerCase().startsWith(prefix[1]!.toLowerCase())) : [];
|
||||
const targets = named.length > 0 ? named : undefined;
|
||||
const title = targets ? prefix![2]! : typed;
|
||||
const q = title.toLowerCase();
|
||||
const inbox = (taskId: string) => state.inbox.filter((item) => item.task_id === taskId).length;
|
||||
const visits = lastVisits();
|
||||
const matches = activeTasks()
|
||||
.filter(({ project, task }) => `${project.name} ${task.title}`.toLowerCase().includes(q))
|
||||
.filter(({ project, task }) =>
|
||||
targets ? targets.some((p) => p.id === project.id) && task.title.toLowerCase().includes(q) : `${project.name} ${task.title}`.toLowerCase().includes(q),
|
||||
)
|
||||
.map((m) => ({ ...m, count: inbox(m.task.id), visited: visits[m.task.id] ?? 0 }))
|
||||
.sort((a, b) => Number(b.count > 0) - Number(a.count > 0) || a.visited - b.visited);
|
||||
rows = matches.map(({ project, task, count }) => {
|
||||
@@ -149,7 +156,7 @@ export function openSwitcher(): void {
|
||||
);
|
||||
return { el, pick: () => go(task.id) };
|
||||
});
|
||||
for (const p of state.projects.filter((p) => `${p.name} project`.toLowerCase().includes(q))) {
|
||||
for (const p of (targets ?? state.projects).filter((p) => `${p.name} project`.toLowerCase().includes(q))) {
|
||||
const el = h("li", {}, h("span", { class: "dot none" }), h("span", { class: "task-title" }, h("span", { class: "project-name" }, p.name)), h("span", { class: "task-state" }, "project"));
|
||||
rows.push({
|
||||
el,
|
||||
@@ -159,9 +166,14 @@ export function openSwitcher(): void {
|
||||
},
|
||||
});
|
||||
}
|
||||
const project = focusedProject() ?? state.projects[0];
|
||||
if (title && project) {
|
||||
const el = h("li", { class: "new-task" }, h("span", { class: "task-title" }, "New task in ", h("span", { class: "project-name" }, project.name), ": ", title));
|
||||
const fallback = focusedProject() ?? state.projects[0];
|
||||
for (const project of title ? (targets ?? (fallback ? [fallback] : [])) : []) {
|
||||
const el = h(
|
||||
"li",
|
||||
{ class: "new-task" },
|
||||
h("span", { class: "task-title" }, "New task in ", h("span", { class: "project-name" }, project.name), ": ", title),
|
||||
h("span", { class: "task-state", title: "Model for the first message" }, models[0]),
|
||||
);
|
||||
rows.push({ el, pick: () => void create(project.id, title) });
|
||||
}
|
||||
selected = Math.min(selected, Math.max(rows.length - 1, 0));
|
||||
|
||||
Reference in New Issue
Block a user