|
5 | 5 | import { OnboardingEvent, POSTHOG_WRAPPER } from '$lib/analytics/posthog';
|
6 | 6 | import { BACKEND } from '$lib/backend';
|
7 | 7 | import { GIT_SERVICE } from '$lib/git/gitService';
|
8 |
| - import { handleAddProjectOutcome } from '$lib/project/project'; |
9 |
| - import { PROJECTS_SERVICE } from '$lib/project/projectsService'; |
10 |
| - import { projectPath } from '$lib/routes/routes.svelte'; |
| 8 | + import { useAddProject } from '$lib/project/useProjects.svelte'; |
11 | 9 | import { parseRemoteUrl } from '$lib/url/gitUrl';
|
12 | 10 | import { inject } from '@gitbutler/core/context';
|
13 | 11 | import { persisted } from '@gitbutler/shared/persisted';
|
|
16 | 14 | import * as Sentry from '@sentry/sveltekit';
|
17 | 15 | import { onMount } from 'svelte';
|
18 | 16 |
|
19 |
| - const projectsService = inject(PROJECTS_SERVICE); |
20 | 17 | const gitService = inject(GIT_SERVICE);
|
21 | 18 | const posthog = inject(POSTHOG_WRAPPER);
|
22 | 19 | const backend = inject(BACKEND);
|
|
62 | 59 | return String(error);
|
63 | 60 | }
|
64 | 61 |
|
| 62 | + const { addProject } = useAddProject(() => { |
| 63 | + posthog.captureOnboarding( |
| 64 | + OnboardingEvent.ClonedProjectFailed, |
| 65 | + 'Failed to add project after cloning' |
| 66 | + ); |
| 67 | + throw new Error('Failed to add project after cloning.'); |
| 68 | + }); |
| 69 | +
|
65 | 70 | async function cloneRepository() {
|
66 | 71 | loading = true;
|
67 | 72 | savedTargetDirPath.set(targetDirPath);
|
|
88 | 93 | await gitService.cloneRepo(repositoryUrl, targetDir);
|
89 | 94 |
|
90 | 95 | posthog.captureOnboarding(OnboardingEvent.ClonedProject);
|
91 |
| - const outcome = await projectsService.addProject(targetDir); |
92 |
| - if (!outcome) { |
93 |
| - posthog.captureOnboarding( |
94 |
| - OnboardingEvent.ClonedProjectFailed, |
95 |
| - 'Failed to add project after cloning' |
96 |
| - ); |
97 |
| - throw new Error('Failed to add project after cloning.'); |
98 |
| - } |
99 |
| -
|
100 |
| - handleAddProjectOutcome(outcome, (project) => goto(projectPath(project.id))); |
| 96 | + await addProject(targetDir); |
101 | 97 | } catch (e) {
|
102 | 98 | Sentry.captureException(e);
|
103 | 99 | const errorMessage = getErrorMessage(e);
|
|
0 commit comments