Skip to content

Commit

Permalink
Merge pull request #1355 from appwrite/fix-page-breaks-on-redirection
Browse files Browse the repository at this point in the history
fix: page breaks on redirection
  • Loading branch information
TorstenDittmann authored Oct 1, 2024
2 parents 1b6d26e + 6b5dcce commit cc160af
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 46 deletions.
1 change: 1 addition & 0 deletions src/lib/helpers/sizeConvertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function calculateSize(bytes: number, decimals = 1, base: 1000 | 1024 = 1
}

export function sizeToBytes(value: number, unit: Size, base = 1000) {
if (typeof value !== 'number') return 0;
const index = sizes.indexOf(unit);
return value * Math.pow(base, index);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function createTimeUnitPair(initialValue = 0) {
{ name: 'Minutes', value: 60 },
{ name: 'Seconds', value: 1 }
];
return { ...createValueUnitPair(initialValue, units), units };
return { ...createValueUnitPair(initialValue || 0, units), units };
}

export function createByteUnitPair(initialValue = 0, base: 1000 | 1024 = 1000) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
let numbers: Models.MockNumber[] = $project?.authMockNumbers ?? [];
let initialNumbers = [];
let projectId: string = $project.$id;
$: initialNumbers = $project?.authMockNumbers?.map((num) => ({ ...num })) ?? [];
$: isSubmitDisabled = JSON.stringify(numbers) === JSON.stringify(initialNumbers);
Expand All @@ -39,7 +38,7 @@
async function updateMockNumbers() {
try {
await sdk.forConsole.projects.updateMockNumbers(projectId, numbers);
await sdk.forConsole.projects.updateMockNumbers($project.$id, numbers);
await invalidate(Dependencies.PROJECT);
addNotification({
type: 'success',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
import { sdk } from '$lib/stores/sdk';
import { project } from '../../store';
const projectId = $project.$id;
let passwordDictionary = $project.authPasswordDictionary ?? false;
let passwordDictionary = $project?.authPasswordDictionary ?? false;
async function updatePasswordDictionary() {
try {
await sdk.forConsole.projects.updateAuthPasswordDictionary(
projectId,
$project.$id,
passwordDictionary
);
await invalidate(Dependencies.PROJECT);
Expand Down Expand Up @@ -56,7 +55,7 @@
</svelte:fragment>

<svelte:fragment slot="actions">
<Button disabled={passwordDictionary === $project.authPasswordDictionary} submit
<Button disabled={passwordDictionary === $project?.authPasswordDictionary} submit
>Update</Button>
</svelte:fragment>
</CardGrid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
import { sdk } from '$lib/stores/sdk';
import { project } from '../../store';
const projectId = $project.$id;
let passwordHistory = $project.authPasswordHistory < 1 ? 5 : $project.authPasswordHistory;
let passwordHistoryEnabled = ($project.authPasswordHistory ?? 0) != 0;
let passwordHistory = $project?.authPasswordHistory < 1 ? 5 : $project?.authPasswordHistory;
let passwordHistoryEnabled = ($project?.authPasswordHistory ?? 0) !== 0;
let initialPasswordHistoryEnabled = passwordHistoryEnabled;
async function updatePasswordHistoryLimit() {
try {
await sdk.forConsole.projects.updateAuthPasswordHistory(
projectId,
$project.$id,
passwordHistoryEnabled ? passwordHistory : 0
);
await invalidate(Dependencies.PROJECT);
Expand Down Expand Up @@ -67,8 +66,8 @@

<svelte:fragment slot="actions">
<Button
disabled={(passwordHistory === $project.authPasswordHistory ||
$project.authPasswordHistory === 0) &&
disabled={(passwordHistory === $project?.authPasswordHistory ||
$project?.authPasswordHistory === 0) &&
initialPasswordHistoryEnabled === passwordHistoryEnabled}
submit>Update</Button>
</svelte:fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { sdk } from '$lib/stores/sdk';
import { project } from '../../store';
let authPersonalDataCheck = $project.authPersonalDataCheck ?? false;
let authPersonalDataCheck = $project?.authPersonalDataCheck ?? false;
async function updatePersonalDataCheck() {
try {
Expand Down Expand Up @@ -50,7 +50,7 @@
</svelte:fragment>

<svelte:fragment slot="actions">
<Button disabled={authPersonalDataCheck === $project.authPersonalDataCheck} submit
<Button disabled={authPersonalDataCheck === $project?.authPersonalDataCheck} submit
>Update</Button>
</svelte:fragment>
</CardGrid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { sdk } from '$lib/stores/sdk';
import { project } from '../../store';
let authSessionAlerts = $project.authSessionAlerts ?? false;
let authSessionAlerts = $project?.authSessionAlerts ?? false;
async function updateSessionAlerts() {
try {
Expand Down Expand Up @@ -46,7 +46,7 @@
</svelte:fragment>

<svelte:fragment slot="actions">
<Button disabled={authSessionAlerts === $project.authSessionAlerts} submit>
<Button disabled={authSessionAlerts === $project?.authSessionAlerts} submit>
Update
</Button>
</svelte:fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
import { sdk } from '$lib/stores/sdk';
import { project } from '../../store';
const projectId = $project.$id;
const { value, unit, baseValue, units } = createTimeUnitPair($project.authDuration);
const { value, unit, baseValue, units } = createTimeUnitPair($project?.authDuration);
const options = units.map((v) => ({ label: v.name, value: v.name }));
async function updateSessionLength() {
try {
await sdk.forConsole.projects.updateAuthDuration(projectId, $baseValue);
await sdk.forConsole.projects.updateAuthDuration($project.$id, $baseValue);
await invalidate(Dependencies.PROJECT);
addNotification({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
import { sdk } from '$lib/stores/sdk';
import { project } from '../../store';
const projectId = $project.$id;
let maxSessions = $project.authSessionsLimit;
let maxSessions = $project?.authSessionsLimit;
async function updateSessionsLimit() {
try {
await sdk.forConsole.projects.updateAuthSessionsLimit(projectId, maxSessions);
await sdk.forConsole.projects.updateAuthSessionsLimit($project.$id, maxSessions);
await invalidate(Dependencies.PROJECT);
addNotification({
Expand Down Expand Up @@ -43,7 +41,7 @@
</svelte:fragment>

<svelte:fragment slot="actions">
<Button disabled={maxSessions === $project.authSessionsLimit} submit>Update</Button>
<Button disabled={maxSessions === $project?.authSessionsLimit} submit>Update</Button>
</svelte:fragment>
</CardGrid>
</Form>
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@
import { sdk } from '$lib/stores/sdk';
import { project } from '../../store';
const projectId = $project.$id;
let isLimited = $project.authLimit !== 0;
let newLimit = isLimited ? $project.authLimit : 100;
let isLimited = $project?.authLimit !== 0;
let newLimit = isLimited ? $project?.authLimit : 100;
$: btnDisabled = (function isBtnDisabled() {
if (
(!isLimited && $project.authLimit === 0) ||
(isLimited && $project.authLimit === newLimit)
(!isLimited && $project?.authLimit === 0) ||
(isLimited && $project?.authLimit === newLimit)
) {
return true;
}
Expand All @@ -28,7 +26,7 @@
async function updateLimit() {
try {
await sdk.forConsole.projects.updateAuthLimit(projectId, isLimited ? newLimit : 0);
await sdk.forConsole.projects.updateAuthLimit($project?.$id, isLimited ? newLimit : 0);
await invalidate(Dependencies.PROJECT);
addNotification({
type: 'success',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@

<script lang="ts">
import { base } from '$app/paths';
import { page } from '$app/stores';
import { Alert, CardGrid, Collapsible, CollapsibleItem, Heading } from '$lib/components';
import { Container } from '$lib/layout';
import { sdk } from '$lib/stores/sdk';
import { project } from '../../store';
import { addNotification } from '$lib/stores/notifications';
import { onMount } from 'svelte';
import EmailVerificationTemplate from './emailVerificationTemplate.svelte';
Expand All @@ -63,7 +61,7 @@
EmailTemplateLocale
} from '@appwrite.io/console';
const projectId = $page.params.project;
export let data;
let emailOpen = 'verification';
$: emailVerificationOpen = emailOpen === 'verification';
Expand All @@ -86,7 +84,7 @@
async function openEmail(type: string) {
type === emailOpen ? (emailOpen = null) : (emailOpen = type);
$emailTemplate = await loadEmailTemplate(projectId, type, 'en');
$emailTemplate = await loadEmailTemplate(data.project.$id, type, 'en');
$baseEmailTemplate = { ...$emailTemplate };
}
Expand All @@ -105,7 +103,7 @@
</div>
</div>

{#if !$project.smtpEnabled}
{#if !data.project.smtpEnabled}
<div class="u-margin-block-start-24">
<Alert
isStandalone
Expand All @@ -114,7 +112,7 @@
buttons={[
{
slot: 'SMTP settings',
href: `${base}/project-${$project.$id}/settings/smtp`
href: `${base}/project-${data.project.$id}/settings/smtp`
}
]}>
<svelte:fragment slot="title">
Expand Down Expand Up @@ -216,7 +214,7 @@
</Collapsible>
</svelte:fragment>
<svelte:fragment slot="actions">
<Button href={`${base}/project-${$project.$id}/settings/smtp`} secondary>
<Button href={`${base}/project-${data.project.$id}/settings/smtp`} secondary>
SMTP settings
</Button>
</svelte:fragment>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { sdk } from '$lib/stores/sdk';
import type { PageLoad } from './$types';

export const load: PageLoad = async () => {
export const load = async () => {
const codes = await sdk.forProject.locale.listCodes();
return {
localeCodes: codes.localeCodes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
$: isButtonDisabled = deepEqual($emailTemplate, $baseEmailTemplate);
$: isSmtpEnabled = $project.smtpEnabled;
$: isSmtpEnabled = $project?.smtpEnabled;
</script>

<Box class="u-position-relative">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import Create from './create.svelte';
import { GRACE_PERIOD_OVERRIDE, isCloud } from '$lib/system';
import { readOnly } from '$lib/stores/billing';
import { project } from '../../store';
import { writable } from 'svelte/store';
import type { Column } from '$lib/helpers/types';
import Table from './table.svelte';
Expand Down Expand Up @@ -199,7 +198,7 @@
{/if}
<Button
secondary
href={`${base}/project-${$project.$id}/functions/function-${$func.$id}/executions/execute-function`}
href={`${base}/project-${$page.params.project}/functions/function-${$func.$id}/executions/execute-function`}
disabled={isCloud && $readOnly && !GRACE_PERIOD_OVERRIDE}>
Execute
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
} from '$lib/elements/table';
import { addNotification } from '$lib/stores/notifications';
import type { PageData } from './$types';
import { project } from '$routes/(console)/project-[project]/store';
import { invalidate } from '$app/navigation';
import { Dependencies } from '$lib/constants';
import { sdk } from '$lib/stores/sdk';
import { toLocaleDateTime } from '$lib/helpers/date';
import type { Column } from '$lib/helpers/types';
import { page } from '$app/stores';
import { canWriteTopics } from '$lib/stores/roles';
export let columns: Column[];
Expand Down Expand Up @@ -75,7 +75,7 @@
<TableBody>
{#each data.topics.topics as topic (topic.$id)}
<TableRowLink
href={`${base}/project-${$project.$id}/messaging/topics/topic-${topic.$id}`}>
href={`${base}/project-${$page.params.project}/messaging/topics/topic-${topic.$id}`}>
{#if $canWriteTopics}
<TableCellCheck bind:selectedIds id={topic.$id} />
{/if}
Expand Down

0 comments on commit cc160af

Please sign in to comment.