|
1 | 1 | <script lang="ts"> |
2 | 2 | import { goto } from '$app/navigation'; |
3 | | - import { base } from '$app/paths'; |
4 | 3 | import { page } from '$app/state'; |
5 | 4 | import { addSubPanel, registerCommands, updateCommandGroupRanks } from '$lib/commandCenter'; |
6 | 5 | import { TeamsPanel, UsersPanel } from '$lib/commandCenter/panels'; |
7 | 6 | import { readOnly } from '$lib/stores/billing'; |
8 | 7 | import { canWriteTeams, canWriteUsers } from '$lib/stores/roles'; |
9 | 8 | import { GRACE_PERIOD_OVERRIDE } from '$lib/system'; |
10 | | - import { project } from '../store'; |
11 | 9 | import { showCreateUser } from './+page.svelte'; |
12 | 10 | import { showCreateTeam } from './teams/+page.svelte'; |
13 | 11 | import { IconPlus } from '@appwrite.io/pink-icons-svelte'; |
| 12 | + import { resolveRoute, withPath } from '$lib/stores/navigation'; |
14 | 13 |
|
15 | | - $: $registerCommands([ |
16 | | - { |
17 | | - label: 'Create user', |
18 | | - callback: async () => { |
19 | | - if (!page.url.pathname.endsWith('auth')) { |
20 | | - await goto(`${base}/project-${$project.region}-${$project.$id}/auth`); |
21 | | - } |
22 | | - showCreateUser.set(true); |
23 | | - }, |
24 | | - keys: page.url.pathname.endsWith('auth') ? ['c'] : ['c', 'u'], |
25 | | - group: 'users', |
26 | | - icon: IconPlus, |
27 | | - rank: page.url.pathname.endsWith('auth') ? 10 : 0, |
28 | | - disabled: ($readOnly && !GRACE_PERIOD_OVERRIDE) || !$canWriteUsers |
29 | | - }, |
30 | | - { |
31 | | - label: 'Create team', |
32 | | - callback: async () => { |
33 | | - if (!page.url.pathname.endsWith('teams')) { |
34 | | - await goto(`${base}/project-${$project.region}-${$project.$id}/auth/teams`); |
35 | | - } |
36 | | - showCreateTeam.set(true); |
| 14 | + let { children } = $props(); |
| 15 | +
|
| 16 | + const authProjectRoute = $derived.by(() => { |
| 17 | + return resolveRoute('/(console)/project-[region]-[project]/auth', { |
| 18 | + ...page.params |
| 19 | + }); |
| 20 | + }); |
| 21 | +
|
| 22 | + $effect(() => { |
| 23 | + $registerCommands([ |
| 24 | + { |
| 25 | + label: 'Create user', |
| 26 | + callback: async () => { |
| 27 | + if (!page.url.pathname.endsWith('auth')) { |
| 28 | + await goto(authProjectRoute); |
| 29 | + } |
| 30 | + showCreateUser.set(true); |
| 31 | + }, |
| 32 | + keys: page.url.pathname.endsWith('auth') ? ['c'] : ['c', 'u'], |
| 33 | + group: 'users', |
| 34 | + icon: IconPlus, |
| 35 | + rank: page.url.pathname.endsWith('auth') ? 10 : 0, |
| 36 | + disabled: ($readOnly && !GRACE_PERIOD_OVERRIDE) || !$canWriteUsers |
37 | 37 | }, |
38 | | - keys: page.url.pathname.endsWith('teams') ? ['c'] : ['c', 't'], |
| 38 | + { |
| 39 | + label: 'Create team', |
| 40 | + callback: async () => { |
| 41 | + if (!page.url.pathname.endsWith('teams')) { |
| 42 | + await goto(withPath(authProjectRoute, '/teams')); |
| 43 | + } |
| 44 | + showCreateTeam.set(true); |
| 45 | + }, |
| 46 | + keys: page.url.pathname.endsWith('teams') ? ['c'] : ['c', 't'], |
39 | 47 |
|
40 | | - group: 'teams', |
41 | | - icon: IconPlus, |
42 | | - rank: page.url.pathname.endsWith('teams') ? 10 : 0, |
43 | | - disabled: ($readOnly && !GRACE_PERIOD_OVERRIDE) || !$canWriteTeams |
44 | | - }, |
45 | | - { |
46 | | - label: 'Go to teams', |
47 | | - keys: ['g', 't'], |
48 | | - callback() { |
49 | | - goto(`${base}/project-${$project.region}-${$project.$id}/auth/teams`); |
| 48 | + group: 'teams', |
| 49 | + icon: IconPlus, |
| 50 | + rank: page.url.pathname.endsWith('teams') ? 10 : 0, |
| 51 | + disabled: ($readOnly && !GRACE_PERIOD_OVERRIDE) || !$canWriteTeams |
50 | 52 | }, |
51 | | - group: 'navigation', |
52 | | - rank: 1, |
53 | | - disabled: page.url.pathname.endsWith('teams') |
54 | | - }, |
55 | | - { |
56 | | - label: 'Go to usage', |
57 | | - keys: ['g', 'u'], |
58 | | - callback() { |
59 | | - goto(`${base}/project-${$project.region}-${$project.$id}/auth/usage`); |
| 53 | + { |
| 54 | + label: 'Go to teams', |
| 55 | + keys: ['g', 't'], |
| 56 | + callback: async () => { |
| 57 | + await goto(withPath(authProjectRoute, '/teams')); |
| 58 | + }, |
| 59 | + group: 'navigation', |
| 60 | + rank: 1, |
| 61 | + disabled: page.url.pathname.endsWith('teams') |
60 | 62 | }, |
61 | | - group: 'navigation', |
62 | | - rank: 1, |
63 | | - disabled: page.url.pathname.endsWith('usage') |
64 | | - }, |
65 | | - { |
66 | | - label: 'Go to security', |
67 | | - keys: ['g', 'e'], |
68 | | - callback() { |
69 | | - goto(`${base}/project-${$project.region}-${$project.$id}/auth/security`); |
| 63 | + { |
| 64 | + label: 'Go to usage', |
| 65 | + keys: ['g', 'u'], |
| 66 | + callback: async () => { |
| 67 | + await goto(withPath(authProjectRoute, '/usage')); |
| 68 | + }, |
| 69 | + group: 'navigation', |
| 70 | + rank: 1, |
| 71 | + disabled: page.url.pathname.endsWith('usage') |
70 | 72 | }, |
71 | | - group: 'navigation', |
72 | | - rank: 1, |
73 | | - disabled: page.url.pathname.endsWith('security') || !$canWriteUsers |
74 | | - }, |
75 | | - { |
76 | | - label: 'Go to settings', |
77 | | - keys: ['g', 's'], |
78 | | - callback() { |
79 | | - goto(`${base}/project-${$project.region}-${$project.$id}/auth/settings`); |
| 73 | + { |
| 74 | + label: 'Go to security', |
| 75 | + keys: ['g', 'e'], |
| 76 | + callback: async () => { |
| 77 | + await goto(withPath(authProjectRoute, '/security')); |
| 78 | + }, |
| 79 | + group: 'navigation', |
| 80 | + rank: 1, |
| 81 | + disabled: page.url.pathname.endsWith('security') || !$canWriteUsers |
80 | 82 | }, |
81 | | - group: 'navigation', |
82 | | - rank: 1, |
83 | | - disabled: page.url.pathname.endsWith('settings') || !$canWriteUsers |
84 | | - }, |
85 | | - { |
86 | | - label: 'Find users', |
87 | | - callback: () => { |
88 | | - addSubPanel(UsersPanel); |
| 83 | + { |
| 84 | + label: 'Go to settings', |
| 85 | + keys: ['g', 's'], |
| 86 | + callback: async () => { |
| 87 | + await goto(withPath(authProjectRoute, '/settings')); |
| 88 | + }, |
| 89 | + group: 'navigation', |
| 90 | + rank: 1, |
| 91 | + disabled: page.url.pathname.endsWith('settings') || !$canWriteUsers |
89 | 92 | }, |
90 | | - group: 'users', |
91 | | - rank: -1 |
92 | | - }, |
93 | | - { |
94 | | - label: 'Find teams', |
95 | | - callback: () => { |
96 | | - addSubPanel(TeamsPanel); |
| 93 | + { |
| 94 | + label: 'Find users', |
| 95 | + callback: () => { |
| 96 | + addSubPanel(UsersPanel); |
| 97 | + }, |
| 98 | + group: 'users', |
| 99 | + rank: -1 |
97 | 100 | }, |
98 | | - group: 'teams', |
99 | | - rank: -1 |
100 | | - } |
101 | | - ]); |
| 101 | + { |
| 102 | + label: 'Find teams', |
| 103 | + callback: () => { |
| 104 | + addSubPanel(TeamsPanel); |
| 105 | + }, |
| 106 | + group: 'teams', |
| 107 | + rank: -1 |
| 108 | + } |
| 109 | + ]); |
| 110 | + }); |
102 | 111 |
|
103 | 112 | // To prioritize the groups! |
104 | | - $: $updateCommandGroupRanks({ users: 300, teams: 200, security: 100, navigation: 50 }); |
| 113 | + $effect(() => { |
| 114 | + $updateCommandGroupRanks({ users: 300, teams: 200, security: 100, navigation: 50 }); |
| 115 | + }); |
105 | 116 | </script> |
106 | 117 |
|
107 | 118 | <svelte:head> |
108 | 119 | <title>Auth - Appwrite</title> |
109 | 120 | </svelte:head> |
110 | 121 |
|
111 | | -<slot /> |
| 122 | +{@render children?.()} |
0 commit comments