Showing the changes to apps/web/src/components/pullRequest/pullRequestReviewStore.ts (1 of 172 files). Show all
Unified · Split
| @@ -6,7 +6,7 @@ · 5 unmodified lines | |||
| 6 | * hosts that have no pending review of their own. That also means a draft lives only as long | 6 | * hosts that have no pending review of their own. That also means a draft lives only as long |
| 7 | * as the tab does, which is why this is deliberately not persisted. | 7 | * as the tab does, which is why this is deliberately not persisted. |
| 8 | */ | 8 | */ |
| 9 | import type { ProjectId, PullRequestRef, PullRequestReviewCommentDraft } from "@t3tools/contracts"; | 9 | import type { PullRequestRef, PullRequestReviewCommentDraft } from "@t3tools/contracts"; |
| 10 | import { create } from "zustand"; | 10 | import { create } from "zustand"; |
| 11 | 11 | ||
| 12 | export type PendingReviewComment = PullRequestReviewCommentDraft & { readonly id: string }; | 12 | export type PendingReviewComment = PullRequestReviewCommentDraft & { readonly id: string }; |
| @@ -24,9 +24,14 @@ export function nextPendingReviewCommentId(): string { · 11 unmodified lines | |||
| 24 | return `pending-review-comment-${pendingCommentSequence}`; | 24 | return `pending-review-comment-${pendingCommentSequence}`; |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | /** One pull request's draft, scoped by project as well as repository: a repository can be checked out twice. */ | 27 | /** A project's thread can review the same repository path and number on different hosts. */ |
| 28 | export function pullRequestReviewKey(reference: PullRequestRef): string { | 28 | export function pullRequestReviewKey(reference: PullRequestRef): string { |
| 29 | return `${reference.projectId}/${reference.repository}#${reference.number}`; | 29 | return JSON.stringify([ |
| 30 | reference.projectId, | ||
| 31 | reference.host?.toLowerCase() ?? null, | ||
| 32 | reference.repository.toLowerCase(), | ||
| 33 | reference.number, | ||
| 34 | ]); | ||
| 30 | } | 35 | } |
| 31 | 36 | ||
| 32 | interface PullRequestReviewStoreState { | 37 | interface PullRequestReviewStoreState { |
| @@ -81,11 +86,9 @@ export const usePullRequestReviewStore = create<PullRequestReviewStoreState>()(( · 48 unmodified lines | |||
| 81 | })); | 86 | })); |
| 82 | 87 | ||
| 83 | /** The comments a pull request's draft holds, stable across renders while it is empty. */ | 88 | /** The comments a pull request's draft holds, stable across renders while it is empty. */ |
| 84 | export function usePendingReviewComments(reference: { | 89 | export function usePendingReviewComments( |
| 85 | readonly projectId: ProjectId; | 90 | reference: PullRequestRef, |
| 86 | readonly repository: string; | 91 | ): ReadonlyArray<PendingReviewComment> { |
| 87 | readonly number: number; | ||
| 88 | }): ReadonlyArray<PendingReviewComment> { | ||
| 89 | return usePullRequestReviewStore( | 92 | return usePullRequestReviewStore( |
| 90 | (store) => store.drafts[pullRequestReviewKey(reference)] ?? EMPTY, | 93 | (store) => store.drafts[pullRequestReviewKey(reference)] ?? EMPTY, |
| 91 | ); | 94 | ); |