Use Svelte Context API for passing user settings

This commit is contained in:
Mattias Granlund 2023-07-08 11:56:14 +01:00
parent fce7ffde19
commit de7973ccb8
4 changed files with 9 additions and 7 deletions

View File

@ -1,6 +1,7 @@
import { get, writable, type Writable } from '@square/svelte-store';
const SETTINGS_KEY = 'settings-json';
export const SETTINGS_CONTEXT = Symbol();
export interface Settings {
aiSummariesEnabled?: boolean;

View File

@ -3,7 +3,8 @@
import NewBranchDropZone from './NewBranchDropZone.svelte';
import type { Branch } from '$lib/api/ipc/vbranches';
import type { VirtualBranchOperations } from './vbranches';
import type { SettingsStore } from '$lib/userSettings';
import { SETTINGS_CONTEXT, type SettingsStore } from '$lib/userSettings';
import { setContext } from 'svelte';
export let projectId: string;
export let projectPath: string;
@ -11,6 +12,8 @@
export let virtualBranches: VirtualBranchOperations;
export let userSettings: SettingsStore;
setContext(SETTINGS_CONTEXT, userSettings);
let dragged: any;
let dropZone: HTMLDivElement;
let priorPosition = 0;
@ -97,7 +100,6 @@
branchId={id}
{virtualBranches}
{projectPath}
{userSettings}
/>
{/each}
<NewBranchDropZone {virtualBranches} />

View File

@ -15,7 +15,6 @@
import type { VirtualBranchOperations } from './vbranches';
import PopupMenu from '../../../lib/components/PopupMenu/PopupMenu.svelte';
import PopupMenuItem from '../../../lib/components/PopupMenu/PopupMenuItem.svelte';
import type { SettingsStore } from '$lib/userSettings';
const dispatch = createEventDispatcher<{
empty: never;
@ -31,7 +30,6 @@
export let projectId: string;
export let order: number;
export let virtualBranches: VirtualBranchOperations;
export let userSettings: SettingsStore;
$: remoteCommits = commits.filter((c) => c.isRemote);
$: localCommits = commits.filter((c) => !c.isRemote);
@ -253,7 +251,6 @@
filepath={file.path}
expanded={file.expanded}
hunks={file.hunks}
{userSettings}
{maximized}
on:update={(e) => {
handleFileUpdate(file.id, e.detail);

View File

@ -8,14 +8,16 @@
import { open } from '@tauri-apps/api/shell';
import PopupMenu from '$lib/components/PopupMenu/PopupMenu.svelte';
import PopupMenuItem from '$lib/components/PopupMenu/PopupMenuItem.svelte';
import type { SettingsStore } from '$lib/userSettings';
import { SETTINGS_CONTEXT, type SettingsStore } from '$lib/userSettings';
import { getContext } from 'svelte';
const userSettings = getContext<SettingsStore>(SETTINGS_CONTEXT);
export let id: string;
export let projectPath: string;
export let filepath: string;
export let hunks: Hunk[];
export let maximized: boolean;
export let userSettings: SettingsStore;
const dispatch = createEventDispatcher<{
expanded: boolean;