Skip to content

Commit

Permalink
fix broken loads
Browse files Browse the repository at this point in the history
  • Loading branch information
ideopunk committed Apr 25, 2024
1 parent a47efd8 commit fb19811
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/lib/components/InternalLink.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
export let href: string;
</script>

<a sveltekit:prefetch {href} class="text-green-theme hover:text-black transition-colors font-bold"
<a data-sveltekit-preload-data {href} class="text-green-theme hover:text-black transition-colors font-bold"
><slot /></a
>
2 changes: 1 addition & 1 deletion src/lib/funcs/collectionsDataTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ function outcomeTransform(outcome: { name: string; probabilities: GoodOutcome |
}

export default function entryTransform(outcomes: Outcomes): TreeData {
return { name: '2022', children: outcomes.map((o) => outcomeTransform(o)) };
return { name: '2024', children: outcomes.map((o) => outcomeTransform(o)) };
}
2 changes: 1 addition & 1 deletion src/lib/funcs/metaculusDataTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function metaculusDataTransform(vals: {
bioX: number;
}): TreeData {
const transformed = {
name: '2022',
name: '2024',
children: [
{
name: 'climate',
Expand Down
2 changes: 1 addition & 1 deletion src/lib/funcs/predictDataTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export default function selfDataTransform(
.flat()
};
});
return { name: '2022', children: ch };
return { name: '2024', children: ch };
}
12 changes: 7 additions & 5 deletions src/routes/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { RequestHandlerOutput } from '@sveltejs/kit';

async function metaculusFetch(question: number): Promise<number> {
if (process.env.NODE_ENV === 'production') {
const res = await fetch(`https://www.metaculus.com/api2/questions/${question}`);
Expand All @@ -22,7 +20,8 @@ function makeRelative(total: number, particular: number, xRisk: number) {
return [roundedParticular, roundedXRisk];
}

export async function load(): Promise<RequestHandlerOutput> {
/** @type {import('./$types').PageServerLoad} */
export async function load(): Promise<any> {
// GET THE DATA
// By 2100 will the human population decrease by at least 10% during any period of 5 years?
const totalQuestion = metaculusFetch(1493);
Expand Down Expand Up @@ -95,7 +94,10 @@ export async function load(): Promise<RequestHandlerOutput> {

console.log('BUILD COMPLETE'); // make sure this only logs during build, not runtime.
return {
vals,
time: new Date().toString()
props: {
vals,
time: new Date().toString(),
test: 'fake'
}
};
}
37 changes: 20 additions & 17 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script lang="ts">
// throw new Error("@migration task: Add data prop (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292707)");
import Details from '$lib/components/details.svelte';
import { browser } from '$app/environment';
Expand All @@ -21,22 +20,26 @@
highlight = e.detail.highlight;
}
export let time: string;
export let vals: {
total: number;
climate: number;
climateX: number;
nano: number;
nanoX: number;
nuke: number;
nukeX: number;
ai: number;
aiX: number;
bio: number;
bioX: number;
export let data: {
props: {
time: string;
vals: {
total: number;
climate: number;
climateX: number;
nano: number;
nanoX: number;
nuke: number;
nukeX: number;
ai: number;
aiX: number;
bio: number;
bioX: number;
}
}
};
let input = metaculusDataTransform(vals);
let input = metaculusDataTransform(data.props.vals);
let chart: SVGSVGElement | null = null;
if (browser) {
Expand Down Expand Up @@ -75,7 +78,7 @@
<div class="flex px-6 lg:px-0 justify-between w-full">
<Legend on:message={handleMessage} />
<div>
<Details {vals} {highlight} />
<Details vals={data.props.vals} {highlight} />
</div>
</div>
<!-- prevent CLS -->
Expand Down Expand Up @@ -114,7 +117,7 @@
<p>
This tree is built from the prediction platform Metaculus's <ExternalLink
href="https://www.metaculus.com/questions/2568">Ragnarok series</ExternalLink
>. It is updated every night (last: {new Date(time).toDateString()}). It tracks predictions
>. It is updated every night (last: {new Date(data.props.time).toDateString()}). It tracks predictions
concerning
<span class="text-yellow-theme font-bold">global catastrophes</span>
and
Expand Down
9 changes: 4 additions & 5 deletions src/routes/collection/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { RequestHandlerOutput } from '@sveltejs/kit';
import estimates from '$lib/data/estimates.json';
import collectionsDataTransform from '$lib/funcs/collectionsDataTransform';

export async function load(): Promise<RequestHandlerOutput> {
let data: {
export async function load(): Promise<any> {
let info: {
title: string;
link: string;
notes: string[];
Expand All @@ -17,13 +16,13 @@ export async function load(): Promise<RequestHandlerOutput> {
}[] = [];

for (const entry of estimates) {
data.push({
info.push({
...collectionsDataTransform(entry.outcomes),
title: entry.title,
notes: entry.notes,
link: entry.link
});
}

return { data, time: new Date().toString() };
return { info, time: new Date().toString() };
}
24 changes: 12 additions & 12 deletions src/routes/collection/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
let width: number;
export let data: {
title: string;
link: string;
notes: string[];
name: string; // the future
children: {
name: string;
children: {
name: string;
}[];
}[];
}[] = [];
info:
{
title: string;
link: string;
notes: string[];
name: string;
children: {
name: string; children: {name: string}[]
}[]
}[]
};
let predictions: { chart: SVGElement; title: string; notes: string[]; link: string }[] = [];
Expand All @@ -33,7 +33,7 @@
// do we want animations?
let classes = mediaQuery.matches || (width && width < 767) ? 'instant' : '';
for (const [ind, entry] of Object.entries(data)) {
for (const [ind, entry] of Object.entries(data.info)) {
// use this later for sharing
const newTree = treeify(entry, {
label: (d) => d.name,
Expand Down
7 changes: 4 additions & 3 deletions svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import adapter from '@sveltejs/adapter-static';

import preprocess from 'svelte-preprocess';

/** @type {import('@sveltejs/kit').Config} */
// /** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: [
preprocess({
postcss: true
})
postcss: true,
}),
preprocess.typescript()
],

kit: {
Expand Down

0 comments on commit fb19811

Please sign in to comment.