History

feat(pull-requests): link multiple pull requests to threads (#10839)

Julius Marminge committed 2 months ago

Commit afb84891 parent 383cc40172 files · +12057 −908Browse files

Showing the changes to apps/web/src/components/pullRequest/pullRequestReviewStore.ts (1 of 172 files). Show all

Unified · Split

apps/web/src/components/pullRequest/pullRequestReviewStore.ts+11−8
@@ -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 long6 * 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 */
9import type { ProjectId, PullRequestRef, PullRequestReviewCommentDraft } from "@t3tools/contracts";9import type { PullRequestRef, PullRequestReviewCommentDraft } from "@t3tools/contracts";
10import { create } from "zustand";10import { create } from "zustand";
11 11
12export type PendingReviewComment = PullRequestReviewCommentDraft & { readonly id: string };12export 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. */
28export function pullRequestReviewKey(reference: PullRequestRef): string {28export 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
32interface PullRequestReviewStoreState {37interface 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. */
84export function usePendingReviewComments(reference: {89export 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 );

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t