Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions src/routes/(console)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { database, checkForDatabaseBackupPolicies } from '$lib/stores/database';
import { newOrgModal, organization } from '$lib/stores/organization';
import { wizard } from '$lib/stores/wizard';
import { afterUpdate, onMount } from 'svelte';
import { onMount } from 'svelte';
import { loading } from '$routes/store';
import { requestedMigration } from '../store';
import Create from './createOrganization.svelte';
Expand Down Expand Up @@ -280,10 +280,12 @@
}
}

database.subscribe(async (database) => {
if (!database || !page.params.region || !page.params.project) return;
// the component checks `isCloud` internally.
await checkForDatabaseBackupPolicies(page.params.region, page.params.project, database);
onMount(() => {
return database.subscribe(async (database) => {
if (!database || !page.params.region || !page.params.project) return;
// the component checks `isCloud` internally.
await checkForDatabaseBackupPolicies(page.params.region, page.params.project, database);
});
});
Comment on lines +283 to 289
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Two separate onMount blocks in the same component

There are now two onMount calls in this component (lines 253 and 283). While Svelte allows multiple onMount registrations, having two separate blocks for the same component lifecycle event makes the initialization flow harder to follow. The database.subscribe setup could be placed inside the existing onMount block at line 253 to keep all mounting logic in one place.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


let currentOrganizationId = null;
Expand All @@ -293,18 +295,21 @@
if (isCloud) {
currentOrganizationId = org.$id;
checkForEnterpriseTrial(org);
await checkForUsageLimit(org);
checkForMarkedForDeletion(org);
await checkForNewDevUpgradePro(org);

if (org?.billingPlanDetails.requiresPaymentMethod) {
await paymentExpired(org);
await checkPaymentAuthorizationRequired(org);
const billingChecks: Promise<unknown>[] = [
checkForUsageLimit(org),
checkForNewDevUpgradePro(org)
];

if (org?.billingPlanDetails.requiresPaymentMethod) {
billingChecks.push(paymentExpired(org), checkPaymentAuthorizationRequired(org));
if (org?.billingTrialDays) {
calculateTrialDay(org);
}
}

await Promise.all(billingChecks);
$activeHeaderAlert = headerAlert.getExcluding('impersonation');
}
}
Expand All @@ -317,9 +322,7 @@

$registerSearchers(orgSearcher, projectsSearcher);

afterUpdate(() => {
$activeHeaderAlert = headerAlert.getExcluding('impersonation');
});
$: (void $headerAlert, ($activeHeaderAlert = headerAlert.getExcluding('impersonation')));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Unusual comma-expression reactive pattern

The comma expression (void $headerAlert, ($activeHeaderAlert = ...)) is a non-obvious Svelte pattern. Reading $headerAlert via void purely to register it as a reactive dependency, while performing the actual side-effect in the right-hand operand, is hard to parse at a glance and not idiomatic Svelte. A named reactive block or a dedicated $: if ($headerAlert) form would communicate intent more clearly. There is also a subtle semantic shift from afterUpdate: this reactive declaration fires on component initialization (before any update), whereas afterUpdate only fired after re-renders. On first mount $headerAlert is empty, so getExcluding returns a no-op result — that is harmless today, but the distinction is worth noting for future maintainers.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

</script>

<CommandCenter />
Expand Down
26 changes: 1 addition & 25 deletions src/routes/(console)/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isCloud } from '$lib/system';
import type { LayoutLoad } from './$types';
import type { Account } from '$lib/stores/user';
import { Dependencies } from '$lib/constants';
import { Platform, Query, type Models } from '@appwrite.io/console';
import { Platform, type Models } from '@appwrite.io/console';
import { makePlansMap } from '$lib/helpers/billing';
import { plansInfo as plansInfoStore } from '$lib/stores/billing';
import { normalizeConsoleVariables } from '$lib/helpers/domains';
Expand Down Expand Up @@ -54,7 +54,6 @@ export const load: LayoutLoad = async ({ depends, parent, url }) => {
currentOrgId: undefined,
organizations,
consoleVariables,
allProjectsCount: 0,
plansInfo: plansInfo ?? null,
version: versionData?.version ?? null
};
Expand Down Expand Up @@ -107,28 +106,6 @@ export const load: LayoutLoad = async ({ depends, parent, url }) => {
preferences.organization ??
(organizations.teams.length > 0 ? organizations.teams[0].$id : undefined);

// Load projects for the current organization if one is selected
let projectsCount = 0;
if (currentOrgId) {
try {
projectsCount = (
await sdk.forConsole.projects.list({
queries: [
Query.equal('teamId', currentOrgId),
Query.limit(1),
Query.select(['$id'])
]
})
).total;
} catch (e) {
if (shouldRedirectToVerifyEmail(e)) {
redirect(303, verifyEmailUrl);
}

projectsCount = 0;
}
}

// just in case!
plansInfoStore.set(fallbackPlansInfoArray);

Expand All @@ -139,7 +116,6 @@ export const load: LayoutLoad = async ({ depends, parent, url }) => {
currentOrgId,
organizations,
consoleVariables,
allProjectsCount: projectsCount,
plansInfo: fallbackPlansInfoArray,
version: versionData?.version ?? null
};
Expand Down
Loading