feat: hydration

This commit is contained in:
Ax333l 2022-10-21 20:31:18 +02:00
parent a1b893b346
commit 01bc0f2063
No known key found for this signature in database
GPG Key ID: D2B4D85271127D23
8 changed files with 79 additions and 61 deletions

View File

@ -1,7 +1,8 @@
<script lang="ts">
import type { Contributor } from '$lib/types';
import ContributorButton from '../atoms/ContributorPerson.svelte';
export let contribs;
export let contribs: Contributor[];
export let repo: string;
let repo_name = repo

View File

@ -1,10 +0,0 @@
import { readable } from "svelte/store";
const fetchContributors = async () => {
const response = await fetch('https://releases.rvcd.win/contributors');
const json = await response.json();
return json;
};
const ContributorsStore = readable(fetchContributors());
export default ContributorsStore;

View File

@ -1,11 +0,0 @@
import { readable } from "svelte/store";
const fetchPatches = async () => {
const response = await fetch('https://releases.rvcd.win/patches');
const json = await response.json();
console.log(typeof json)
return json;
};
const PatchesStore = readable(fetchPatches());
export default PatchesStore;

34
src/lib/types.ts Normal file
View File

@ -0,0 +1,34 @@
export interface Contributor {
login: string;
avatar_url: string;
html_url: string;
}
export interface Repository {
name: string;
contributors: Contributor[];
}
export interface Patch {
name: string;
description: string;
version: string;
excluded: boolean;
deprecated: boolean;
dependencies: string[];
options: PatchOption[];
compatiblePackages: CompatiblePackage[];
}
export interface CompatiblePackage {
name: string;
versions: string[];
}
export interface PatchOption {
key: string;
title: string;
description: string;
required: boolean;
choices: string[];
}

View File

@ -1,28 +1,20 @@
<script lang="ts">
import type { APIOutput } from './+page';
import ContributorHost from '$lib/components/molecules/ContributorHost.svelte';
import ContributorsStore from '../../lib/stores/ContributorsStore.js';
import Footer from '$lib/components/molecules/Footer.svelte';
import { onMount } from 'svelte';
import { fly } from 'svelte/transition';
import { quintOut } from 'svelte/easing';
let data;
onMount(() => {
ContributorsStore.subscribe(async (e) => {
data = await e;
});
});
export let data: APIOutput;
</script>
<div class="wrapper contrib-grid">
{#if data}
{#each data.repositories as { contributors, name }}
<div in:fly={{ y: 10, easing: quintOut, duration: 750 }}>
<ContributorHost contribs={contributors} repo={name} />
</div>
{/each}
{/if}
</div>
<style>
@ -34,4 +26,4 @@
}
</style>
<Footer />
<Footer />

View File

@ -0,0 +1,10 @@
import type { Repository } from '$lib/types';
export type APIOutput = { repositories: Repository[] };
export async function load({
fetch
}): APIOutput {
const response = await fetch('https://releases.rvcd.win/contributors');
return await response.json();
}

View File

@ -1,43 +1,24 @@
<script lang="ts">
import type { Output } from "./+page";
import Patch from "$lib/components/atoms/Patch.svelte";
import PatchesStore from "$lib/stores/PatchesStore";
import Footer from "$lib/components/molecules/Footer.svelte";
import { onMount } from "svelte";
import { fly } from 'svelte/transition';
import { quintOut } from 'svelte/easing';
let patches: any;
let pkg_list: Object[] = [];
export let data: Output;
let { patches, packages } = data;
let current: boolean | Object = false;
onMount (async () => {
PatchesStore.subscribe(async (e) => {
patches = await e;
console.log(patches);
for (let i = 0; i < patches.length; i++) {
patches[i].compatiblePackages.forEach(pkg => {
let index = pkg_list.findIndex(x => x == pkg.name);
if (index === -1) {
pkg_list.push(pkg.name);
pkg_list = pkg_list;
};
});
};
})
});
</script>
<section>
<aside class="menu">
{#if pkg_list}
<div in:fly="{{ y: 10, easing: quintOut, duration: 750 }}">
<h5>PACKAGES</h5>
<hr/>
<div class="package-list">
{#each pkg_list as pkg}
{#each packages as pkg}
<div
class="package"
class:selected={ current === pkg }
@ -48,10 +29,8 @@
{/each}
</div>
</div>
{/if}
</aside>
{#if patches}
<div class="patches-list patches-container">
{#each patches as patch, i}
<div in:fly="{{ x: 10, easing: quintOut, duration: 750, delay: (80 * i)}}">
@ -72,7 +51,6 @@
</div>
{/each}
</div>
{/if}
</section>
<Footer/>

View File

@ -0,0 +1,24 @@
import type { Patch } from '$lib/types';
export type Output = { patches: Patch[], packages: string[] };
export async function load({
fetch
}): Output {
const response = await fetch('https://releases.rvcd.win/patches');
const json = await response.json();
let pkg_list = [];
// yes
for (let i = 0; i < json.length; i++) {
json[i].compatiblePackages.forEach(pkg => {
let index = pkg_list.findIndex(x => x == pkg.name);
if (index === -1) {
pkg_list.push(pkg.name);
};
});
};
return { patches: json, packages: pkg_list };
}