Skip to content
Closed
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
377 changes: 377 additions & 0 deletions apps/web/e2e/keyboard.spec.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@opennextjs/cloudflare": "1.20.11",
"better-auth": "1.7.8",
"class-variance-authority": "0.7.1",
"cmdk": "1.1.1",
"cn": "0.4.0",
"drizzle-orm": "0.45.4",
"lucide-react": "1.57.0",
Expand Down
65 changes: 62 additions & 3 deletions apps/web/src/app/w/[workspaceId]/board-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ interface BoardContextValue {
loadDetail: (task: TaskView) => Promise<TaskDetail>;
notice: string | null;
notify: (message: string) => void;
/** Keyboard focus in the current view, and the multi-selection (ids). */
focusedId: string | null;
setFocusedId: (id: string | null) => void;
selected: ReadonlySet<string>;
setSelected: (next: ReadonlySet<string>) => void;
/** The task ids in on-screen order. The visible view sets it after each render. */
setOrder: (ids: string[]) => void;
getOrder: () => string[];
newTaskOpen: boolean;
setNewTaskOpen: (open: boolean) => void;
}

const BoardContext = createContext<BoardContextValue | null>(null);
Expand All @@ -39,6 +49,10 @@ export function BoardProvider({ workspaceId, initial, etag, children }: { worksp
const [store] = useState(() => new BoardStore(initial, etag, { fetchSnapshot: (e) => fetchSnapshot(workspaceId, e) }));
const [peekId, setPeekId] = useState<string | null>(null);
const [notice, setNotice] = useState<string | null>(null);
const [focusedId, setFocusedId] = useState<string | null>(null);
const [selected, setSelected] = useState<ReadonlySet<string>>(() => new Set());
const [newTaskOpen, setNewTaskOpen] = useState(false);
const order = useRef<string[]>([]);
const details = useRef(new Map<string, Promise<TaskDetail>>());
const noticeTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);

Expand All @@ -65,8 +79,27 @@ export function BoardProvider({ workspaceId, initial, etag, children }: { worksp
}, []);

const value = useMemo<BoardContextValue>(
() => ({ workspaceId, store, peekId, openPeek: setPeekId, closePeek: () => setPeekId(null), loadDetail, notice, notify }),
[workspaceId, store, peekId, loadDetail, notice, notify],
() => ({
workspaceId,
store,
peekId,
openPeek: setPeekId,
closePeek: () => setPeekId(null),
loadDetail,
notice,
notify,
focusedId,
setFocusedId,
selected,
setSelected,
setOrder: (ids: string[]) => {
order.current = ids;
},
getOrder: () => order.current,
newTaskOpen,
setNewTaskOpen,
}),
[workspaceId, store, peekId, loadDetail, notice, notify, focusedId, selected, newTaskOpen],
);
return <BoardContext value={value}>{children}</BoardContext>;
}
Expand Down Expand Up @@ -132,6 +165,32 @@ function taskActions(workspaceId: string, store: BoardStore, notify: (message: s
}
}

/** One field on many tasks, one after another (GitHub rate limits). One undo step for all. */
async function setFieldMany(tasks: TaskView[], field: FieldView, input: FieldInput | null): Promise<void> {
if (tasks.length === 1) return setField(tasks[0]!, field, input);
const done: { task: TaskView; previous: FieldInput | null }[] = [];
for (const [i, task] of tasks.entries()) {
notify(`Updating ${field.name}: ${i + 1} of ${tasks.length}…`);
const previous = currentInput(field, task);
try {
await store.mutate(task.id, withField(field, input), () => patch(task.id, { fields: { [field.id]: input } }));
done.push({ task, previous });
} catch (error) {
notify(`Stopped after ${done.length} of ${tasks.length}: ${(error as Error).message}`);
break;
}
}
if (done.length === tasks.length) notify(`Updated ${field.name} on ${tasks.length} tasks.`);
if (done.length > 0) {
store.pushUndo({
label: `${field.name} change on ${done.length} tasks`,
run: async () => {
for (const { task, previous } of done) await setField(task, field, previous, false);
},
});
}
}

async function undo(): Promise<void> {
try {
const label = await store.undo();
Expand All @@ -141,5 +200,5 @@ function taskActions(workspaceId: string, store: BoardStore, notify: (message: s
}
}

return { setField, setState, undo, upsert: (task: TaskView) => store.upsert(task) };
return { setField, setFieldMany, setState, undo, upsert: (task: TaskView) => store.upsert(task) };
}
Loading
Loading