Use getContextByClass for AuthService

This commit is contained in:
Mattias Granlund 2024-03-21 18:41:22 +01:00
parent 87dd2c7327
commit a282a41c39
6 changed files with 17 additions and 15 deletions

View File

@ -3,14 +3,16 @@
import Icon from './Icon.svelte';
import InfoMessage from './InfoMessage.svelte';
import Link from './Link.svelte';
import { AuthService } from '$lib/backend/auth';
import { getContextByClass } from '$lib/utils/context';
import { slide } from 'svelte/transition';
import type { AuthService } from '$lib/backend/auth';
export let authService: AuthService;
export let projectId: string;
export let remoteName: string | null | undefined;
export let branchName: string | null | undefined;
const authService = getContextByClass(AuthService);
type Check = { name: string; promise: Promise<any> };
$: checks = [] as Check[];

View File

@ -4,6 +4,7 @@
import RadioButton from './RadioButton.svelte';
import SectionCard from './SectionCard.svelte';
import TextBox from './TextBox.svelte';
import { AuthService } from '$lib/backend/auth';
import { ProjectService, type Key, type KeyType, type Project } from '$lib/backend/projects';
import Button from '$lib/components/Button.svelte';
import Link from '$lib/components/Link.svelte';
@ -13,11 +14,10 @@
import { openExternalUrl } from '$lib/utils/url';
import { BaseBranch } from '$lib/vbranches/types';
import { onMount } from 'svelte';
import type { AuthService } from '$lib/backend/auth';
export let authService: AuthService;
export let project: Project;
const authService = getContextByClass(AuthService);
const baseBranch = getContextStoreByClass(BaseBranch);
const projectService = getContextByClass(ProjectService);
@ -207,7 +207,6 @@
<CredentialCheck
bind:this={credentialCheck}
projectId={project.id}
{authService}
remoteName={remoteName || $baseBranch?.remoteName}
branchName={branchName || $baseBranch?.shortName}
/>

View File

@ -7,15 +7,13 @@
import { UserService } from '$lib/stores/user';
import { getContextByClass } from '$lib/utils/context';
import { BranchController } from '$lib/vbranches/branchController';
import type { AuthService } from '$lib/backend/auth';
import type { Project } from '$lib/backend/projects';
import { goto } from '$app/navigation';
export let authService: AuthService;
const branchController = getContextByClass(BranchController);
export let project: Project;
export let remoteBranches: { name: string }[];
const branchController = getContextByClass(BranchController);
const userService = getContextByClass(UserService);
const user = userService.user;
@ -37,7 +35,7 @@
<DecorativeSplitView user={$user} img={newProjectSvg}>
{#if selectedBranch}
{@const [remoteName, branchName] = selectedBranch.split(/\/(.*)/s)}
<KeysForm {project} {authService} {remoteName} {branchName} />
<KeysForm {project} {remoteName} {branchName} />
<div class="actions">
<Button kind="outlined" color="neutral" on:mousedown={() => (selectedBranch = '')}
>Back</Button

View File

@ -2,6 +2,7 @@
import '../styles/main.postcss';
import { AIService } from '$lib/backend/aiService';
import { AuthService } from '$lib/backend/auth';
import { GitConfigService } from '$lib/backend/gitConfigService';
import { ProjectService } from '$lib/backend/projects';
import { PromptService } from '$lib/backend/prompt';
@ -23,7 +24,7 @@
import { goto } from '$app/navigation';
export let data: LayoutData;
$: ({ cloud, promptService } = data);
$: ({ cloud } = data);
const userSettings = loadUserSettings();
initTheme(userSettings);
@ -35,7 +36,8 @@
$: setContext(GitHubService, data.githubService);
$: setContext(GitConfigService, data.gitConfig);
$: setContext(AIService, data.aiService);
$: setContext(PromptService, promptService);
$: setContext(PromptService, data.promptService);
$: setContext(AuthService, data.authService);
let shareIssueModal: ShareIssueModal;

View File

@ -15,12 +15,13 @@
import type { PageData } from './$types';
import { goto } from '$app/navigation';
// TODO: Too much functionality here for a +page.svelte file
export let data: PageData;
$: projectService = data.projectService;
$: project$ = data.project$;
$: cloud = data.cloud;
$: authService = data.authService;
const userService = getContextByClass(UserService);
const user = userService.user;
@ -74,7 +75,7 @@
<ContentWrapper title="Project settings">
<CloudForm project={$project$} on:updated={onCloudUpdated} />
<DetailsForm project={$project$} on:updated={onDetailsUpdated} />
<KeysForm project={$project$} {authService} />
<KeysForm project={$project$} />
<Spacer />
<PreferencesForm project={$project$} on:updated={onPreferencesUpdated} />
<SectionCard>

View File

@ -7,7 +7,7 @@
export let data: PageData;
$: ({ authService, projectId, project$ } = data);
$: ({ projectId, project$ } = data);
</script>
{#await getRemoteBranches(projectId)}
@ -21,7 +21,7 @@
use virtual branches, please push your code to a remote branch to use as a base"
/>
{:else}
<ProjectSetup project={$project$} {authService} {remoteBranches} />
<ProjectSetup project={$project$} {remoteBranches} />
{/if}
{:catch}
<ProblemLoadingRepo