Файли
openidea/src/features/github/reviewMode/settings.ts
T
imacross 059fd8a69b feat(github): pull request tool window, timeline and review flow (#477)
Replaces the Pull Requests tool window with a full review workflow on top of gh's authentication.

- List with search, quick filters and paging; a tab per pull request and a New Pull Request tab.
- Details: commit picker, changes tree with viewed state, CI and reviewer status, merge, close and reopen.
- Timeline editor: comments, review threads, reactions and suggested changes.
- Review in the diff viewer and, for the checked-out branch, in the editor (review mode).
- New generic vcs extension points: registerDiffViewerProvider, lineInlays, reviewGutter, branch widget extensions; new vcs_merge_base and gh_api commands.
- CSP: img-src allows https://avatars.githubusercontent.com for avatars.

Fixed while testing against a real repository: remotes behind an SSH host alias, mergeability stuck on UNKNOWN, Apply Locally staying disabled after a checkout, relative links navigating the app's page, and review inlays wider than the pane.

Co-authored-by: imacross <[email protected]>
2026-10-31 07:50:43 +08:00

53 рядки
1.7 KiB
TypeScript

/**
* Review mode settings: the "Review Mode" toggle, persisted per project in local storage
* (`GithubPullRequestsProjectUISettings.editorReviewEnabled`, on by default), and the
* threads shown while it is on ("Show Unresolved Comments Only", the default, or "Show All
* Comments"; kept for the session like IntelliJ's view model).
*/
import { create } from "zustand";
import { useProject } from "@/platform/project";
import type { EditorThreadsOption } from "./model";
interface ReviewModeSettings {
enabled: boolean;
threads: EditorThreadsOption;
}
const key = (root: string) => `openidea.github.reviewMode.v1:${root}`;
const projectRoot = () => useProject.getState().project?.root ?? null;
function loadEnabled(root: string | null): boolean {
if (!root) return true;
try {
return globalThis.localStorage?.getItem(key(root)) !== "off";
} catch {
return true;
}
}
export const useReviewModeSettings = create<ReviewModeSettings>(() => ({
enabled: loadEnabled(projectRoot()),
threads: "unresolved",
}));
/** Turns review mode on or off for the project. */
export function setReviewModeEnabled(enabled: boolean) {
useReviewModeSettings.setState({ enabled });
const root = projectRoot();
if (!root) return;
try {
globalThis.localStorage?.setItem(key(root), enabled ? "on" : "off");
} catch {
/* storage unavailable */
}
}
export function setEditorThreadsOption(threads: EditorThreadsOption) {
useReviewModeSettings.setState({ threads });
}
/** Another project: its own toggle, the default threads option. */
export function reloadReviewModeSettings() {
useReviewModeSettings.setState({ enabled: loadEnabled(projectRoot()), threads: "unresolved" });
}