Skip to content
Source
Sign inSign up

pullRequestFilesViewed.ts

28 lines1013 Bytes

1import type { PullRequestFilesViewedResult } from "@t3tools/contracts";
2​
3export type FilesViewedRead = PullRequestFilesViewedResult | null;
4​
5export interface ViewedPress {
6 readonly viewed: boolean;
7 readonly version: number;
8 /** Set once the write lands: the press yields to the server once a read newer than this lands. */
9 readonly awaitingReadAfter: { readonly read: FilesViewedRead } | undefined;
11​
12export interface ViewedState {
13 readonly key: string;
14 readonly presses: Readonly<Record<string, ViewedPress>>;
15 readonly error: string | null;
17​
18/** The pressed states the server's read has not caught up with yet. */
19export function viewedOverlay(
20 presses: Readonly<Record<string, ViewedPress>>,
21 read: FilesViewedRead,
22): Record<string, boolean> {
23 const overlay: Record<string, boolean> = {};
24 for (const [path, press] of Object.entries(presses))
25 if (press.awaitingReadAfter === undefined || press.awaitingReadAfter.read === read)
26 overlay[path] = press.viewed;
27 return overlay;