|
35 | 35 | IconReact, |
36 | 36 | IconUnity |
37 | 37 | } from '@appwrite.io/pink-icons-svelte'; |
| 38 | + import type { PageProps } from './$types'; |
38 | 39 | import { getPlatformInfo } from '$lib/helpers/platform'; |
39 | 40 | import CreateProjectCloud from './createProjectCloud.svelte'; |
40 | 41 | import { currentPlan, regions as regionsStore } from '$lib/stores/organization'; |
41 | 42 | import SelectProjectCloud from '$lib/components/billing/alerts/selectProjectCloud.svelte'; |
42 | 43 | import ArchiveProject from '$lib/components/archiveProject.svelte'; |
43 | 44 |
|
44 | | - export let data; |
| 45 | + let { data }: PageProps = $props(); |
45 | 46 |
|
46 | | - let showCreate = false; |
47 | | - let addOrganization = false; |
48 | | - let showSelectProject = false; |
49 | | - let showCreateProjectCloud = false; |
50 | | - let freePlanAlertDismissed = false; |
| 47 | + let showCreate = $state(false); |
| 48 | + let addOrganization = $state(false); |
| 49 | + let showSelectProject = $state(false); |
| 50 | + let showCreateProjectCloud = $state(false); |
| 51 | + let freePlanAlertDismissed = $state(false); |
51 | 52 |
|
52 | | - let searchQuery: SearchQuery; |
| 53 | + let searchQuery: SearchQuery | null = $state(null); |
| 54 | +
|
| 55 | + const projectCreationDisabled = $derived.by(() => { |
| 56 | + return ( |
| 57 | + (isCloud && |
| 58 | + getServiceLimit('projects', null, data.currentPlan) <= data.projects.total) || |
| 59 | + (isCloud && $readOnly && !GRACE_PERIOD_OVERRIDE) || |
| 60 | + !$canWriteProjects |
| 61 | + ); |
| 62 | + }); |
| 63 | +
|
| 64 | + const reachedProjectLimit = $derived.by(() => { |
| 65 | + return ( |
| 66 | + isCloud && getServiceLimit('projects', null, data.currentPlan) <= data.projects.total |
| 67 | + ); |
| 68 | + }); |
| 69 | +
|
| 70 | + const projectsLimit = $derived.by(() => { |
| 71 | + return getServiceLimit('projects', null, data.currentPlan); |
| 72 | + }); |
| 73 | +
|
| 74 | + const projectsToArchive = $derived.by(() => { |
| 75 | + return isCloud |
| 76 | + ? data.projects.projects.filter((project) => project.status === 'archived') |
| 77 | + : []; |
| 78 | + }); |
53 | 79 |
|
54 | 80 | function filterPlatforms(platforms: { name: string; icon: string }[]) { |
55 | 81 | return platforms.filter( |
|
82 | 108 | } |
83 | 109 | } |
84 | 110 |
|
85 | | - $: projectCreationDisabled = |
86 | | - (isCloud && getServiceLimit('projects', null, data.currentPlan) <= data.projects.total) || |
87 | | - (isCloud && $readOnly && !GRACE_PERIOD_OVERRIDE) || |
88 | | - !$canWriteProjects; |
89 | | -
|
90 | | - $: reachedProjectLimit = |
91 | | - isCloud && getServiceLimit('projects', null, data.currentPlan) <= data.projects.total; |
92 | | - $: projectsLimit = getServiceLimit('projects', null, data.currentPlan); |
93 | | -
|
94 | | - $: $registerCommands([ |
95 | | - { |
96 | | - label: 'Create project', |
97 | | - callback: () => { |
98 | | - showCreate = true; |
99 | | - }, |
100 | | - keys: ['c'], |
101 | | - disabled: projectCreationDisabled, |
102 | | - group: 'projects', |
103 | | - icon: IconPlus |
104 | | - } |
105 | | - ]); |
106 | | -
|
107 | 111 | function dismissFreePlanAlert() { |
108 | 112 | freePlanAlertDismissed = true; |
109 | 113 | const notificationId = `freePlanAlert_${data.organization.$id}`; |
|
132 | 136 | return project.status === 'archived'; |
133 | 137 | } |
134 | 138 |
|
135 | | - $: projectsToArchive = isCloud |
136 | | - ? data.projects.projects.filter((project) => project.status === 'archived') |
137 | | - : []; |
138 | | -
|
139 | | - $: activeProjects = data.projects.projects.filter((project) => project.status !== 'archived'); |
140 | 139 | function clearSearch() { |
141 | 140 | searchQuery?.clearInput(); |
142 | 141 | } |
| 142 | +
|
| 143 | + $effect(() => { |
| 144 | + $registerCommands([ |
| 145 | + { |
| 146 | + label: 'Create project', |
| 147 | + callback: () => { |
| 148 | + showCreate = true; |
| 149 | + }, |
| 150 | + keys: ['c'], |
| 151 | + disabled: projectCreationDisabled, |
| 152 | + group: 'projects', |
| 153 | + icon: IconPlus |
| 154 | + } |
| 155 | + ]); |
| 156 | + }); |
143 | 157 | </script> |
144 | 158 |
|
145 | 159 | <SelectProjectCloud |
|
221 | 235 | </Alert.Inline> |
222 | 236 | {/if} |
223 | 237 |
|
224 | | - {#if activeProjects.length > 0} |
| 238 | + {#if data.projects.total > 0} |
225 | 239 | <CardContainer |
226 | 240 | disableEmpty={!$canWriteProjects} |
227 | | - total={activeProjects.length} |
| 241 | + total={data.projects.total} |
228 | 242 | offset={data.offset} |
229 | 243 | on:click={handleCreateProject}> |
230 | | - {#each activeProjects as project} |
| 244 | + {#each data.projects.projects as project} |
231 | 245 | {@const platforms = filterPlatforms( |
232 | 246 | project.platforms.map((platform) => getPlatformInfo(platform.type)) |
233 | 247 | )} |
|
309 | 323 | name="Projects" |
310 | 324 | limit={data.limit} |
311 | 325 | offset={data.offset} |
312 | | - total={activeProjects.length} /> |
| 326 | + total={data.projects.total} /> |
313 | 327 |
|
314 | 328 | <!-- Archived Projects Section --> |
315 | 329 | <ArchiveProject |
|
0 commit comments