|
| 1 | +<script lang="ts"> |
| 2 | + import DecorativeSplitView from './DecorativeSplitView.svelte'; |
| 3 | + import ProjectSwitcher from './ProjectSwitcher.svelte'; |
| 4 | + import RemoveProjectButton from './RemoveProjectButton.svelte'; |
| 5 | + import notFoundSvg from '$lib/assets/illustrations/not-found.svg?raw'; |
| 6 | + import { ProjectService } from '$lib/backend/projects'; |
| 7 | + import InfoMessage from '$lib/shared/InfoMessage.svelte'; |
| 8 | + import Spacer from '$lib/shared/Spacer.svelte'; |
| 9 | + import { getContext } from '$lib/utils/context'; |
| 10 | + import Button from '@gitbutler/ui/Button.svelte'; |
| 11 | +
|
| 12 | + const projectService = getContext(ProjectService); |
| 13 | + const id = projectService.getLastOpenedProject(); |
| 14 | + const projectPromise = id |
| 15 | + ? projectService.getProject(id, true) |
| 16 | + : Promise.reject('Failed to get project'); |
| 17 | +
|
| 18 | + let deleteSucceeded: boolean | undefined = $state(undefined); |
| 19 | + let isDeleting = $state(false); |
| 20 | +
|
| 21 | + async function stopTracking(id: string) { |
| 22 | + isDeleting = true; |
| 23 | + deleteProject: { |
| 24 | + try { |
| 25 | + await projectService.deleteProject(id); |
| 26 | + } catch (e) { |
| 27 | + deleteSucceeded = false; |
| 28 | + break deleteProject; |
| 29 | + } |
| 30 | + deleteSucceeded = true; |
| 31 | + } |
| 32 | + isDeleting = false; |
| 33 | + } |
| 34 | +
|
| 35 | + async function locate(id: string) { |
| 36 | + await projectService.relocateProject(id); |
| 37 | + } |
| 38 | +
|
| 39 | + function getDeletionStatusMessage(repoName: string) { |
| 40 | + if (deleteSucceeded === undefined) return null; |
| 41 | + if (deleteSucceeded) return `Project "${repoName}" successfully deleted`; |
| 42 | + return `Failed to delete "${repoName}" project`; |
| 43 | + } |
| 44 | +</script> |
| 45 | + |
| 46 | +<DecorativeSplitView img={notFoundSvg}> |
| 47 | + <div class="container" data-tauri-drag-region> |
| 48 | + {#if deleteSucceeded === undefined} |
| 49 | + {#await projectPromise then project} |
| 50 | + <div class="text-content"> |
| 51 | + <h2 class="title-text text-18 text-body text-bold" data-tauri-drag-region> |
| 52 | + Can’t find "{project.title}" |
| 53 | + </h2> |
| 54 | + |
| 55 | + <p class="description-text text-13 text-body"> |
| 56 | + Sorry, we can't find the project you're looking for. |
| 57 | + <br /> |
| 58 | + It might have been removed or doesn't exist. |
| 59 | + <button class="check-again-btn" onclick={() => location.reload()}>Click here</button> |
| 60 | + to check again. |
| 61 | + <br /> |
| 62 | + The current project path: <span class="code-string">{project.path}</span> |
| 63 | + </p> |
| 64 | + </div> |
| 65 | + |
| 66 | + <div class="button-container"> |
| 67 | + <Button |
| 68 | + type="button" |
| 69 | + style="pop" |
| 70 | + kind="solid" |
| 71 | + onclick={async () => await locate(project.id)}>Locate project…</Button |
| 72 | + > |
| 73 | + <RemoveProjectButton |
| 74 | + noModal |
| 75 | + {isDeleting} |
| 76 | + onDeleteClicked={async () => await stopTracking(project.id)} |
| 77 | + /> |
| 78 | + </div> |
| 79 | + |
| 80 | + {#if deleteSucceeded !== undefined} |
| 81 | + <InfoMessage filled outlined={false} style="success" icon="info"> |
| 82 | + <svelte:fragment slot="content" |
| 83 | + >{getDeletionStatusMessage(project.title)}</svelte:fragment |
| 84 | + > |
| 85 | + </InfoMessage> |
| 86 | + {/if} |
| 87 | + {:catch} |
| 88 | + <div class="text-content"> |
| 89 | + <h2 class="title-text text-18 text-body text-bold">Can’t find project</h2> |
| 90 | + </div> |
| 91 | + {/await} |
| 92 | + {/if} |
| 93 | + |
| 94 | + <Spacer dotted margin={0} /> |
| 95 | + <ProjectSwitcher /> |
| 96 | + </div> |
| 97 | +</DecorativeSplitView> |
| 98 | + |
| 99 | +<style lang="postcss"> |
| 100 | + .container { |
| 101 | + display: flex; |
| 102 | + flex-direction: column; |
| 103 | + gap: 20px; |
| 104 | + } |
| 105 | +
|
| 106 | + .button-container { |
| 107 | + display: flex; |
| 108 | + gap: 8px; |
| 109 | + } |
| 110 | +
|
| 111 | + .text-content { |
| 112 | + display: flex; |
| 113 | + flex-direction: column; |
| 114 | + gap: 12px; |
| 115 | + } |
| 116 | +
|
| 117 | + .title-text { |
| 118 | + color: var(--clr-scale-ntrl-30); |
| 119 | + /* margin-bottom: 12px; */ |
| 120 | + } |
| 121 | +
|
| 122 | + .description-text { |
| 123 | + color: var(--clr-text-2); |
| 124 | + line-height: 1.6; |
| 125 | + } |
| 126 | +
|
| 127 | + .check-again-btn { |
| 128 | + text-decoration: underline; |
| 129 | + } |
| 130 | +</style> |
0 commit comments