diff --git a/package.json b/package.json index 1d895f3..2a94dfd 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "tslib": "^2.6.2", "typescript": "^5.3.3", "vite": "^4.5.1", + "vite-plugin-tailwind-purgecss": "^0.2.0", "vitest": "^0.25.8", "zod": "^3.22.4" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 01ffb56..0f45dc7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -130,6 +130,9 @@ devDependencies: vite: specifier: ^4.5.1 version: 4.5.1(@types/node@20.10.5) + vite-plugin-tailwind-purgecss: + specifier: ^0.2.0 + version: 0.2.0(vite@4.5.1) vitest: specifier: ^0.25.8 version: 0.25.8 @@ -1658,6 +1661,11 @@ packages: hasBin: true dev: false + /commander@10.0.1: + resolution: {integrity: sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==} + engines: {node: '>=14'} + dev: true + /commander@4.1.1: resolution: {integrity: sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==} engines: {node: '>= 6'} @@ -2224,6 +2232,17 @@ packages: once: 1.4.0 path-is-absolute: 1.0.1 + /glob@8.1.0: + resolution: {integrity: sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==} + engines: {node: '>=12'} + dependencies: + fs.realpath: 1.0.0 + inflight: 1.0.6 + inherits: 2.0.4 + minimatch: 5.1.6 + once: 1.4.0 + dev: true + /global@4.4.0: resolution: {integrity: sha512-wv/LAoHdRE3BeTGz53FAamhGlPLhlssK45usmGFThIi4XqnBmjKQ16u+RNbP7WvigRZDxUsM0J3gcQ5yicaL0w==} dependencies: @@ -2679,6 +2698,13 @@ packages: dependencies: brace-expansion: 1.1.11 + /minimatch@5.1.6: + resolution: {integrity: sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==} + engines: {node: '>=10'} + dependencies: + brace-expansion: 2.0.1 + dev: true + /minimatch@9.0.3: resolution: {integrity: sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==} engines: {node: '>=16 || 14 >=14.17'} @@ -3153,6 +3179,16 @@ packages: engines: {node: '>=6'} dev: true + /purgecss@6.0.0-alpha.0: + resolution: {integrity: sha512-UC7d7uIyZsky+srEsSXny9BkbTcVn3ZtBCNX3rW3DsqJKhvUXFRpufA4ktcHzWF0+JLZgmsqjUm/8R82x9bHpw==} + hasBin: true + dependencies: + commander: 10.0.1 + glob: 8.1.0 + postcss: 8.4.32 + postcss-selector-parser: 6.0.14 + dev: true + /qs@6.11.2: resolution: {integrity: sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==} engines: {node: '>=0.6'} @@ -3836,6 +3872,16 @@ packages: /util-deprecate@1.0.2: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} + /vite-plugin-tailwind-purgecss@0.2.0(vite@4.5.1): + resolution: {integrity: sha512-6Q+SaalUd0t3BOIIiCQPlbZQuYARVgjoC78X+fLbQJqIEy/9fC58aQgHMgi+CmYfVfZmJToA8YiLueSGEo2mng==} + peerDependencies: + vite: ^4.1.1 || ^5.0.0 + dependencies: + estree-walker: 3.0.3 + purgecss: 6.0.0-alpha.0 + vite: 4.5.1(@types/node@20.10.5) + dev: true + /vite@4.5.1(@types/node@20.10.5): resolution: {integrity: sha512-AXXFaAJ8yebyqzoNB9fu2pHoo/nWX+xZlaRwoeYUxEqBO+Zj4msE5G+BhGBll9lYEKv9Hfks52PAF2X7qDYXQA==} engines: {node: ^14.18.0 || >=16.0.0} diff --git a/src/routes/dashboard/[slug]/+page.ts b/src/routes/dashboard/[slug]/+page.ts index 480f628..3abf30e 100644 --- a/src/routes/dashboard/[slug]/+page.ts +++ b/src/routes/dashboard/[slug]/+page.ts @@ -18,6 +18,32 @@ export const load = async ({ parent, data, depends, url, params: { slug } }) => const scriptsForm = data.scriptsForm const newScriptForm = data.newScriptForm + async function getSubscriptions(product: string) { + const { + data, + count, + error: err + } = await supabaseClient + .schema("profiles") + .from("subscription") + .select("id, price, cancel", { count: "estimated" }) + .eq("product", product) + + if (err) { + console.error(err) + throw error( + 500, + `Server error, this is probably not an issue on your end! - SELECT product failed + Error code: ${err.code} + Error hint: ${err.hint} + Error details: ${err.details} + Error hint: ${err.message}` + ) + } + + return { data, count } + } + async function getPrices() { const { data, error: err } = await supabaseClient .schema("scripts") @@ -66,17 +92,38 @@ export const load = async ({ parent, data, depends, url, params: { slug } }) => ) } - const result = data.map((product) => { - return { + const result: { + id: string + user_id: string + name: string + username: string + bundle: string | null + script: string | null + active: boolean + subs: { + id: string + price: string + cancel: boolean + }[] + subCount: number + }[] = [] + + for (let i = 0; i < data.length; i++) { + const product = data[i] + const subs = await getSubscriptions(product.id) + result.push({ id: product.id, user_id: product.user_id, name: product.name, username: product.bundles?.username ?? product.scripts?.protected.username ?? "", bundle: product.bundle, script: product.script, - active: product.active - } - }) + active: product.active, + subs: subs.data, + subCount: subs.count ?? 0 + }) + } + return result } diff --git a/src/routes/subscriptions/+page.svelte b/src/routes/subscriptions/+page.svelte index c54af81..4ed8d6f 100644 --- a/src/routes/subscriptions/+page.svelte +++ b/src/routes/subscriptions/+page.svelte @@ -84,6 +84,13 @@ userLocale = navigator.language }) + function dateDiff(start: string, end: string) { + const dateStart = new Date(start).getFullYear() + const dateEnd = new Date(end).getFullYear() + + return dateEnd - dateStart + } + const headTitle = "Subscriptions - WaspScripts" const headDescription = "Get access to exclusive scripts. With access to premium scripts you have scripts for nearly all skills in OSRS." @@ -143,8 +150,13 @@ {#each profile.subscription as subscription} {@const price = getPrice(subscription.price, prices)} - {#await getBundle(subscription.product) then bundle} + {#await getBundle(subscription.product)} + ... + {:then bundle} {#if bundle} + {@const isTenYearSub = + bundle.name.includes("Legacy") && + dateDiff(subscription.date_start, subscription.date_end) > 9}
@@ -169,11 +181,23 @@ - {#if price} {getPriceAmount(price)} {:else} ... {/if} + {#if isTenYearSub} + - + {:else if price} + {getPriceAmount(price)} + {:else} + ... + {/if} - {#if price} {getPriceIntervalEx(price)} {:else} ... {/if} + {#if isTenYearSub} + - + {:else if price} + {getPriceIntervalEx(price)} + {:else} + ... + {/if} @@ -185,29 +209,45 @@ - { - subsform.setAttribute( - "action", - "?/subscriptions&product=" + subscription.subscription - ) - subsform.requestSubmit() - }} - > - - {subscription.cancel ? "Cancel" : "Renew"} - - + {#if isTenYearSub} + + + {subscription.cancel ? "Cancel" : "Renew"} + + + {:else} + { + subsform.setAttribute( + "action", + "?/subscriptions&product=" + subscription.subscription + ) + subsform.requestSubmit() + }} + > + + {subscription.cancel ? "Cancel" : "Renew"} + + + {/if} {#if bundle.open} - + {#each bundle.scripts as script} @@ -231,7 +271,9 @@ {/if} {:else} - {#await getScript(subscription.product) then script} + {#await getScript(subscription.product)} + ... + {:then script} {#if script} @@ -306,34 +348,34 @@ {#each bundles as bundle, i} - - -
-
{bundle.name}
-
by {bundle.username}
-
-
- - - - + {#if bundle.active} + + +
+
{bundle.name}
+
by {bundle.username}
+
+
- - {#if bundle.active} {getCurrentPrice(bundle.prices)} {:else}-{/if} - + + + + + + {#if bundle.active} {getCurrentPrice(bundle.prices)} {:else}-{/if} + - - {#if bundle.active} +
{#each bundle.prices as price, j}
- {:else} - Unavailable - {/if} -
- - - {#if bundle.active} - - {:else} -
Checkout
- {/if} -
-
- {#if bundle.open} - - + + + + {#if bundle.active} + + {:else} +
Checkout
+ {/if} +
+ {#if bundle.open} + + + + {/if} {/if} {/each} {#each scripts as script, i} - - -
-
{script.name}
-
by {script.username}
-
-
- - - - - - {getCurrentPrice(script.prices)} - - - {#if script.active} -
- {#each script.prices as price, j} - - {/each} + {#if script.active} +
+ +
+
{script.name}
+
by {script.username}
- {:else} - Unavailable - {/if} -
+ + + + + + + {getCurrentPrice(script.prices)} + + + {#if script.active} +
+ {#each script.prices as price, j} + + {/each} +
+ {:else} + Unavailable + {/if} +
- - {#if script.active} + - {:else} -
Checkout
- {/if} -
-
+ + + {/if} {/each}
- - - {#each bundle.scripts as script} - - - - {/each} - -
-
- - {script.title} -
-
-
+ + + {#each bundle.scripts as script} + + + + {/each} + +
+
+ + {script.title} +
+
+
diff --git a/src/routes/subscriptions/+page.ts b/src/routes/subscriptions/+page.ts index 07ab2f6..9e6ccf6 100644 --- a/src/routes/subscriptions/+page.ts +++ b/src/routes/subscriptions/+page.ts @@ -2,8 +2,9 @@ import type { Prices, ProductEx, ScriptSimple } from "$lib/types/collection" import { error } from "@sveltejs/kit" export const load = async ({ parent, data }) => { + const { supabaseClient } = await parent() + async function getPrices() { - const { supabaseClient } = await parent() const { data, error: err } = await supabaseClient .schema("scripts") .from("prices") @@ -29,7 +30,6 @@ export const load = async ({ parent, data }) => { } async function getProducts() { - const { supabaseClient } = await parent() const { data, error: err } = await supabaseClient .schema("scripts") .from("products") @@ -68,7 +68,6 @@ export const load = async ({ parent, data }) => { } async function getScripts() { - const { supabaseClient } = await parent() const { data, error: err } = await supabaseClient .schema("scripts") .from("scripts") @@ -94,7 +93,6 @@ export const load = async ({ parent, data }) => { } async function getBundles() { - const { supabaseClient } = await parent() const { data, error: err } = await supabaseClient .schema("scripts") .from("bundles") diff --git a/vite.config.ts b/vite.config.ts index c9af058..3e3a075 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,8 +1,9 @@ import { sveltekit } from "@sveltejs/kit/vite" import { defineConfig } from "vitest/config" +import { purgeCss } from "vite-plugin-tailwind-purgecss" export default defineConfig({ - plugins: [sveltekit()], + plugins: [sveltekit(), purgeCss()], test: { include: ["src/**/*.{test,spec}.{js,ts}"] }