ref0-git 0.0.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (385) hide show
  1. package/app/apps/github/.dev.vars.example +6 -0
  2. package/app/apps/github/README.md +70 -0
  3. package/app/apps/github/THIRD_PARTY_NOTICES.md +214 -0
  4. package/app/apps/github/components.json +25 -0
  5. package/app/apps/github/generated/git-rest.ts +10444 -0
  6. package/app/apps/github/generated/routeTree.gen.ts +1242 -0
  7. package/app/apps/github/migrations/postgres/0001_auth.sql +46 -0
  8. package/app/apps/github/migrations/sql/0001_auth.sql +19 -0
  9. package/app/apps/github/migrations/sql/0002_passkeys.sql +9 -0
  10. package/app/apps/github/migrations/sql/0003_orgs.sql +22 -0
  11. package/app/apps/github/migrations/sql/0004_avatars.sql +6 -0
  12. package/app/apps/github/package.json +80 -0
  13. package/app/apps/github/src/branches/branch-list.tsx +385 -0
  14. package/app/apps/github/src/branches/branches.ts +55 -0
  15. package/app/apps/github/src/clients/allowed.ts +213 -0
  16. package/app/apps/github/src/clients/at-most.ts +17 -0
  17. package/app/apps/github/src/clients/avatars.ts +410 -0
  18. package/app/apps/github/src/clients/cached.ts +65 -0
  19. package/app/apps/github/src/clients/calls.ts +160 -0
  20. package/app/apps/github/src/clients/clients.ts +82 -0
  21. package/app/apps/github/src/clients/graphql.ts +50 -0
  22. package/app/apps/github/src/clients/host-answer.ts +28 -0
  23. package/app/apps/github/src/clients/host-calls.ts +382 -0
  24. package/app/apps/github/src/clients/icon-bytes.ts +203 -0
  25. package/app/apps/github/src/clients/proxy.ts +59 -0
  26. package/app/apps/github/src/clients/session-ended.ts +18 -0
  27. package/app/apps/github/src/clients/transfers.ts +212 -0
  28. package/app/apps/github/src/code/breadcrumbs.tsx +50 -0
  29. package/app/apps/github/src/code/code-page.tsx +147 -0
  30. package/app/apps/github/src/code/code-tree.tsx +338 -0
  31. package/app/apps/github/src/code/controls.tsx +230 -0
  32. package/app/apps/github/src/code/file-view.tsx +450 -0
  33. package/app/apps/github/src/code/files.ts +332 -0
  34. package/app/apps/github/src/code/folder-list.tsx +122 -0
  35. package/app/apps/github/src/code/go-to-file.tsx +131 -0
  36. package/app/apps/github/src/code/highlighted.tsx +58 -0
  37. package/app/apps/github/src/code/lines.ts +46 -0
  38. package/app/apps/github/src/code/load.ts +147 -0
  39. package/app/apps/github/src/code/markdown-files.ts +58 -0
  40. package/app/apps/github/src/code/places.ts +88 -0
  41. package/app/apps/github/src/code/ref-pages.ts +179 -0
  42. package/app/apps/github/src/code/ref-switcher.tsx +203 -0
  43. package/app/apps/github/src/code/refs.ts +142 -0
  44. package/app/apps/github/src/code/repo-home.tsx +240 -0
  45. package/app/apps/github/src/code/repo.ts +105 -0
  46. package/app/apps/github/src/code/saved-reads.ts +199 -0
  47. package/app/apps/github/src/code/saved.ts +110 -0
  48. package/app/apps/github/src/code/tree-fold.ts +186 -0
  49. package/app/apps/github/src/code/trees.ts +136 -0
  50. package/app/apps/github/src/components/avatar-picture.ts +53 -0
  51. package/app/apps/github/src/components/avatar-url.ts +16 -0
  52. package/app/apps/github/src/components/confirm-action.tsx +100 -0
  53. package/app/apps/github/src/components/count.tsx +24 -0
  54. package/app/apps/github/src/components/create-button.tsx +38 -0
  55. package/app/apps/github/src/components/file-icons/file-icons.css +225 -0
  56. package/app/apps/github/src/components/file-icons/file-icons.tsx +138 -0
  57. package/app/apps/github/src/components/filter.tsx +35 -0
  58. package/app/apps/github/src/components/hotkeys/hotkeys.tsx +255 -0
  59. package/app/apps/github/src/components/item-list.tsx +65 -0
  60. package/app/apps/github/src/components/language-dot.tsx +29 -0
  61. package/app/apps/github/src/components/list-toolbar.tsx +82 -0
  62. package/app/apps/github/src/components/markdown/editor.tsx +57 -0
  63. package/app/apps/github/src/components/markdown/markdown.css +177 -0
  64. package/app/apps/github/src/components/markdown/markdown.tsx +82 -0
  65. package/app/apps/github/src/components/owner-card.tsx +196 -0
  66. package/app/apps/github/src/components/pull-status.tsx +34 -0
  67. package/app/apps/github/src/components/recent.ts +41 -0
  68. package/app/apps/github/src/components/relative-time.tsx +78 -0
  69. package/app/apps/github/src/components/repos/icon-hashes.ts +91 -0
  70. package/app/apps/github/src/components/repos/new-repo-form.tsx +196 -0
  71. package/app/apps/github/src/components/repos/repo-icon.tsx +47 -0
  72. package/app/apps/github/src/components/repos/repo-list.tsx +528 -0
  73. package/app/apps/github/src/components/repos/your-repos.tsx +124 -0
  74. package/app/apps/github/src/components/review-state.tsx +75 -0
  75. package/app/apps/github/src/components/route-dialog.tsx +137 -0
  76. package/app/apps/github/src/components/save-button.tsx +58 -0
  77. package/app/apps/github/src/components/shell/app-shell.tsx +164 -0
  78. package/app/apps/github/src/components/shell/create-org-dialog.tsx +118 -0
  79. package/app/apps/github/src/components/shell/create-row.tsx +49 -0
  80. package/app/apps/github/src/components/shell/link-menu.tsx +94 -0
  81. package/app/apps/github/src/components/shell/nav-user.tsx +97 -0
  82. package/app/apps/github/src/components/shell/owner-repos.tsx +247 -0
  83. package/app/apps/github/src/components/shell/owner-switcher.tsx +104 -0
  84. package/app/apps/github/src/components/shell/repo-switcher.tsx +179 -0
  85. package/app/apps/github/src/components/shell/sections.ts +31 -0
  86. package/app/apps/github/src/components/shell/submenu-chevron.ts +147 -0
  87. package/app/apps/github/src/components/signin/device-card.tsx +139 -0
  88. package/app/apps/github/src/components/signin/login-form.tsx +88 -0
  89. package/app/apps/github/src/components/signin/signin-page.tsx +33 -0
  90. package/app/apps/github/src/components/signin/signup-form.tsx +106 -0
  91. package/app/apps/github/src/components/states/live-status.tsx +42 -0
  92. package/app/apps/github/src/components/states/states.tsx +126 -0
  93. package/app/apps/github/src/components/tab-indicator.tsx +143 -0
  94. package/app/apps/github/src/components/theme-choice.tsx +108 -0
  95. package/app/apps/github/src/components/theme-provider.tsx +126 -0
  96. package/app/apps/github/src/components/tones.ts +23 -0
  97. package/app/apps/github/src/components/ui/alert-dialog.tsx +187 -0
  98. package/app/apps/github/src/components/ui/alert.tsx +78 -0
  99. package/app/apps/github/src/components/ui/avatar.tsx +106 -0
  100. package/app/apps/github/src/components/ui/badge.tsx +51 -0
  101. package/app/apps/github/src/components/ui/breadcrumb.tsx +124 -0
  102. package/app/apps/github/src/components/ui/button-group.tsx +87 -0
  103. package/app/apps/github/src/components/ui/button.tsx +61 -0
  104. package/app/apps/github/src/components/ui/calendar.tsx +221 -0
  105. package/app/apps/github/src/components/ui/card.tsx +102 -0
  106. package/app/apps/github/src/components/ui/checkbox.tsx +26 -0
  107. package/app/apps/github/src/components/ui/collapsible.tsx +19 -0
  108. package/app/apps/github/src/components/ui/combobox.tsx +304 -0
  109. package/app/apps/github/src/components/ui/command.tsx +208 -0
  110. package/app/apps/github/src/components/ui/dialog.tsx +156 -0
  111. package/app/apps/github/src/components/ui/dropdown-menu.tsx +290 -0
  112. package/app/apps/github/src/components/ui/empty.tsx +100 -0
  113. package/app/apps/github/src/components/ui/field.tsx +236 -0
  114. package/app/apps/github/src/components/ui/hover-card.tsx +48 -0
  115. package/app/apps/github/src/components/ui/input-group.tsx +163 -0
  116. package/app/apps/github/src/components/ui/input.tsx +19 -0
  117. package/app/apps/github/src/components/ui/item.tsx +201 -0
  118. package/app/apps/github/src/components/ui/kbd.tsx +27 -0
  119. package/app/apps/github/src/components/ui/label.tsx +33 -0
  120. package/app/apps/github/src/components/ui/popover.tsx +87 -0
  121. package/app/apps/github/src/components/ui/radio-group.tsx +35 -0
  122. package/app/apps/github/src/components/ui/select.tsx +198 -0
  123. package/app/apps/github/src/components/ui/separator.tsx +22 -0
  124. package/app/apps/github/src/components/ui/sheet.tsx +138 -0
  125. package/app/apps/github/src/components/ui/sidebar.tsx +724 -0
  126. package/app/apps/github/src/components/ui/skeleton.tsx +13 -0
  127. package/app/apps/github/src/components/ui/sonner.tsx +47 -0
  128. package/app/apps/github/src/components/ui/styles.css +242 -0
  129. package/app/apps/github/src/components/ui/table.tsx +113 -0
  130. package/app/apps/github/src/components/ui/tabs.tsx +79 -0
  131. package/app/apps/github/src/components/ui/textarea.tsx +17 -0
  132. package/app/apps/github/src/components/ui/title.ts +6 -0
  133. package/app/apps/github/src/components/ui/toggle-group.tsx +89 -0
  134. package/app/apps/github/src/components/ui/toggle.tsx +42 -0
  135. package/app/apps/github/src/components/ui/tooltip.tsx +63 -0
  136. package/app/apps/github/src/components/user-avatar.tsx +145 -0
  137. package/app/apps/github/src/components/view-tabs.tsx +42 -0
  138. package/app/apps/github/src/context/context.ts +133 -0
  139. package/app/apps/github/src/diffs/blobs.ts +94 -0
  140. package/app/apps/github/src/diffs/diff-view.tsx +155 -0
  141. package/app/apps/github/src/diffs/files.ts +121 -0
  142. package/app/apps/github/src/diffs/hunks.tsx +454 -0
  143. package/app/apps/github/src/diffs/patch.ts +131 -0
  144. package/app/apps/github/src/diffs/rows.ts +137 -0
  145. package/app/apps/github/src/history/commit-diff.ts +54 -0
  146. package/app/apps/github/src/history/commit-list.tsx +207 -0
  147. package/app/apps/github/src/history/commit-page.tsx +147 -0
  148. package/app/apps/github/src/history/history.ts +129 -0
  149. package/app/apps/github/src/hooks/allowed.ts +31 -0
  150. package/app/apps/github/src/hooks/answers.ts +65 -0
  151. package/app/apps/github/src/hooks/avatars.ts +54 -0
  152. package/app/apps/github/src/hooks/draft.ts +38 -0
  153. package/app/apps/github/src/hooks/open-counts.ts +127 -0
  154. package/app/apps/github/src/hooks/profiles.ts +120 -0
  155. package/app/apps/github/src/hooks/repos.ts +440 -0
  156. package/app/apps/github/src/hooks/use-mobile.ts +19 -0
  157. package/app/apps/github/src/hooks/viewer.ts +39 -0
  158. package/app/apps/github/src/inbox/count.ts +70 -0
  159. package/app/apps/github/src/inbox/inbox-item.tsx +66 -0
  160. package/app/apps/github/src/inbox/inbox-page.tsx +572 -0
  161. package/app/apps/github/src/inbox/marks.ts +130 -0
  162. package/app/apps/github/src/inbox/release-tags.ts +65 -0
  163. package/app/apps/github/src/inbox/search.ts +97 -0
  164. package/app/apps/github/src/inbox/subjects.ts +184 -0
  165. package/app/apps/github/src/inbox/subscription-controls.tsx +184 -0
  166. package/app/apps/github/src/inbox/subscriptions.ts +189 -0
  167. package/app/apps/github/src/inbox/threads.ts +198 -0
  168. package/app/apps/github/src/issues/changes.ts +332 -0
  169. package/app/apps/github/src/issues/counts.ts +62 -0
  170. package/app/apps/github/src/issues/issue-list.tsx +682 -0
  171. package/app/apps/github/src/issues/issue-page.tsx +533 -0
  172. package/app/apps/github/src/issues/issues.ts +566 -0
  173. package/app/apps/github/src/issues/label-dialog.tsx +310 -0
  174. package/app/apps/github/src/issues/labels-page.tsx +119 -0
  175. package/app/apps/github/src/issues/new-issue.tsx +79 -0
  176. package/app/apps/github/src/issues/parts.tsx +71 -0
  177. package/app/apps/github/src/issues/picker.tsx +298 -0
  178. package/app/apps/github/src/issues/search.ts +238 -0
  179. package/app/apps/github/src/issues/sidebar.tsx +236 -0
  180. package/app/apps/github/src/lib/cn.ts +8 -0
  181. package/app/apps/github/src/lib/highlighting.ts +13 -0
  182. package/app/apps/github/src/live/follow.ts +129 -0
  183. package/app/apps/github/src/live/sse.ts +74 -0
  184. package/app/apps/github/src/live/use-follow.ts +37 -0
  185. package/app/apps/github/src/markdown/README.md +53 -0
  186. package/app/apps/github/src/markdown/allowed-html.ts +69 -0
  187. package/app/apps/github/src/markdown/context.ts +206 -0
  188. package/app/apps/github/src/markdown/images.ts +81 -0
  189. package/app/apps/github/src/markdown/lookup.ts +127 -0
  190. package/app/apps/github/src/markdown/patches.ts +299 -0
  191. package/app/apps/github/src/markdown/query.ts +25 -0
  192. package/app/apps/github/src/markdown/references.ts +158 -0
  193. package/app/apps/github/src/markdown/render.ts +103 -0
  194. package/app/apps/github/src/names/owners.ts +51 -0
  195. package/app/apps/github/src/names/repos.ts +24 -0
  196. package/app/apps/github/src/palette/palette.tsx +562 -0
  197. package/app/apps/github/src/palette/recent.ts +116 -0
  198. package/app/apps/github/src/palette/rows.tsx +487 -0
  199. package/app/apps/github/src/palette/server.ts +107 -0
  200. package/app/apps/github/src/palette/targets.ts +306 -0
  201. package/app/apps/github/src/policy.ts +606 -0
  202. package/app/apps/github/src/private-repos.ts +47 -0
  203. package/app/apps/github/src/pulls/compare-page.tsx +342 -0
  204. package/app/apps/github/src/pulls/files-tab.tsx +776 -0
  205. package/app/apps/github/src/pulls/live.ts +124 -0
  206. package/app/apps/github/src/pulls/merge-box.tsx +367 -0
  207. package/app/apps/github/src/pulls/merge-button.ts +86 -0
  208. package/app/apps/github/src/pulls/pull-list.tsx +235 -0
  209. package/app/apps/github/src/pulls/pull-page.tsx +474 -0
  210. package/app/apps/github/src/pulls/pull.ts +468 -0
  211. package/app/apps/github/src/pulls/pulls.ts +318 -0
  212. package/app/apps/github/src/pulls/review.ts +350 -0
  213. package/app/apps/github/src/pulls/search.ts +130 -0
  214. package/app/apps/github/src/queue/queue-page.tsx +405 -0
  215. package/app/apps/github/src/queue/queue.ts +231 -0
  216. package/app/apps/github/src/releases/latest-release.tsx +55 -0
  217. package/app/apps/github/src/releases/overview.tsx +30 -0
  218. package/app/apps/github/src/releases/release-form.tsx +353 -0
  219. package/app/apps/github/src/releases/release-list.tsx +173 -0
  220. package/app/apps/github/src/releases/release-view.tsx +183 -0
  221. package/app/apps/github/src/releases/releases.ts +308 -0
  222. package/app/apps/github/src/releases/tag-list.tsx +134 -0
  223. package/app/apps/github/src/router.tsx +46 -0
  224. package/app/apps/github/src/routes/$owner/$repo/_code/blob/$.tsx +33 -0
  225. package/app/apps/github/src/routes/$owner/$repo/_code/tree/$.tsx +28 -0
  226. package/app/apps/github/src/routes/$owner/$repo/_code.tsx +11 -0
  227. package/app/apps/github/src/routes/$owner/$repo/_releases/releases/index.tsx +19 -0
  228. package/app/apps/github/src/routes/$owner/$repo/_releases/tags.tsx +19 -0
  229. package/app/apps/github/src/routes/$owner/$repo/_releases.tsx +23 -0
  230. package/app/apps/github/src/routes/$owner/$repo/branches.tsx +39 -0
  231. package/app/apps/github/src/routes/$owner/$repo/commit/$sha.tsx +34 -0
  232. package/app/apps/github/src/routes/$owner/$repo/commits/$.tsx +42 -0
  233. package/app/apps/github/src/routes/$owner/$repo/compare/$.tsx +19 -0
  234. package/app/apps/github/src/routes/$owner/$repo/index.tsx +24 -0
  235. package/app/apps/github/src/routes/$owner/$repo/issues/$number.tsx +50 -0
  236. package/app/apps/github/src/routes/$owner/$repo/issues/index.tsx +53 -0
  237. package/app/apps/github/src/routes/$owner/$repo/issues/new.tsx +43 -0
  238. package/app/apps/github/src/routes/$owner/$repo/labels.tsx +22 -0
  239. package/app/apps/github/src/routes/$owner/$repo/pull/$number/checks.tsx +15 -0
  240. package/app/apps/github/src/routes/$owner/$repo/pull/$number/commits.tsx +15 -0
  241. package/app/apps/github/src/routes/$owner/$repo/pull/$number/files.tsx +15 -0
  242. package/app/apps/github/src/routes/$owner/$repo/pull/$number/index.tsx +19 -0
  243. package/app/apps/github/src/routes/$owner/$repo/pull/$number/route.tsx +52 -0
  244. package/app/apps/github/src/routes/$owner/$repo/pulls/index.tsx +48 -0
  245. package/app/apps/github/src/routes/$owner/$repo/queue.tsx +22 -0
  246. package/app/apps/github/src/routes/$owner/$repo/releases/edit/$.tsx +58 -0
  247. package/app/apps/github/src/routes/$owner/$repo/releases/new.tsx +40 -0
  248. package/app/apps/github/src/routes/$owner/$repo/releases/tag/$.tsx +35 -0
  249. package/app/apps/github/src/routes/$owner/$repo/route.tsx +102 -0
  250. package/app/apps/github/src/routes/$owner/$repo/settings/access.tsx +9 -0
  251. package/app/apps/github/src/routes/$owner/$repo/settings/hooks/index.tsx +16 -0
  252. package/app/apps/github/src/routes/$owner/$repo/settings/hooks/new.tsx +25 -0
  253. package/app/apps/github/src/routes/$owner/$repo/settings/index.tsx +17 -0
  254. package/app/apps/github/src/routes/$owner/$repo/settings/route.tsx +28 -0
  255. package/app/apps/github/src/routes/$owner/$repo/settings/rules.tsx +12 -0
  256. package/app/apps/github/src/routes/$owner/$repo/tokens.tsx +16 -0
  257. package/app/apps/github/src/routes/$owner/index.tsx +45 -0
  258. package/app/apps/github/src/routes/-nav.tsx +293 -0
  259. package/app/apps/github/src/routes/-root-testing.ts +107 -0
  260. package/app/apps/github/src/routes/__root.tsx +225 -0
  261. package/app/apps/github/src/routes/api.auth.$.ts +18 -0
  262. package/app/apps/github/src/routes/downloads/$owner/$repo/$asset.tsx +10 -0
  263. package/app/apps/github/src/routes/file-icons[.]svg.ts +21 -0
  264. package/app/apps/github/src/routes/icons/$owner/$repo.tsx +14 -0
  265. package/app/apps/github/src/routes/icons/$owner/index.tsx +14 -0
  266. package/app/apps/github/src/routes/icons/index.tsx +12 -0
  267. package/app/apps/github/src/routes/index.tsx +48 -0
  268. package/app/apps/github/src/routes/login.tsx +24 -0
  269. package/app/apps/github/src/routes/login_.code.tsx +31 -0
  270. package/app/apps/github/src/routes/new.tsx +91 -0
  271. package/app/apps/github/src/routes/notifications.tsx +20 -0
  272. package/app/apps/github/src/routes/orgs/$owner/issues.tsx +8 -0
  273. package/app/apps/github/src/routes/orgs/$owner/pulls.tsx +8 -0
  274. package/app/apps/github/src/routes/orgs/$owner/releases.tsx +8 -0
  275. package/app/apps/github/src/routes/orgs/$owner/route.tsx +25 -0
  276. package/app/apps/github/src/routes/orgs/$owner/settings.tsx +30 -0
  277. package/app/apps/github/src/routes/orgs/$owner/tokens.tsx +15 -0
  278. package/app/apps/github/src/routes/settings.tsx +54 -0
  279. package/app/apps/github/src/routes/signup.tsx +24 -0
  280. package/app/apps/github/src/routes/uploads/$owner/$repo/$release.tsx +10 -0
  281. package/app/apps/github/src/seed/acme.ts +498 -0
  282. package/app/apps/github/src/seed/licenses.ts +114 -0
  283. package/app/apps/github/src/seed/seed.ts +528 -0
  284. package/app/apps/github/src/server.ts +97 -0
  285. package/app/apps/github/src/settings/account-avatar.tsx +43 -0
  286. package/app/apps/github/src/settings/avatar-section.tsx +140 -0
  287. package/app/apps/github/src/settings/avatar.ts +58 -0
  288. package/app/apps/github/src/settings/general-settings.tsx +439 -0
  289. package/app/apps/github/src/settings/general.ts +73 -0
  290. package/app/apps/github/src/settings/hook-form.tsx +195 -0
  291. package/app/apps/github/src/settings/hook-list.tsx +166 -0
  292. package/app/apps/github/src/settings/hooks.ts +87 -0
  293. package/app/apps/github/src/settings/org-settings.tsx +228 -0
  294. package/app/apps/github/src/settings/orgs.ts +116 -0
  295. package/app/apps/github/src/settings/rule-list.tsx +72 -0
  296. package/app/apps/github/src/settings/rules.ts +27 -0
  297. package/app/apps/github/src/settings/settings-layout.tsx +114 -0
  298. package/app/apps/github/src/signin/approval.ts +186 -0
  299. package/app/apps/github/src/signin/auth-client.ts +127 -0
  300. package/app/apps/github/src/signin/auth.ts +753 -0
  301. package/app/apps/github/src/signin/avatars.ts +126 -0
  302. package/app/apps/github/src/signin/client-ip.ts +39 -0
  303. package/app/apps/github/src/signin/credentials.ts +26 -0
  304. package/app/apps/github/src/signin/device-code.ts +95 -0
  305. package/app/apps/github/src/signin/device-prompt.ts +125 -0
  306. package/app/apps/github/src/signin/errors.ts +135 -0
  307. package/app/apps/github/src/signin/host-session.ts +68 -0
  308. package/app/apps/github/src/signin/orgs.ts +283 -0
  309. package/app/apps/github/src/signin/owner-names.ts +183 -0
  310. package/app/apps/github/src/signin/person-lock.ts +104 -0
  311. package/app/apps/github/src/signin/seal.ts +88 -0
  312. package/app/apps/github/src/signin/seed-people.ts +92 -0
  313. package/app/apps/github/src/signin/session.ts +48 -0
  314. package/app/apps/github/src/signin/unborn.ts +110 -0
  315. package/app/apps/github/src/signin/viewer-orgs.ts +47 -0
  316. package/app/apps/github/src/signin/viewer.ts +74 -0
  317. package/app/apps/github/src/signin/with-headers.ts +14 -0
  318. package/app/apps/github/src/tokens/tokens-page.tsx +529 -0
  319. package/app/apps/github/src/tokens/tokens.ts +54 -0
  320. package/app/apps/github/tsconfig.json +25 -0
  321. package/app/apps/github/tsconfig.worker.json +24 -0
  322. package/app/apps/github/vite.config.ts +21 -0
  323. package/app/pnpm-workspace.yaml +216 -0
  324. package/app/tsconfig.base.json +127 -0
  325. package/dist/LICENSE +202 -0
  326. package/dist/cli/child.mjs +42 -0
  327. package/dist/cli/commands.mjs +23 -0
  328. package/dist/cli/credentials.mjs +84 -0
  329. package/dist/cli/documents.mjs +214 -0
  330. package/dist/cli/events.mjs +55 -0
  331. package/dist/cli/failure.mjs +105 -0
  332. package/dist/cli/folders.mjs +32 -0
  333. package/dist/cli/git-remote-ref0.d.mts +1 -0
  334. package/dist/cli/git-remote-ref0.mjs +29 -0
  335. package/dist/cli/git.mjs +69 -0
  336. package/dist/cli/helpers.mjs +184 -0
  337. package/dist/cli/hosts.mjs +127 -0
  338. package/dist/cli/node.mjs +15 -0
  339. package/dist/cli/output.mjs +135 -0
  340. package/dist/cli/prompt.mjs +35 -0
  341. package/dist/cli/queue.mjs +215 -0
  342. package/dist/cli/ref0-git.d.mts +1 -0
  343. package/dist/cli/ref0-git.mjs +144 -0
  344. package/dist/cli/repos.mjs +162 -0
  345. package/dist/cli/resources.mjs +131 -0
  346. package/dist/cli/run-end.mjs +57 -0
  347. package/dist/cli/runtime.mjs +50 -0
  348. package/dist/cli/setup.mjs +1410 -0
  349. package/dist/cli/sign-in.mjs +162 -0
  350. package/dist/cli/sign-ins.mjs +136 -0
  351. package/dist/cli/sqlite.mjs +28 -0
  352. package/dist/cli/tokens.mjs +141 -0
  353. package/dist/cli/vendor.mjs +123 -0
  354. package/dist/init/app.mjs +231 -0
  355. package/dist/init/astro.mjs +49 -0
  356. package/dist/init/choices.mjs +497 -0
  357. package/dist/init/cloudflare.mjs +324 -0
  358. package/dist/init/create.mjs +151 -0
  359. package/dist/init/detect.mjs +297 -0
  360. package/dist/init/files.mjs +80 -0
  361. package/dist/init/frameworks.mjs +248 -0
  362. package/dist/init/git-module.mjs +49 -0
  363. package/dist/init/github-routes.mjs +66 -0
  364. package/dist/init/jsonc.mjs +143 -0
  365. package/dist/init/metadata.mjs +48 -0
  366. package/dist/init/mounts.mjs +109 -0
  367. package/dist/init/next.mjs +203 -0
  368. package/dist/init/node-app.mjs +189 -0
  369. package/dist/init/node.mjs +460 -0
  370. package/dist/init/nuxt.mjs +115 -0
  371. package/dist/init/output.mjs +21 -0
  372. package/dist/init/plan.mjs +82 -0
  373. package/dist/init/range-major.mjs +257 -0
  374. package/dist/init/react-router.mjs +59 -0
  375. package/dist/init/routes.mjs +148 -0
  376. package/dist/init/shell.mjs +4 -0
  377. package/dist/init/stores.mjs +51 -0
  378. package/dist/init/sveltekit.mjs +139 -0
  379. package/dist/init/template.mjs +142 -0
  380. package/dist/init/templates.mjs +343 -0
  381. package/dist/init/vercel.mjs +384 -0
  382. package/dist/init/versions.mjs +32 -0
  383. package/dist/init/workspace.mjs +20 -0
  384. package/package.json +48 -6
  385. package/README.md +0 -5
@@ -0,0 +1,572 @@
1
+ import { useInfiniteQuery } from '@tanstack/react-query';
2
+ import { useNavigate } from '@tanstack/react-router';
3
+ import {
4
+ CircleCheckIcon,
5
+ CircleDotIcon,
6
+ CircleSlashIcon,
7
+ InboxIcon,
8
+ MessageSquareIcon,
9
+ SearchIcon,
10
+ TagIcon,
11
+ type LucideIcon,
12
+ } from 'lucide-react';
13
+ import { type RefObject, useEffect, useRef, useState } from 'react';
14
+
15
+ import { cn } from '#/lib/cn';
16
+
17
+ import { Go, usePreloaded } from '../code/controls.tsx';
18
+ import { typesInto } from '../components/hotkeys/hotkeys.tsx';
19
+ import { ItemList, More } from '../components/item-list.tsx';
20
+ import { RelativeTime } from '../components/relative-time.tsx';
21
+ import { Alert, AlertDescription } from '../components/ui/alert.tsx';
22
+ import { Button } from '../components/ui/button.tsx';
23
+ import { Checkbox } from '../components/ui/checkbox.tsx';
24
+ import { DropdownMenuRadioGroup, DropdownMenuRadioItem } from '../components/ui/dropdown-menu.tsx';
25
+ import {
26
+ Empty,
27
+ EmptyDescription,
28
+ EmptyHeader,
29
+ EmptyMedia,
30
+ EmptyTitle,
31
+ } from '../components/ui/empty.tsx';
32
+ import {
33
+ Item,
34
+ ItemActions,
35
+ ItemContent,
36
+ ItemDescription,
37
+ ItemMedia,
38
+ ItemTitle,
39
+ } from '../components/ui/item.tsx';
40
+ import { Skeleton } from '../components/ui/skeleton.tsx';
41
+ import { Filter } from '../components/filter.tsx';
42
+ import { pullStatuses } from '../components/pull-status.tsx';
43
+ import { tones } from '../components/tones.ts';
44
+ import { UserAvatar } from '../components/user-avatar.tsx';
45
+ import { useInboxMark, type InboxMark, type ThreadMark } from './marks.ts';
46
+ import { useReleaseTags } from './release-tags.ts';
47
+ import { inboxHref } from './search.ts';
48
+ import { useSubjectStates, type SubjectState } from './subjects.ts';
49
+ import {
50
+ inboxList,
51
+ isReason,
52
+ reasonName,
53
+ reasons,
54
+ subjectNumber,
55
+ threadHref,
56
+ type InboxFilter,
57
+ type InboxList,
58
+ type Thread,
59
+ } from './threads.ts';
60
+
61
+ /** A thread's row's icon and its name, by its subject's state, as GitHub's lists tell them apart. */
62
+ const stateIcons: Readonly<
63
+ Record<
64
+ SubjectState['state'],
65
+ { readonly Icon: LucideIcon; readonly name: string; readonly tone: string }
66
+ >
67
+ > = {
68
+ open: { Icon: CircleDotIcon, name: 'Open', tone: tones.open },
69
+ closed: { Icon: CircleCheckIcon, name: 'Closed', tone: tones.closed },
70
+ not_planned: { Icon: CircleSlashIcon, name: 'Closed as not planned', tone: tones.draft },
71
+ merged: pullStatuses.merged,
72
+ draft: pullStatuses.draft,
73
+ };
74
+
75
+ /** A pull request's open and closed icons, which are its own, not an issue's. */
76
+ const pullIcons = { open: pullStatuses.open, closed: pullStatuses.closed } as const;
77
+
78
+ /** The icon a thread's row shows: its subject's state once it's read, else its kind's. */
79
+ function ThreadIcon({
80
+ thread,
81
+ state,
82
+ }: {
83
+ readonly thread: Thread;
84
+ readonly state: SubjectState | undefined;
85
+ }) {
86
+ const { subject } = thread;
87
+
88
+ if (subject.kind === 'release') {
89
+ return <TagIcon aria-label="Release" className="size-5 text-muted-foreground" />;
90
+ }
91
+
92
+ if (subject.kind === 'other') return <MessageSquareIcon aria-hidden className="size-5" />;
93
+
94
+ if (state === undefined) {
95
+ const Icon = subject.kind === 'pull' ? pullStatuses.open.Icon : CircleDotIcon;
96
+
97
+ return <Icon aria-hidden className="size-5 text-muted-foreground" />;
98
+ }
99
+
100
+ const shown =
101
+ subject.kind === 'pull' && (state.state === 'open' || state.state === 'closed')
102
+ ? pullIcons[state.state]
103
+ : stateIcons[state.state];
104
+
105
+ return <shown.Icon aria-label={shown.name} className={cn('size-5', shown.tone)} />;
106
+ }
107
+
108
+ /** A row's box, which picks it for a mark, and what picking it does. */
109
+ interface Pick {
110
+ readonly picked: boolean;
111
+ readonly onPick: (picked: boolean) => void;
112
+ }
113
+
114
+ /**
115
+ * A thread's row: its box, where the tab offers marks, its subject's state, its title, leading to
116
+ * the issue, pull request or release, its repo and why it's in the inbox, then who acted on it last and
117
+ * when. An unread row's title is bold, with a dot a screen reader hears as "Unread". Opening it
118
+ * calls `onOpen`.
119
+ */
120
+ function ThreadRow({
121
+ thread,
122
+ state,
123
+ tag,
124
+ pick,
125
+ onOpen,
126
+ }: {
127
+ readonly thread: Thread;
128
+ readonly state: SubjectState | undefined;
129
+ /** A release thread's tag, once it's read, for its row to lead to the release's page. */
130
+ readonly tag: string | undefined;
131
+ readonly pick: Pick | undefined;
132
+ readonly onOpen: () => void;
133
+ }) {
134
+ const numbered = subjectNumber(thread.subject);
135
+ const number = numbered === undefined ? '' : ` #${numbered}`;
136
+
137
+ return (
138
+ <Item
139
+ role="listitem"
140
+ data-thread={thread.id}
141
+ className="flex-nowrap items-start gap-3 px-3 py-3 has-[:focus-visible]:bg-muted/50 sm:px-4"
142
+ >
143
+ {pick !== undefined && (
144
+ <Checkbox
145
+ aria-label={`Select ${thread.title}`}
146
+ checked={pick.picked}
147
+ onCheckedChange={pick.onPick}
148
+ className="mt-1"
149
+ />
150
+ )}
151
+ <ItemMedia>
152
+ <ThreadIcon thread={thread} state={state} />
153
+ </ItemMedia>
154
+ <ItemContent className="min-w-0">
155
+ <ItemTitle
156
+ className={cn(
157
+ 'line-clamp-none max-w-full text-sm/6 wrap-anywhere sm:text-base/6',
158
+ thread.unread ? 'font-semibold' : 'font-normal text-muted-foreground',
159
+ )}
160
+ >
161
+ {thread.unread && (
162
+ <span className="mr-1.5 inline-block size-2 rounded-full bg-link align-middle">
163
+ <span className="sr-only">Unread: </span>
164
+ </span>
165
+ )}
166
+ <Go href={threadHref(thread, tag)} onClick={onOpen} className="hover:underline">
167
+ {thread.title}
168
+ </Go>
169
+ </ItemTitle>
170
+ <ItemDescription className="text-sm/5">
171
+ {thread.place.owner}/{thread.place.repo}
172
+ {number} · {reasonName(thread.reason)}
173
+ </ItemDescription>
174
+ </ItemContent>
175
+ <ItemActions className="gap-2 text-sm text-muted-foreground">
176
+ {state?.actor !== undefined && (
177
+ <span className="flex items-center">
178
+ <span className="sr-only">Last by {state.actor}</span>
179
+ <UserAvatar login={state.actor} account="user" size="sm" />
180
+ </span>
181
+ )}
182
+ <RelativeTime at={thread.updatedAt} />
183
+ </ItemActions>
184
+ </Item>
185
+ );
186
+ }
187
+
188
+ /** How far each of GitHub's row keys moves: `j` to the next row, `k` to the one before. */
189
+ const rowSteps: ReadonlyMap<string, number> = new Map([
190
+ ['j', 1],
191
+ ['k', -1],
192
+ ]);
193
+
194
+ /** The list's rows, in order, which `j` and `k` move between. */
195
+ const rowsOf = (list: HTMLElement) => [...list.querySelectorAll<HTMLElement>('[data-thread]')];
196
+
197
+ /** A row's title link, which `j` and `k` focus. */
198
+ const titleOf = (row: HTMLElement) =>
199
+ row.querySelector<HTMLElement>('[data-slot="item-title"] a') ?? undefined;
200
+
201
+ /** GitHub's inbox key that marks the row focus is in done. */
202
+ const doneKey = 'e';
203
+
204
+ /**
205
+ * The page's row keys, as GitHub's inbox takes them. `j` and `k` focus the next row's title and the
206
+ * one before, from the row focus is in, on its title or anything else in it, or the first; Enter on
207
+ * it opens it, as on any link. `e` marks the row focus is in done, through `done`, where the tab
208
+ * offers it, and focuses the next row, or the one before for the last. No key acts while someone
209
+ * types in a field, or holds a modifier.
210
+ */
211
+ const useRowKeys = (
212
+ list: RefObject<HTMLElement | null>,
213
+ done: ((id: string) => void) | undefined,
214
+ ) =>
215
+ useEffect(() => {
216
+ const onKey = (event: KeyboardEvent) => {
217
+ const step = rowSteps.get(event.key);
218
+ const marks = event.key === doneKey && done !== undefined;
219
+ if (
220
+ (step === undefined && !marks) ||
221
+ event.defaultPrevented ||
222
+ event.metaKey ||
223
+ event.ctrlKey ||
224
+ event.altKey
225
+ )
226
+ return;
227
+
228
+ if (typesInto(event.target ?? undefined) || list.current === null) return;
229
+
230
+ const rows = rowsOf(list.current);
231
+ const at = rows.findIndex((row) => row.contains(document.activeElement));
232
+ const marked = marks ? rows[at]?.dataset.thread : undefined;
233
+ if (marks && marked === undefined) return;
234
+
235
+ const to = step === undefined ? (at + 1 < rows.length ? at + 1 : at - 1) : at + step;
236
+ const row = rows[at === -1 ? 0 : Math.min(Math.max(to, 0), rows.length - 1)];
237
+ const next = row === undefined || row === rows[at] ? undefined : titleOf(row);
238
+
239
+ event.preventDefault();
240
+ next?.focus();
241
+
242
+ if (marked !== undefined) done?.(marked);
243
+ };
244
+
245
+ document.addEventListener('keydown', onKey);
246
+
247
+ return () => document.removeEventListener('keydown', onKey);
248
+ }, [list, done]);
249
+
250
+ /** What each tab says with nothing in it, past a filter. */
251
+ const emptyTabs = {
252
+ unread: {
253
+ Icon: InboxIcon,
254
+ title: "You're all caught up",
255
+ description: 'Mentions, reviews asked of you and activity on what you take part in come here.',
256
+ },
257
+ all: {
258
+ Icon: InboxIcon,
259
+ title: "You're all caught up",
260
+ description: 'Mentions, reviews asked of you and activity on what you take part in come here.',
261
+ },
262
+ done: {
263
+ Icon: CircleCheckIcon,
264
+ title: 'Nothing marked done',
265
+ description: 'Notifications you mark done come here, until new activity brings them back.',
266
+ },
267
+ } as const satisfies Record<
268
+ InboxList,
269
+ { readonly Icon: LucideIcon; readonly title: string; readonly description: string }
270
+ >;
271
+
272
+ /** What a filter that keeps nothing says, on any tab. */
273
+ const emptyFiltered = {
274
+ Icon: SearchIcon,
275
+ title: 'No notifications match',
276
+ description: 'Clear the filter to see the rest of the inbox.',
277
+ } as const;
278
+
279
+ /** An inbox with nothing to show: all caught up, nothing marked done, or nothing under the filter. */
280
+ function NoThreads({ filtered, list }: { readonly filtered: boolean; readonly list: InboxList }) {
281
+ const { Icon, title, description } = filtered ? emptyFiltered : emptyTabs[list];
282
+
283
+ return (
284
+ <Empty>
285
+ <EmptyHeader>
286
+ <EmptyMedia variant="icon">
287
+ <Icon />
288
+ </EmptyMedia>
289
+ <EmptyTitle>{title}</EmptyTitle>
290
+ <EmptyDescription>{description}</EmptyDescription>
291
+ </EmptyHeader>
292
+ </Empty>
293
+ );
294
+ }
295
+
296
+ /** A second's last millisecond: GitHub's times hold whole seconds. */
297
+ const restOfSecond = 999;
298
+
299
+ /**
300
+ * The end of the second of the newest time among `threads`, which a mark-all marks up to.
301
+ * GitHub's times hold whole seconds and the drop-in keeps milliseconds, so the newest row's own
302
+ * time would leave that row unread when it came partway into its second.
303
+ */
304
+ const newestOf = (threads: readonly Thread[]) => {
305
+ const newest = Math.max(...threads.map((thread) => Date.parse(thread.updatedAt)));
306
+
307
+ return Number.isFinite(newest) ? new Date(newest + restOfSecond).toISOString() : undefined;
308
+ };
309
+
310
+ /**
311
+ * The marks over a tab's rows: a box that picks every row, then Mark as read and Mark as done for
312
+ * the rows picked, or, with none picked, Mark all as read, which marks the tab's repo, or the
313
+ * whole inbox, up to the newest row shown. A filter by reason offers no Mark all, since GitHub's
314
+ * mark-all takes no reason.
315
+ */
316
+ function Marks({
317
+ filter,
318
+ threads,
319
+ picked,
320
+ pick,
321
+ mark,
322
+ }: {
323
+ readonly filter: InboxFilter;
324
+ readonly threads: readonly Thread[];
325
+ readonly picked: readonly string[];
326
+ readonly pick: (ids: readonly string[]) => void;
327
+ /** The page's one mark, which every row and key shares, so a pending one holds the rest. */
328
+ readonly mark: InboxMark;
329
+ }) {
330
+ const every = threads.length > 0 && picked.length === threads.length;
331
+ const upTo = newestOf(threads);
332
+ const marksAll = filter.reason === undefined && upTo !== undefined;
333
+ const markPicked = (kind: ThreadMark) =>
334
+ void mark.mark({ kind, ids: picked }).then(() => pick([]));
335
+
336
+ return (
337
+ <div className="flex min-h-10 flex-wrap items-center gap-2 border-b px-3 py-1.5 text-sm sm:px-4">
338
+ <Checkbox
339
+ aria-label="Select all"
340
+ checked={every}
341
+ indeterminate={picked.length > 0 && !every}
342
+ onCheckedChange={(checked) => pick(checked ? threads.map((thread) => thread.id) : [])}
343
+ />
344
+ {picked.length > 0 ? (
345
+ <>
346
+ <span className="text-muted-foreground">{picked.length} selected</span>
347
+ <Button
348
+ variant="outline"
349
+ size="sm"
350
+ disabled={mark.pending}
351
+ onClick={() => markPicked('read')}
352
+ >
353
+ Mark as read
354
+ </Button>
355
+ <Button
356
+ variant="outline"
357
+ size="sm"
358
+ disabled={mark.pending}
359
+ onClick={() => markPicked('done')}
360
+ >
361
+ <CircleCheckIcon data-icon="inline-start" />
362
+ Mark as done
363
+ </Button>
364
+ </>
365
+ ) : (
366
+ marksAll && (
367
+ <Button
368
+ variant="ghost"
369
+ size="sm"
370
+ disabled={mark.pending}
371
+ onClick={() => void mark.mark({ kind: 'all', repo: filter.repo, upTo })}
372
+ >
373
+ Mark all as read
374
+ </Button>
375
+ )
376
+ )}
377
+ </div>
378
+ );
379
+ }
380
+
381
+ /**
382
+ * The threads under `filter`, a page at a time, each row's subject read for each page. Past the
383
+ * Done tab, each row has a box for the marks over the rows, opening an unread one marks it read,
384
+ * and `e` marks the focused one done.
385
+ */
386
+ function Threads({ filter }: { readonly filter: InboxFilter }) {
387
+ const pages = useInfiniteQuery(inboxList(filter));
388
+ const loaded = pages.data?.pages ?? [];
389
+ const threads = loaded.flatMap((page) => page.threads);
390
+ const states = useSubjectStates(loaded);
391
+ const tags = useReleaseTags(loaded);
392
+ const list = useRef<HTMLDivElement>(null);
393
+ const mark = useInboxMark();
394
+ const marks = filter.list !== 'done';
395
+ const [chosen, choose] = useState<ReadonlySet<string>>(new Set());
396
+ // A row picked before a read that no longer lists it is no longer picked.
397
+ const picked = threads.flatMap((thread) => (chosen.has(thread.id) ? [thread.id] : []));
398
+ const pick = (ids: readonly string[]) => choose(new Set(ids));
399
+ useRowKeys(list, marks ? (id) => void mark.mark({ kind: 'done', ids: [id] }) : undefined);
400
+
401
+ if (pages.isPending) return <Skeleton className="h-40" />;
402
+
403
+ if (pages.error !== null && threads.length === 0) {
404
+ return (
405
+ <div className="p-3">
406
+ <Alert variant="destructive">
407
+ <AlertDescription className="flex flex-wrap items-center justify-between gap-2">
408
+ {pages.error.message}
409
+ <Button variant="outline" size="sm" onClick={() => void pages.refetch()}>
410
+ Try again
411
+ </Button>
412
+ </AlertDescription>
413
+ </Alert>
414
+ </div>
415
+ );
416
+ }
417
+
418
+ return (
419
+ <div ref={list}>
420
+ {marks && threads.length > 0 && (
421
+ <Marks filter={filter} threads={threads} picked={picked} pick={pick} mark={mark} />
422
+ )}
423
+ {threads.length === 0 ? (
424
+ <NoThreads
425
+ filtered={filter.reason !== undefined || filter.repo !== undefined}
426
+ list={filter.list}
427
+ />
428
+ ) : (
429
+ <ItemList
430
+ aria-label="Notifications"
431
+ rows={threads}
432
+ keyOf={(thread) => thread.id}
433
+ row={(thread) => (
434
+ <ThreadRow
435
+ thread={thread}
436
+ state={states.get(thread.id)}
437
+ tag={tags.get(thread.id)}
438
+ pick={
439
+ marks
440
+ ? {
441
+ picked: chosen.has(thread.id),
442
+ onPick: (on) =>
443
+ pick(on ? [...picked, thread.id] : picked.filter((id) => id !== thread.id)),
444
+ }
445
+ : undefined
446
+ }
447
+ onOpen={() => {
448
+ if (marks && thread.unread) void mark.mark({ kind: 'read', ids: [thread.id] });
449
+ }}
450
+ />
451
+ )}
452
+ />
453
+ )}
454
+ <More pages={pages} label="More notifications" />
455
+ </div>
456
+ );
457
+ }
458
+
459
+ /** Each tab's name, in the order the tabs show. */
460
+ const tabNames = { unread: 'Unread', all: 'All', done: 'Done' } as const satisfies Record<
461
+ InboxList,
462
+ string
463
+ >;
464
+
465
+ /** Whether `name` is one of the tabs. */
466
+ const isList = (name: string): name is InboxList => Object.hasOwn(tabNames, name);
467
+
468
+ /** The Unread, All and Done tabs, linking to each, the one shown marked. */
469
+ function ListTabs({ filter }: { readonly filter: InboxFilter }) {
470
+ const tabs = Object.keys(tabNames).filter(isList);
471
+ const hrefOf = (list: InboxList) => inboxHref({ ...filter, list });
472
+ usePreloaded(tabs.flatMap((list) => (list === filter.list ? [] : [hrefOf(list)])));
473
+
474
+ return (
475
+ <nav
476
+ aria-label="Inbox"
477
+ className="inline-grid auto-cols-fr grid-flow-col rounded-md border bg-muted p-0.5 text-sm"
478
+ >
479
+ {tabs.map((list) => (
480
+ <Go
481
+ key={list}
482
+ href={hrefOf(list)}
483
+ aria-current={list === filter.list ? 'page' : undefined}
484
+ className="pressable flex items-center justify-center rounded-sm px-3 py-1 whitespace-nowrap text-muted-foreground outline-none hover:text-foreground focus-visible:ring-[3px] focus-visible:ring-ring aria-[current]:border aria-[current]:bg-background aria-[current]:font-semibold aria-[current]:text-foreground aria-[current]:shadow-xs"
485
+ >
486
+ {tabNames[list]}
487
+ </Go>
488
+ ))}
489
+ </nav>
490
+ );
491
+ }
492
+
493
+ /** A radio group's value for no filter. */
494
+ const anyValue = '';
495
+
496
+ /** The Reason and Repository filters, each a menu, which go to the page for what's picked. */
497
+ function Filters({
498
+ filter,
499
+ repos,
500
+ }: {
501
+ readonly filter: InboxFilter;
502
+ /** The repos the list's threads are in, which the Repository menu offers. */
503
+ readonly repos: readonly string[];
504
+ }) {
505
+ const navigate = useNavigate();
506
+ const go = (next: InboxFilter) => void navigate({ href: inboxHref(next) });
507
+ const current = filter.repo === undefined ? anyValue : `${filter.repo.owner}/${filter.repo.repo}`;
508
+ const offered = current === anyValue || repos.includes(current) ? repos : [current, ...repos];
509
+ const reasonPicked = (value: string) =>
510
+ go({ ...filter, reason: isReason(value) ? value : undefined });
511
+ const repoPicked = (value: string) => {
512
+ const [owner, repo] = value.split('/');
513
+
514
+ go({
515
+ ...filter,
516
+ repo: owner === undefined || repo === undefined ? undefined : { owner, repo },
517
+ });
518
+ };
519
+
520
+ return (
521
+ <div className="flex items-center gap-1">
522
+ <Filter name="Reason">
523
+ <DropdownMenuRadioGroup value={filter.reason ?? anyValue} onValueChange={reasonPicked}>
524
+ <DropdownMenuRadioItem value={anyValue}>Any reason</DropdownMenuRadioItem>
525
+ {Object.entries(reasons).map(([value, name]) => (
526
+ <DropdownMenuRadioItem key={value} value={value}>
527
+ {name}
528
+ </DropdownMenuRadioItem>
529
+ ))}
530
+ </DropdownMenuRadioGroup>
531
+ </Filter>
532
+ <Filter name="Repository">
533
+ <DropdownMenuRadioGroup value={current} onValueChange={repoPicked}>
534
+ <DropdownMenuRadioItem value={anyValue}>Every repository</DropdownMenuRadioItem>
535
+ {offered.map((name) => (
536
+ <DropdownMenuRadioItem key={name} value={name}>
537
+ {name}
538
+ </DropdownMenuRadioItem>
539
+ ))}
540
+ </DropdownMenuRadioGroup>
541
+ </Filter>
542
+ </div>
543
+ );
544
+ }
545
+
546
+ /**
547
+ * The viewer's Inbox, as GitHub's notifications show it: the Unread, All or Done tab, by reason and
548
+ * by repo, newest first. `j` and `k` move between rows, Enter opens one, and `e` marks it done.
549
+ */
550
+ export function InboxPage({ filter }: { readonly filter: InboxFilter }) {
551
+ const pages = useInfiniteQuery(inboxList(filter));
552
+ const repos = [
553
+ ...new Set(
554
+ (pages.data?.pages ?? []).flatMap((page) =>
555
+ page.threads.map((thread) => `${thread.place.owner}/${thread.place.repo}`),
556
+ ),
557
+ ),
558
+ ].toSorted();
559
+
560
+ return (
561
+ <div className="flex flex-col gap-3">
562
+ <h1 className="text-xl font-semibold">Inbox</h1>
563
+ <section aria-label="Notifications" className="border">
564
+ <div className="flex flex-wrap items-center justify-between gap-2 border-b bg-muted/50 px-3 py-1.5">
565
+ <ListTabs filter={filter} />
566
+ <Filters filter={filter} repos={repos} />
567
+ </div>
568
+ <Threads filter={filter} />
569
+ </section>
570
+ </div>
571
+ );
572
+ }
@@ -0,0 +1,130 @@
1
+ import { useMutation, useMutationState, useQueryClient } from '@tanstack/react-query';
2
+ import { toast } from 'sonner';
3
+
4
+ import { atMost } from '../clients/at-most.ts';
5
+ import { github } from '../clients/clients.ts';
6
+ import type { RepoPlace } from '../code/places.ts';
7
+ import { failure } from '../hooks/answers.ts';
8
+ import { inboxCount } from './count.ts';
9
+ import { inboxListKey } from './threads.ts';
10
+
11
+ /** What a mark does to one thread: reads it, or marks it done, which reads it with it. */
12
+ export type ThreadMark = 'read' | 'done';
13
+
14
+ /**
15
+ * A change to the viewer's inbox: threads marked read or done, or every unread thread marked read,
16
+ * in one repo or all, up to the newest the page has shown.
17
+ */
18
+ export type Mark =
19
+ | { readonly kind: ThreadMark; readonly ids: readonly string[] }
20
+ | { readonly kind: 'all'; readonly repo: RepoPlace | undefined; readonly upTo: string };
21
+
22
+ /** Each thread mark's call, GitHub's `PATCH` or `DELETE` on the thread, and what its failure says. */
23
+ const threadMarks = {
24
+ read: {
25
+ send: (thread_id: number) =>
26
+ github.PATCH('/notifications/threads/{thread_id}', { params: { path: { thread_id } } }),
27
+ failed: "The notification wasn't marked read",
28
+ },
29
+ done: {
30
+ send: (thread_id: number) =>
31
+ github.DELETE('/notifications/threads/{thread_id}', { params: { path: { thread_id } } }),
32
+ failed: "The notification wasn't marked done",
33
+ },
34
+ } as const satisfies Record<
35
+ ThreadMark,
36
+ {
37
+ readonly send: (
38
+ id: number,
39
+ ) => Promise<{ readonly error?: unknown; readonly response: Response }>;
40
+ readonly failed: string;
41
+ }
42
+ >;
43
+
44
+ /** How many threads a mark of several marks at once: each one commits to the viewer's inbox. */
45
+ const marksAtOnce = 4;
46
+
47
+ /** The thread `id` marked as `kind` says. */
48
+ const markOne = async (kind: ThreadMark, id: string) => {
49
+ const { send, failed } = threadMarks[kind];
50
+ const answer = await send(Number(id));
51
+ if (!answer.response.ok) throw failure(failed, answer);
52
+ };
53
+
54
+ /** What marking the thread `id` threw, once its call has answered, or `undefined` if it didn't. */
55
+ const failureOf = async (kind: ThreadMark, id: string) => {
56
+ try {
57
+ await markOne(kind, id);
58
+
59
+ return undefined;
60
+ } catch (failure) {
61
+ return failure;
62
+ }
63
+ };
64
+
65
+ /**
66
+ * Every unread thread updated at or before `upTo` marked read: a thread that came after the page
67
+ * showed its newest stays unread. GitHub's words when a job marks the rest later, else nothing.
68
+ */
69
+ const markAll = async (repo: RepoPlace | undefined, upTo: string) => {
70
+ const body = { last_read_at: upTo, read: true };
71
+ const answer =
72
+ repo === undefined
73
+ ? await github.PUT('/notifications', { body })
74
+ : await github.PUT('/repos/{owner}/{repo}/notifications', { params: { path: repo }, body });
75
+ if (!answer.response.ok) throw failure("The inbox wasn't marked read", answer);
76
+
77
+ return answer.response.status === 202 ? answer.data?.message : undefined;
78
+ };
79
+
80
+ /** The key every inbox mark runs under, one after another. */
81
+ const markKey = ['inbox', 'mark'] as const;
82
+
83
+ /**
84
+ * Marks the viewer's inbox, one mark after another however many ask, then reads its lists and its
85
+ * count again, whether the mark went through or not, so the page shows what the drop-in holds. A
86
+ * failed mark says why in a toast, and a mark-all a job finishes says so. `mark` settles once its
87
+ * own mark has, and `pending` holds while any is waiting or running.
88
+ */
89
+ export const useInboxMark = () => {
90
+ const queries = useQueryClient();
91
+ const { mutateAsync } = useMutation({
92
+ mutationKey: markKey,
93
+ scope: { id: markKey.join('/') },
94
+ mutationFn: async (mark: Mark) => {
95
+ if (mark.kind === 'all') return markAll(mark.repo, mark.upTo);
96
+
97
+ // Every thread's call answers before the mark settles, failed or not, so the reads after it
98
+ // and the next mark wait for all of them.
99
+ const failures = await atMost(marksAtOnce, mark.ids, (id) => failureOf(mark.kind, id));
100
+ const failed = failures.find((failure) => failure !== undefined);
101
+ if (failed !== undefined) throw failed;
102
+
103
+ return undefined;
104
+ },
105
+ onSuccess: (later) => {
106
+ if (later !== undefined) toast(later);
107
+ },
108
+ onError: (error) => toast.error(error.message),
109
+ onSettled: () =>
110
+ Promise.all([
111
+ queries.invalidateQueries({ queryKey: inboxListKey }),
112
+ queries.invalidateQueries({ queryKey: inboxCount.queryKey }),
113
+ ]),
114
+ });
115
+ const pending =
116
+ useMutationState({ filters: { mutationKey: markKey, status: 'pending' } }).length > 0;
117
+
118
+ return {
119
+ // The toast has said why a mark failed, so its caller only waits for it.
120
+ mark: (mark: Mark) =>
121
+ mutateAsync(mark).then(
122
+ () => undefined,
123
+ () => undefined,
124
+ ),
125
+ pending,
126
+ };
127
+ };
128
+
129
+ /** The inbox's mark, as `useInboxMark` gives it. */
130
+ export type InboxMark = ReturnType<typeof useInboxMark>;