( note: ZenNote, action: "archive" | "unarchive", onUpdate: (oldPath: string, updatedNote: ZenNote) => void, )
| 306 | } |
| 307 | |
| 308 | async function updateNoteArchiveState( |
| 309 | note: ZenNote, |
| 310 | action: "archive" | "unarchive", |
| 311 | onUpdate: (oldPath: string, updatedNote: ZenNote) => void, |
| 312 | ): Promise<void> { |
| 313 | const verb = action === "archive" ? "Archiving" : "Unarchiving"; |
| 314 | const done = action === "archive" ? "Archived" : "Unarchived"; |
| 315 | const toast = await showToast({ |
| 316 | style: Toast.Style.Animated, |
| 317 | title: `${verb} note`, |
| 318 | message: note.title, |
| 319 | }); |
| 320 | |
| 321 | try { |
| 322 | const { stdout } = await execZen([action, note.path, "--json"]); |
| 323 | const updatedNote = parseNote(JSON.parse(String(stdout)) as unknown); |
| 324 | if (!updatedNote) |
| 325 | throw new Error(`Expected \`zn ${action} --json\` to return a note.`); |
| 326 | onUpdate(note.path, updatedNote); |
| 327 | toast.style = Toast.Style.Success; |
| 328 | toast.title = `${done} note`; |
| 329 | toast.message = updatedNote.title; |
| 330 | } catch (err) { |
| 331 | const loadError = toLoadError(err); |
| 332 | toast.style = Toast.Style.Failure; |
| 333 | toast.title = loadError.title; |
| 334 | toast.message = loadError.message; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | async function moveNoteToTrash( |
| 339 | note: ZenNote, |
no test coverage detected