mirror of
https://github.com/better-auth/better-hub
synced 2026-08-09 12:26:04 +00:00
feat: persist diff preferences (#188)
closes https://github.com/better-auth/better-hub/issues/184
This commit is contained in:
@@ -61,6 +61,7 @@ import { ClientMarkdown } from "@/components/shared/client-markdown";
|
||||
import { CheckStatusBadge } from "@/components/pr/check-status-badge";
|
||||
import { useMutationEvents } from "@/components/shared/mutation-event-provider";
|
||||
import { UserTooltip } from "@/components/shared/user-tooltip";
|
||||
import { getDiffPreferences, setSplitView, setWordWrap } from "@/lib/diff-preferences";
|
||||
|
||||
interface DiffFile {
|
||||
filename: string;
|
||||
@@ -158,8 +159,8 @@ export function PRDiffViewer({
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
const [wordWrap, setWordWrap] = useState(true);
|
||||
const [splitView, setSplitView] = useState(false);
|
||||
const [wordWrap, setWordWrapState] = useState(() => getDiffPreferences().wordWrap);
|
||||
const [splitView, setSplitViewState] = useState(() => getDiffPreferences().splitView);
|
||||
const [sidebarWidth, setSidebarWidth] = useState(220);
|
||||
const [sidebarCollapsed, setSidebarCollapsed] = useState(false);
|
||||
const [isDragging, setIsDragging] = useState(false);
|
||||
@@ -543,8 +544,18 @@ export function PRDiffViewer({
|
||||
total={files.length}
|
||||
wordWrap={wordWrap}
|
||||
splitView={splitView}
|
||||
onToggleWrap={() => setWordWrap((w) => !w)}
|
||||
onToggleSplit={() => setSplitView((s) => !s)}
|
||||
onToggleWrap={() => {
|
||||
setWordWrapState((w) => {
|
||||
setWordWrap(!w);
|
||||
return !w;
|
||||
});
|
||||
}}
|
||||
onToggleSplit={() => {
|
||||
setSplitViewState((s) => {
|
||||
setSplitView(!s);
|
||||
return !s;
|
||||
});
|
||||
}}
|
||||
sidebarCollapsed={sidebarCollapsed}
|
||||
onToggleSidebar={() =>
|
||||
setSidebarCollapsed((c) => !c)
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
const STORAGE_KEY = "better-github-diff-preferences";
|
||||
|
||||
export interface DiffPreferences {
|
||||
splitView: boolean;
|
||||
wordWrap: boolean;
|
||||
}
|
||||
|
||||
const DEFAULT_PREFERENCES: DiffPreferences = {
|
||||
splitView: false,
|
||||
wordWrap: true,
|
||||
};
|
||||
|
||||
export function getDiffPreferences(): DiffPreferences {
|
||||
if (typeof window === "undefined") return DEFAULT_PREFERENCES;
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY);
|
||||
if (!raw) return DEFAULT_PREFERENCES;
|
||||
const parsed = JSON.parse(raw) as Partial<DiffPreferences>;
|
||||
return { ...DEFAULT_PREFERENCES, ...parsed };
|
||||
} catch {
|
||||
return DEFAULT_PREFERENCES;
|
||||
}
|
||||
}
|
||||
|
||||
export function setDiffPreferences(prefs: Partial<DiffPreferences>): DiffPreferences {
|
||||
if (typeof window === "undefined") return DEFAULT_PREFERENCES;
|
||||
try {
|
||||
const current = getDiffPreferences();
|
||||
const updated = { ...current, ...prefs };
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(updated));
|
||||
return updated;
|
||||
} catch {
|
||||
return getDiffPreferences();
|
||||
}
|
||||
}
|
||||
|
||||
export function setSplitView(splitView: boolean): void {
|
||||
setDiffPreferences({ splitView });
|
||||
}
|
||||
|
||||
export function setWordWrap(wordWrap: boolean): void {
|
||||
setDiffPreferences({ wordWrap });
|
||||
}
|
||||
Reference in New Issue
Block a user