Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to hide minimap #2652

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/common/settings/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface ReadonlyStorage {
getItem(key: string): string | null;
}

export const migrateOldStorageSettings = (settings: ReadonlyStorage): ChainnerSettings => {
export const migrateOldStorageSettings = (settings: ReadonlyStorage): Partial<ChainnerSettings> => {
const get = <T>(key: string, defaultValue: T): T => {
const stored = settings.getItem(key);
if (stored === null) {
Expand Down
2 changes: 2 additions & 0 deletions src/common/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface ChainnerSettings {
snapToGrid: boolean;
snapToGridAmount: number;
viewportExportPadding: number;
showMinimap: boolean;

experimentalFeatures: boolean;
hardwareAcceleration: boolean;
Expand All @@ -38,6 +39,7 @@ export const defaultSettings: Readonly<ChainnerSettings> = {
snapToGrid: false,
snapToGridAmount: 16,
viewportExportPadding: 20,
showMinimap: true,

experimentalFeatures: false,
hardwareAcceleration: false,
Expand Down
8 changes: 6 additions & 2 deletions src/main/setting-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { existsSync, readFileSync, renameSync, writeFileSync } from 'fs';
import { LocalStorage } from 'node-localstorage';
import path from 'path';
import { migrateOldStorageSettings } from '../common/settings/migration';
import { ChainnerSettings } from '../common/settings/settings';
import { ChainnerSettings, defaultSettings } from '../common/settings/settings';
import { getRootDirSync } from './platform';

const settingsJson = path.join(getRootDirSync(), 'settings.json');
Expand All @@ -20,10 +20,14 @@ export const readSettings = (): ChainnerSettings => {
// legacy settings
const storagePath = path.join(getRootDirSync(), 'settings');
const storage = new LocalStorage(storagePath);
const settings = migrateOldStorageSettings({
const partialSettings = migrateOldStorageSettings({
keys: Array.from({ length: storage.length }, (_, i) => storage.key(i)),
getItem: (key: string) => storage.getItem(key),
});
const settings: ChainnerSettings = {
...defaultSettings,
...partialSettings,
};

// write a new settings.json we'll use form now on
writeSettings(settings);
Expand Down
16 changes: 9 additions & 7 deletions src/renderer/components/ReactFlowBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const ReactFlowBox = memo(({ wrapperRef, nodeTypes, edgeTypes }: ReactFlo
} = useContext(GlobalContext);
const { schemata, functionDefinitions } = useContext(BackendContext);

const { snapToGrid: isSnapToGrid, snapToGridAmount, animateChain } = useSettings();
const { snapToGrid: isSnapToGrid, snapToGridAmount, animateChain, showMinimap } = useSettings();

const typeState = useContextSelector(GlobalVolatileContext, (c) => c.typeState);
const chainLineage = useContextSelector(GlobalVolatileContext, (c) => c.chainLineage);
Expand Down Expand Up @@ -511,12 +511,14 @@ export const ReactFlowBox = memo(({ wrapperRef, nodeTypes, edgeTypes }: ReactFlo
size={1}
variant={BackgroundVariant.Dots}
/>
<MiniMap
pannable
zoomable
ariaLabel=""
zoomStep={3}
/>
{showMinimap && (
<MiniMap
pannable
zoomable
ariaLabel=""
zoomStep={3}
/>
)}
<Controls>
<ControlButton
disabled={nodes.length === 0}
Expand Down
11 changes: 11 additions & 0 deletions src/renderer/components/SettingsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const AppearanceSettings = memo(() => {
useMutSetting('viewportExportPadding');
const [snapToGrid, setSnapToGrid] = useMutSetting('snapToGrid');
const [snapToGridAmount, setSnapToGridAmount] = useMutSetting('snapToGridAmount');
const [showMinimap, setShowMinimap] = useMutSetting('showMinimap');

return (
<VStack
Expand Down Expand Up @@ -76,6 +77,16 @@ const AppearanceSettings = memo(() => {
value={animateChain}
/>

<ToggleSetting
setValue={setShowMinimap}
setting={{
label: 'Minimap',
description:
'Enable a minimap of the current chain in the bottom right corner of the node editor.',
}}
value={showMinimap}
/>

<ToggleSetting
setValue={setSnapToGrid}
setting={{
Expand Down
Loading