Files
orca/mobile/src/tasks/task-draft-rows.ts
T
Kelvin Amoaba e22bb7c46c feat(mobile): keep Tasks and new-workspace drafts across kills (#40127)
* feat(mobile): keep Tasks and new-workspace drafts across kills

Task comments (per item and project row), the New issue title and body,
and the New workspace note now live in device-store draft rows. They come
back after the form closes or the app is killed, and only into an empty
field. A comment's setter stays bound to its item, so a send that settles
after the user moved on clears the right row.

* fix(mobile): rebuild comment sends when the draft's item changes

* fix(mobile): key the workspace note by host and keep cleared fields cleared

* fix(mobile): clear only the note a finished create sent

* fix(mobile): count clearing an empty draft field as the user's choice

* perf(mobile): cap field drafts, read sheet drafts on open, retry a failed read once

* fix(mobile): retry a failed draft read after a pause and keep New issue text typed during a create

* fix(mobile): save draft text again once a failed store read can be retried

* fix(mobile): remove a stored draft when an unread field is cleared
2026-11-09 13:51:32 +00:00

36 lines
1.7 KiB
TypeScript

import { durableDraftRowKey } from '../drafts/durable-draft-rows'
import { useDurableDraftField } from '../drafts/durable-draft-fields'
import { githubTaskKey } from './github-task-identity'
import type { ActionableTaskItem } from './mobile-tasks-project-workspace-types'
import type { GitHubProjectRow } from './mobile-tasks-view-state-types'
/** The item a status edit or refresh hands over as a new object is still the same item. */
export function taskItemIdentity(item: ActionableTaskItem): string {
return item.provider === 'github' ? `github:${githubTaskKey(item.source)}` : item.key
}
// Tasks rows are host-scoped (`''` worktree part); the shell binds the host.
function taskCommentDraftKey(id: string | null): string | null {
return id === null ? null : durableDraftRowKey('taskComment', '', id)
}
const TASK_CREATE_DRAFT_KEY = durableDraftRowKey('taskCreate', '', '')
/** The open item's comment box, kept per item. */
export function useTaskCommentDraft(item: ActionableTaskItem | null) {
return useDurableDraftField(taskCommentDraftKey(item && taskItemIdentity(item)), 'text')
}
/** A GitHub project row's comment box, kept per row. */
export function useProjectRowCommentDraft(row: GitHubProjectRow | null) {
return useDurableDraftField(taskCommentDraftKey(row && `githubProject:${row.id}`), 'text')
}
/** The New issue sheet's title and body, kept until a create succeeds and read only once the sheet opens. */
export function useTaskCreateDraft(open: boolean) {
const key = open ? TASK_CREATE_DRAFT_KEY : null
const [createTitle, setCreateTitle] = useDurableDraftField(key, 'title')
const [createBody, setCreateBody] = useDurableDraftField(key, 'body')
return { createTitle, setCreateTitle, createBody, setCreateBody }
}