|
1 | 1 | <script lang="ts"> |
2 | | - import { base } from '$app/paths'; |
3 | 2 | import { page } from '$app/state'; |
4 | 3 | import { registerCommands, updateCommandGroupRanks } from '$lib/commandCenter'; |
5 | 4 | import { |
|
27 | 26 | import { goto } from '$app/navigation'; |
28 | 27 | import { Button } from '$lib/elements/forms'; |
29 | 28 | import Avatar from '$lib/components/avatar.svelte'; |
| 29 | + import { resolveRoute, withPath } from '$lib/stores/navigation'; |
| 30 | + import type { PageProps } from './$types'; |
30 | 31 |
|
31 | | - export let data; |
| 32 | + const { data }: PageProps = $props(); |
32 | 33 |
|
33 | | - let offset = 0; |
| 34 | + let offset = $state(0); |
34 | 35 |
|
35 | | - const project = page.params.project; |
| 36 | + const createFunctionsUrl = resolveRoute( |
| 37 | + '/(console)/project-[region]-[project]/functions/create-function', |
| 38 | + { |
| 39 | + ...page.params |
| 40 | + } |
| 41 | + ); |
| 42 | +
|
| 43 | + const isLimited = $derived(isServiceLimited('functions', $organization, data.functions.total)); |
36 | 44 |
|
37 | 45 | onMount(async () => { |
38 | 46 | const from = page.url.searchParams.get('from'); |
|
42 | 50 | case 'template': { |
43 | 51 | const template = page.url.searchParams.get('template'); |
44 | 52 | const templateConfig = page.url.searchParams.get('templateConfig'); |
45 | | - goto( |
46 | | - `${base}/project-${page.params.region}-${project}/functions/create-function/template-${template}?templateConfig=${templateConfig}` |
| 53 | + const templateUrl = resolveRoute( |
| 54 | + '/(console)/project-[region]-[project]/functions/create-function/template-[template]', |
| 55 | + { |
| 56 | + ...page.params, |
| 57 | + template |
| 58 | + } |
47 | 59 | ); |
| 60 | + await goto(withPath(templateUrl, `?templateConfig=${templateConfig}`)); |
48 | 61 | break; |
49 | 62 | } |
50 | 63 | case 'cover': |
51 | | - goto( |
52 | | - `${base}/project-${page.params.region}-${project}/functions/create-function` |
53 | | - ); |
| 64 | + await goto(createFunctionsUrl); |
54 | 65 | break; |
55 | 66 | } |
56 | 67 | } |
|
60 | 71 | return toLocaleDateTime(parseExpression(func.schedule, { utc: true }).next().toString()); |
61 | 72 | } |
62 | 73 |
|
63 | | - $: $registerCommands([ |
64 | | - { |
65 | | - label: 'Create function', |
66 | | - callback: () => |
67 | | - goto(`${base}/project-${page.params.region}-${project}/functions/create-function`), |
68 | | - keys: ['c'], |
69 | | - disabled: |
70 | | - $wizard.show || |
71 | | - isServiceLimited('functions', $organization, data.functions?.total) || |
72 | | - !$canWriteFunctions, |
73 | | - icon: IconPlus, |
74 | | - group: 'functions' |
75 | | - } |
76 | | - ]); |
| 74 | + $effect(() => { |
| 75 | + $registerCommands([ |
| 76 | + { |
| 77 | + label: 'Create function', |
| 78 | + callback: () => goto(createFunctionsUrl), |
| 79 | + keys: ['c'], |
| 80 | + disabled: |
| 81 | + $wizard.show || |
| 82 | + isServiceLimited('functions', $organization, data.functions?.total) || |
| 83 | + !$canWriteFunctions, |
| 84 | + icon: IconPlus, |
| 85 | + group: 'functions' |
| 86 | + } |
| 87 | + ]); |
| 88 | + }); |
77 | 89 |
|
78 | | - $updateCommandGroupRanks({ functions: 1000 }); |
| 90 | + $effect(() => { |
| 91 | + $updateCommandGroupRanks({ functions: 1000 }); |
| 92 | + }); |
79 | 93 | </script> |
80 | 94 |
|
81 | 95 | <Container> |
82 | 96 | <Layout.Stack direction="row" justifyContent="space-between"> |
83 | 97 | <SearchQuery placeholder="Search by name or ID" /> |
84 | 98 |
|
85 | | - <Button href={`${base}/project-${page.params.region}-${project}/functions/create-function`}> |
86 | | - <Icon icon={IconPlus} slot="start" /> |
87 | | - Create function |
88 | | - </Button> |
| 99 | + <Tooltip disabled={!isLimited}> |
| 100 | + <div> |
| 101 | + <Button disabled={isLimited} href={createFunctionsUrl}> |
| 102 | + <Icon icon={IconPlus} slot="start" /> |
| 103 | + Create function |
| 104 | + </Button> |
| 105 | + </div> |
| 106 | + <svelte:fragment slot="tooltip"> |
| 107 | + You have reached the maximum number of functions for your plan. |
| 108 | + </svelte:fragment> |
| 109 | + </Tooltip> |
89 | 110 | </Layout.Stack> |
90 | 111 |
|
91 | 112 | {#if data.functions.total} |
|
95 | 116 | event="functions" |
96 | 117 | total={data.functions.total} |
97 | 118 | service="functions" |
98 | | - on:click={() => |
99 | | - goto(`${base}/project-${page.params.region}-${project}/functions/create-function`)}> |
| 119 | + on:click={() => goto(createFunctionsUrl)}> |
100 | 120 | {#each data.functions.functions as func (func.$id)} |
101 | 121 | <GridItem1 |
102 | | - href={`${base}/project-${page.params.region}-${project}/functions/function-${func.$id}`}> |
| 122 | + href={resolveRoute( |
| 123 | + '/(console)/project-[region]-[project]/functions/function-[function]', |
| 124 | + { |
| 125 | + ...page.params, |
| 126 | + function: func.$id |
| 127 | + } |
| 128 | + )}> |
103 | 129 | <svelte:fragment slot="title"> |
104 | 130 | <Layout.Stack gap="l" alignItems="center" direction="row" inline> |
105 | 131 | <Avatar alt={func.name} size="m"> |
|
135 | 161 | <EmptySearch hidePages bind:search={data.search} target="functions"> |
136 | 162 | <Button |
137 | 163 | secondary |
138 | | - href={`${base}/project-${page.params.region}-${page.params.project}/functions`}> |
| 164 | + href={resolveRoute('/(console)/project-[region]-[project]/functions', { |
| 165 | + ...page.params |
| 166 | + })}> |
139 | 167 | Clear search |
140 | 168 | </Button> |
141 | 169 | </EmptySearch> |
|
145 | 173 | allowCreate={$canWriteFunctions} |
146 | 174 | href="https://appwrite.io/docs/products/functions" |
147 | 175 | target="function" |
148 | | - on:click={() => |
149 | | - goto( |
150 | | - `${base}/project-${page.params.region}-${project}/functions/create-function` |
151 | | - )} /> |
| 176 | + on:click={() => goto(createFunctionsUrl)} /> |
152 | 177 | {/if} |
153 | 178 | </Container> |
0 commit comments