diff --git a/src/routes/card/+page.svelte b/src/routes/card/+page.svelte deleted file mode 100644 index ee82e0700..000000000 --- a/src/routes/card/+page.svelte +++ /dev/null @@ -1,7 +0,0 @@ - - - diff --git a/src/routes/card/+page.ts b/src/routes/card/+page.ts index bbeeb2f69..209eeb5aa 100644 --- a/src/routes/card/+page.ts +++ b/src/routes/card/+page.ts @@ -5,4 +5,6 @@ export async function load({ parent }) { if (!isCloud) throw redirect(303, '/'); const { account } = await parent(); if (!account) throw redirect(303, '/login'); + + throw redirect(303, `/card/${account.$id}`); } diff --git a/src/routes/card/Card.svelte b/src/routes/card/Card.svelte index 59c418716..8c5e91ff6 100644 --- a/src/routes/card/Card.svelte +++ b/src/routes/card/Card.svelte @@ -12,15 +12,11 @@ import { windowFocusStore } from '$lib/stores/windowFocus'; import { spring } from 'svelte/motion'; - import { getCardImgUrls } from './helpers'; - import { VARS } from '$lib/system'; - import { page } from '$app/stores'; let cardEl: HTMLDivElement | undefined; export let active = false; export let isFlipped = false; - export let userId: string; - export let frontImgBase64: string | undefined = undefined; + export let base64: { front: string; back: string }; let interacting = false; @@ -230,9 +226,6 @@ --angle: ${angle}deg; --center: ${$centerProximity}; `; - - const endpoint = VARS.APPWRITE_ENDPOINT ?? `${$page.url.origin}/v1`; - const { frontImg, backImg } = getCardImgUrls(userId, endpoint); @@ -251,7 +244,7 @@ }}>
The back of the Card {/each}
- The front of the card + The front of the card
diff --git a/src/routes/card/[uid]/+page.svelte b/src/routes/card/[uid]/+page.svelte index bd7a0c4a2..41dab1b5b 100644 --- a/src/routes/card/[uid]/+page.svelte +++ b/src/routes/card/[uid]/+page.svelte @@ -1,7 +1,519 @@ - + + + {seo.title} + + + +
+
+

+ {title} + +

+ +
+ {#if variant === 'owner'} +
+ + Cloud Beta hoodies + Cloud Beta hoodies +
+ {/if} +
+
+

Cloud is live in public

+

Beta

+
+

+ {#if variant === 'owner'} + Share your Cloud card and you may win an exclusive Cloud hoodie! + {:else} + Create your Cloud account and unlock your exclusive card! + {/if} +

+ {#if variant === 'external'} + Claim your card + {/if} +
+
+ The front of the card +
    +
  • + + +
  • + {#if variant === 'owner'} +
  • + +
  • + {/if} +
  • + +
  • +
+ +
+
+ {#if !cardActive} +
+ +
+ {/if} + {#if browser} + + {/if} +
+ {#if cardActive} +
(cardActive = false)} + on:keydown={() => { + /* no-op */ + }} + transition:fade /> + {/if} +
+ +
+
+ + + Get Embed Code +
+ +
+ + + +
+ + diff --git a/src/routes/card/[uid]/+page.ts b/src/routes/card/[uid]/+page.ts index 03153158f..5ed45e219 100644 --- a/src/routes/card/[uid]/+page.ts +++ b/src/routes/card/[uid]/+page.ts @@ -1,25 +1,33 @@ import { VARS } from '$lib/system.js'; import { redirect } from '@sveltejs/kit'; -import { getCardImgUrls } from '../helpers.js'; -export const ssr = false; +function getCardImgUrls(userId: string, endpoint: string) { + const resolved = endpoint; -function urlContentToDataUri(url) { - return fetch(url) - .then((response) => response.blob()) - .then( - (blob) => - new Promise((callback) => { - const reader = new FileReader(); - reader.onload = function () { - callback(this.result); - }; - reader.readAsDataURL(blob); - }) - ); + const frontImg = `${resolved}/cards/cloud?userId=${userId}`; + const backImg = `${resolved}/cards/cloud-back?userId=${userId}`; + const ogImg = `${resolved}/cards/cloud-og?userId=${userId}`; + + return { frontImg, backImg, ogImg }; } -export async function load({ params, url }) { +async function urlContentToDataUri(url: string): Promise { + const res = await fetch(url); + const blob = await res.blob(); + + return await new Promise((callback) => { + const reader = new FileReader(); + reader.onload = function () { + if (typeof this.result !== 'string') return ''; + callback(this.result); + }; + reader.readAsDataURL(blob); + }); +} + +export async function load({ params, url, parent }) { + const { account } = await parent(); + const userId = params.uid; const endpoint = VARS.APPWRITE_ENDPOINT ?? `${url.origin}/v1`; const { frontImg, backImg } = getCardImgUrls(userId, endpoint); @@ -32,6 +40,14 @@ export async function load({ params, url }) { return { userId: params.uid, - frontBase64: await urlContentToDataUri(frontImg) + base64: { + front: await urlContentToDataUri(frontImg), + back: await urlContentToDataUri(backImg) + }, + isOwner: account && account.$id === userId, + imgUrls: { + frontImg, + backImg + } }; } diff --git a/src/routes/card/display.svelte b/src/routes/card/display.svelte deleted file mode 100644 index dcc27eedc..000000000 --- a/src/routes/card/display.svelte +++ /dev/null @@ -1,538 +0,0 @@ - - - - - {seo.title} - - - - - - - - - - - - - - -
-
-

- {title} - -

- -
- {#if variant === 'owner'} -
- - Cloud Beta hoodies - Cloud Beta hoodies -
- {/if} -
-
-

Cloud is live in public

-

Beta

-
-

- {#if variant === 'owner'} - Share your Cloud card and you may win an exclusive Cloud hoodie! - {:else} - Create your Cloud account and unlock your exclusive card! - {/if} -

- {#if variant === 'external'} - Claim your card - {/if} -
-
- The front of the card -
    -
  • - - -
  • - {#if variant === 'owner'} -
  • - -
  • - {/if} -
  • - -
  • -
- -
-
- {#if !cardActive} -
- -
- {/if} - {#if browser} - - {/if} -
- {#if cardActive} -
(cardActive = false)} - on:keydown={() => { - /* no-op */ - }} - transition:fade /> - {/if} -
- -
-
- - - Get Embed Code -
- -
- - - -
- - diff --git a/src/routes/card/helpers.ts b/src/routes/card/helpers.ts deleted file mode 100644 index e59c305f9..000000000 --- a/src/routes/card/helpers.ts +++ /dev/null @@ -1,9 +0,0 @@ -export function getCardImgUrls(userId: string, endpoint: string) { - const resolved = endpoint; - - const frontImg = `${resolved}/cards/cloud?userId=${userId}`; - const backImg = `${resolved}/cards/cloud-back?userId=${userId}`; - const ogImg = `${resolved}/cards/cloud-og?userId=${userId}`; - - return { frontImg, backImg, ogImg }; -}