|
2 | 2 | import Button from '$lib/Button.svelte'; |
3 | 3 | import { goto } from '$app/navigation'; |
4 | 4 | import { projectPageState } from './state.svelte'; |
| 5 | + import { deleteProject, getProjects } from '$lib/auth'; |
5 | 6 |
|
6 | 7 | const project = projectPageState.project; |
7 | 8 |
|
|
35 | 36 | function openHackatimeAccountModal() { |
36 | 37 | projectPageState.openHackatimeAccountModal = true; |
37 | 38 | } |
| 39 | +
|
| 40 | + let deletingProject = $state(false); |
| 41 | + let showDeleteModal = $state(false); |
| 42 | +
|
| 43 | + function openDeleteModal() { |
| 44 | + showDeleteModal = true; |
| 45 | + } |
| 46 | +
|
| 47 | + function closeDeleteModal() { |
| 48 | + showDeleteModal = false; |
| 49 | + } |
| 50 | +
|
| 51 | + async function handleDeleteProject() { |
| 52 | + if (!projectPageState.project) return; |
| 53 | +
|
| 54 | + deletingProject = true; |
| 55 | + try { |
| 56 | + const result = await deleteProject(projectPageState.project.projectId); |
| 57 | + if (result.success) { |
| 58 | + await goto('/app/projects'); |
| 59 | + } else { |
| 60 | + alert(result.error || 'Failed to delete project'); |
| 61 | + deletingProject = false; |
| 62 | + } |
| 63 | + } catch (err) { |
| 64 | + alert(err instanceof Error ? err.message : 'Failed to delete project'); |
| 65 | + deletingProject = false; |
| 66 | + } |
| 67 | + } |
38 | 68 | </script> |
39 | 69 |
|
40 | 70 | <div class="project-details"> |
|
141 | 171 | {/if} |
142 | 172 | </div> |
143 | 173 |
|
| 174 | +{#if showDeleteModal} |
| 175 | + <div class="modal-overlay" onclick={closeDeleteModal}> |
| 176 | + <div class="modal-box" onclick={(e) => e.stopPropagation()} role="dialog"> |
| 177 | + <div class="modal-content"> |
| 178 | + <h2 class="modal-title">Delete Project?</h2> |
| 179 | + <p class="modal-text"> |
| 180 | + Are you sure you want to delete this project? This action cannot be undone. |
| 181 | + </p> |
| 182 | + <div class="multi-button"> |
| 183 | + <Button label="Cancel" color="blue" onclick={closeDeleteModal} disabled={deletingProject}/> |
| 184 | + <Button label={deletingProject ? "Deleting..." : "Delete"} color="red" onclick={handleDeleteProject} disabled={deletingProject}/> |
| 185 | + </div> |
| 186 | + </div> |
| 187 | + </div> |
| 188 | + </div> |
| 189 | +{/if} |
| 190 | + |
144 | 191 | {#if projectPageState.user && projectPageState.user.hackatimeAccount} |
145 | 192 | {#if projectPageState.project?.submissions && projectPageState.project.submissions.length > 0} |
146 | 193 | {@const latestSubmission = projectPageState.project.submissions[projectPageState.project.submissions.length - 1]} |
|
160 | 207 | <div class="submit-section"> |
161 | 208 | <Button label="EDIT" icon="edit" color="blue" onclick={() => goto(`/app/projects/${projectPageState.project?.projectId}/edit`)}/> |
162 | 209 | <Button label="Submit" onclick={() => goto(`/app/projects/${projectPageState.project?.projectId}/submit`)}/> |
| 210 | + {#if projectPageState.project?.submissions && projectPageState.project.submissions.length === 0} |
| 211 | + <Button label="" icon="remove" color="red" onclick={openDeleteModal} disabled={deletingProject}/> |
| 212 | + {/if} |
163 | 213 | </div> |
164 | 214 | {:else} |
165 | 215 | <div class="submit-section-inital"> |
166 | 216 | <Button label="LINK HACKATIME Project" icon="link" color="blue" onclick={openHackatimeProjectModal}/> |
167 | 217 | <img alt="required!" src="/handdrawn_text/required.png" style="width: 140px;" /> |
168 | 218 | </div> |
| 219 | + {#if projectPageState.project?.submissions && projectPageState.project.submissions.length === 0} |
| 220 | + <div class="submit-section"> |
| 221 | + <Button label="" icon="remove" color="red" onclick={openDeleteModal} disabled={deletingProject}/> |
| 222 | + </div> |
| 223 | + {/if} |
169 | 224 | {/if} |
170 | 225 | {:else} |
171 | 226 | <div class="submit-section-inital"> |
|
552 | 607 | font-size: 16px; |
553 | 608 | } |
554 | 609 | } |
| 610 | +
|
| 611 | + .modal-overlay { |
| 612 | + position: fixed; |
| 613 | + inset: 0; |
| 614 | + background: rgba(0, 0, 0, 0.5); |
| 615 | + display: flex; |
| 616 | + align-items: center; |
| 617 | + justify-content: center; |
| 618 | + z-index: 1000; |
| 619 | + } |
| 620 | +
|
| 621 | + .modal-box { |
| 622 | + position: relative; |
| 623 | + background-image: url("/shapes/shape-bg-1.svg"); |
| 624 | + background-size: 100% 100%; |
| 625 | + background-repeat: no-repeat; |
| 626 | + width: 795px; |
| 627 | + height: 490px; |
| 628 | + max-width: 90vw; |
| 629 | + padding: 30px 37px; |
| 630 | + } |
| 631 | +
|
| 632 | + .modal-content { |
| 633 | + position: relative; |
| 634 | + width: 100%; |
| 635 | + height: 100%; |
| 636 | + display: flex; |
| 637 | + flex-direction: column; |
| 638 | + align-items: center; |
| 639 | + justify-content: space-between; |
| 640 | + } |
| 641 | +
|
| 642 | + .modal-title { |
| 643 | + font-family: "Moga", sans-serif; |
| 644 | + font-size: 44px; |
| 645 | + color: #453b61; |
| 646 | + text-align: center; |
| 647 | + letter-spacing: -0.352px; |
| 648 | + line-height: 1.5; |
| 649 | + margin: 0; |
| 650 | + } |
| 651 | +
|
| 652 | + .modal-text { |
| 653 | + font-family: "PT Sans", sans-serif; |
| 654 | + font-size: 24px; |
| 655 | + color: #453b61; |
| 656 | + text-align: center; |
| 657 | + letter-spacing: -0.264px; |
| 658 | + line-height: 1.5; |
| 659 | + margin: 0; |
| 660 | + } |
| 661 | +
|
| 662 | + .multi-button { |
| 663 | + display: flex; |
| 664 | + gap: 32px; |
| 665 | + } |
| 666 | +
|
| 667 | + @media (max-width: 820px) { |
| 668 | + .modal-content { |
| 669 | + padding: 25px 30px; |
| 670 | + gap: 40px; |
| 671 | + } |
| 672 | +
|
| 673 | + .modal-title { |
| 674 | + font-size: 32px; |
| 675 | + } |
| 676 | +
|
| 677 | + .modal-text { |
| 678 | + font-size: 20px; |
| 679 | + } |
| 680 | + } |
| 681 | +
|
| 682 | + @media (max-width: 480px) { |
| 683 | + .modal-content { |
| 684 | + padding: 20px 25px; |
| 685 | + gap: 30px; |
| 686 | + } |
| 687 | +
|
| 688 | + .modal-title { |
| 689 | + font-size: 24px; |
| 690 | + } |
| 691 | +
|
| 692 | + .modal-text { |
| 693 | + font-size: 16px; |
| 694 | + } |
| 695 | +
|
| 696 | + .multi-button { |
| 697 | + flex-direction: column; |
| 698 | + gap: 16px; |
| 699 | + width: 100%; |
| 700 | + } |
| 701 | + } |
555 | 702 | </style> |
0 commit comments