refactor: api client

This commit is contained in:
Ax333l
2022-11-11 11:30:52 +01:00
parent 10812aef27
commit ad08371ed7
10 changed files with 111 additions and 147 deletions

View File

@ -7,14 +7,14 @@
<section class="error">
<h1>{status}</h1>
{#if status == 500}
<p>
{$page.error.message}
</p>
{:else if status == 404}
{#if status == 404}
<p>That page received a cease and desist letter from a multi-billion dollar tech company.</p>
<br />
<Navigation href="/" is_selected={() => true}>Home</Navigation>
{:else}
<p>
{$page.error.message}
</p>
{/if}
</section>

View File

@ -6,13 +6,6 @@
import RouterEvents from '../data/RouterEvents';
import '../app.css';
import type { PageData } from './$types';
import { contributors } from "../data/api";
export let data: PageData;
contributors.init(data);
// Just like the set/clearInterval example found here: https://svelte.dev/docs#run-time-svelte-store-derived
const show_loading_animation = derived(RouterEvents, ($event, set) => {
if ($event.navigating) {
@ -44,3 +37,6 @@
{:else}
<slot />
{/if}
<!--
afn if you are moving the footer here, please make it not use the repositories store directly and instead use component props :) -->
<!-- <Footer repos={$repositories}> -->

View File

@ -1,7 +1,14 @@
import type { PageLoad } from './$types';
import { contributors } from '../data/api';
import { repositories } from '../data/api';
export const prerender = true;
export const load: PageLoad = contributors.page_load_impl();
const base = repositories.page_load_impl();
export const load: PageLoad = async ({ fetch }) => {
// The entire site may softlock if the user sets a bad API url if we don't do this.
try {
return await base({ fetch });
} catch(_) { }
}

View File

@ -5,11 +5,7 @@
import ContributorHost from '$lib/components/molecules/ContributorHost.svelte';
import Footer from '$lib/components/molecules/Footer.svelte';
// Handled by `+layout.ts`.
import { contributors } from '../../data/api';
import type { PageData } from './$types';
export let data: PageData;
import { repositories } from '../../data/api';
</script>
<svelte:head>
@ -25,7 +21,7 @@
<h2>Want to show up here? <span><a href="https://github.com/revanced" target="_blank" rel="noreferrer">Become a contributor</a></span></h2>
</div>
<div class="contrib-grid">
{#each $contributors.repositories as { contributors: contribs, name }}
{#each $repositories as { contributors: contribs, name }}
<div in:fly={{ y: 10, easing: quintOut, duration: 750 }}>
<ContributorHost {contribs} repo={name} />
</div>
@ -34,7 +30,7 @@
</div>
</main>
<Footer {...data} />
<Footer />
<style>
.contrib-grid {

View File

@ -0,0 +1,5 @@
import type { PageLoad } from './$types';
import { repositories } from '../../data/api';
export const load: PageLoad = repositories.page_load_impl();

View File

@ -1,13 +1,9 @@
<script lang="ts">
import type { PageData } from './$types';
import { tools as api_tools } from '../../data/api';
import { tools } from '../../data/api';
import Button from '$lib/components/atoms/Button.svelte';
import Footer from '$lib/components/molecules/Footer.svelte';
export let data: PageData;
api_tools.init(data);
$: manager = $api_tools.tools["revanced/revanced-manager"];
$: manager = $tools["revanced/revanced-manager"];
</script>
<div class="wrapper">
@ -17,7 +13,7 @@
<img src="../manager_two.png" alt="Manager Screenshot"/>
</div>
<Footer {...data}/>
<Footer />
<style>

View File

@ -1,6 +1,4 @@
<script lang="ts">
import type { PageData } from './$types';
import { fly } from 'svelte/transition';
import { quintOut } from 'svelte/easing';
@ -12,10 +10,6 @@
import PatchCell from '$lib/components/molecules/PatchCell.svelte';
import Footer from '$lib/components/molecules/Footer.svelte';
export let data: PageData;
// Needed when someone navigates directly to the page.
api_patches.init(data);
$: ({ patches, packages } = $api_patches);
let current: boolean = false;
@ -55,7 +49,7 @@
{/each}
</div>
</main>
<Footer {...data} />
<Footer />
<style>
main {