Skip to content

Commit fc20f0e

Browse files
authored
Merge pull request #25 from containerish/adhoc-changes
Add: Pre-render and prefetch
2 parents 2e1afd3 + 2d0e45b commit fc20f0e

File tree

9 files changed

+67
-70
lines changed

9 files changed

+67
-70
lines changed

src/apis/httpClient.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ abstract class HttpClient {
1111
protected constructor(baseURL: string, headers?: any) {
1212
this.http = axios.create({
1313
baseURL,
14-
headers: {
15-
'Cache-Control': 'no-cache',
16-
...headers
17-
},
14+
headers,
1815
withCredentials: true,
1916
httpAgent: this.getUserAgent(),
2017
httpsAgent: this.getUserAgent(),

src/components/dropdown.svelte

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,14 @@
66
import { goto } from '$app/navigation';
77
export let user: User;
88
export let show = false;
9-
export let handleShowMenu: VoidFunction;
109
export let closeMenu: VoidFunction;
1110
11+
const auth = new Auth();
12+
1213
function onClickOutside() {
1314
closeMenu();
1415
}
1516
16-
const modalCloseFunc = () => {
17-
showModal = false;
18-
};
19-
20-
const auth = new Auth();
21-
2217
const signOut = async () => {
2318
const { error } = await auth.Signout();
2419
if (error) {
@@ -48,8 +43,8 @@
4843
>
4944
<a
5045
href="#"
51-
class="flex items-center p-3 -mt-2 text-sm text-gray-600 transition-colors duration-200 transform
52-
hover:bg-white hover:no-underline"
46+
class="flex cursor-default items-center p-3 -mt-2 text-sm text-gray-600 transition-colors duration-200 transform
47+
hover:no-underline"
5348
>
5449
<div class="mx-1">
5550
<h1 class="text-lg font-normal text-brown-900">
@@ -63,8 +58,9 @@
6358

6459
<hr class="border-gray-400" />
6560

66-
<button
67-
on:click={() => navigateAround('/u')}
61+
<a
62+
href="/u"
63+
sveltekit:prefetch
6864
class="flex items-center w-full border-0 m-0 p-3 text-sm text-gray-600 capitalize transition-colors duration-200
6965
transform hover:bg-white hover:no-underline"
7066
>
@@ -85,7 +81,7 @@
8581
</svg>
8682

8783
<span class="mx-1">View Profile</span>
88-
</button>
84+
</a>
8985
<hr class="border-gray-200" />
9086

9187
<button

src/components/repository.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<script lang="ts">
22
import { goto } from '$app/navigation';
3-
4-
import Copy from '$lib/icons/copy.svelte';
53
import Download from '$lib/icons/download.svelte';
64
import LockOpen from '$lib/icons/lock-open.svelte';
75
import Star from '$lib/icons/star.svelte';

src/components/signin.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
}
8383
8484
const { error, status } = await auth.Login(email, password);
85-
/* const { error, status } = await auth.Login('[email protected]', 'Qwerty@123'); */
8685
if (error) {
8786
isLoading = false;
8887
formErr = error.message;

src/lib/navbar-auth.svelte

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@
2929
const closeMenu = () => {
3030
showMenu = false;
3131
};
32-
33-
const handleShowMenu = () => {
34-
showMenu = !showMenu;
35-
};
36-
37-
const navigateAround = async (path: string) => {
38-
await goto(path);
39-
};
4032
</script>
4133

4234
{#if sessionOk}
@@ -56,28 +48,31 @@
5648

5749
<div class="items-center md:flex flex-[3] justify-end sm:flex half:flex">
5850
<div class="flex flex-col justify-center items-center md:flex-row half:mt-0 pl-10">
59-
<button
60-
on:click={() => navigateAround('/search')}
51+
<a
52+
sveltekit:prefetch
53+
href="/search"
6154
class="my-1 text-lg leading-5 font-lato font-semibold text-brown-800 transition-colors duration-200 bg-inherit
6255
border-none transform hover:text-brown-800 hover:no-underline md:mx-6 md:my-0 half:mx-2"
6356
>
6457
Explore
65-
</button>
66-
<button
67-
on:click={() => navigateAround('/repositories')}
58+
</a>
59+
<a
60+
href="/repositories"
61+
sveltekit:prefetch
6862
class="my-1 mx-0 px-0 text-lg font-semibold font-lato leading-5 text-brown-800 transition-colors duration-200
6963
transform bg-inherit border-none hover:text-brown-800 hover:no-underline md:mx-6 md:my-0 half:mx-2"
7064
>
7165
Repositories
72-
</button>
73-
<button
74-
on:click={() => navigateAround('/faq')}
66+
</a>
67+
<a
68+
sveltekit:prefetch
69+
href="/faq"
7570
class="my-1 text-lg font-semibold px-0 leading-5 text-brown-800 border-2 transition-colors duration-200
7671
transform bg-inherit border-none hover:text-brown-800 hover:no-underline md:mx-6 md:my-0 half:mx-2"
7772
>
7873
FAQ
79-
</button>
80-
<Dropdown user={u} show={showMenu} {closeMenu} {handleShowMenu}>
74+
</a>
75+
<Dropdown user={u} show={showMenu} {closeMenu}>
8176
<button
8277
on:click={toggleMenu}
8378
class="flex items-center px-4 w-full half:px-2 ml-8 half:ml-4 mt-1.5 font-lato font-semibold border-brown-800

src/routes/index.svelte

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
import Landing from './landing.svelte';
33
import { session } from '$app/stores';
44
import { goto } from '$app/navigation';
5-
// @ts-ignore
6-
session.subscribe(async ({ authenticated }) => {
7-
if (authenticated) goto('/repositories');
5+
import { onMount } from 'svelte';
6+
onMount(async () => {
7+
// @ts-ignore
8+
if ($session.authenticated) {
9+
goto('/repositories');
10+
}
811
});
912
</script>
1013

src/routes/settings/index.svelte

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
<script lang="ts">
2-
import { browser } from '$app/env';
32
import { goto } from '$app/navigation';
43
import Card from '$lib/card.svelte';
54
import UserIcon from '$lib/icons/user.svelte';
65
import { Auth, type User } from '../../apis/auth';
76
import { session } from '$app/stores';
87
export let u: User;
98
9+
let nameOrUsername: string;
1010
const auth = new Auth();
11-
if (browser) {
11+
onMount(async () => {
1212
// @ts-ignore
13-
session.subscribe(async ({ authenticated, user }) => {
14-
if (authenticated) {
15-
u = user;
16-
return;
17-
}
18-
19-
goto('/auth/unauthorized');
20-
});
21-
}
13+
if (!$session.authenticated) {
14+
await goto('/auth/unauthorized');
15+
}
2216
23-
let nameOrUsername = u.name ? u.name : u.username;
17+
// @ts-ignore
18+
u = $session.user;
19+
nameOrUsername = u.name ? u.name : u.username;
20+
});
2421
2522
import { form, field } from 'svelte-forms';
2623
import { required, max, min, matchField } from 'svelte-forms/validators';
24+
import { onMount } from 'svelte';
2725
2826
let currentPassword = field('current_password', '', [required(), min(8), max(48)]);
2927
let newPassword = field('new_password', '', [required(), min(8), max(48)]);

src/routes/u/[username]/[repo].svelte

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
<script lang="ts" context="module">
2+
export const prerender: boolean = true;
3+
export async function load({ params }) {
4+
return {
5+
props: {
6+
repo: params.repo,
7+
username: params.username
8+
}
9+
};
10+
}
11+
</script>
12+
113
<script lang="ts">
214
import Star from '$lib/icons/star.svelte';
315
import Globe from '$lib/icons/globe.svelte';

src/routes/u/index.svelte

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
<script context="module" lang="ts">
2-
export function load({ session }) {
3-
return {
4-
props: {
5-
user: session.user
6-
}
7-
};
8-
}
9-
</script>
10-
111
<script lang="ts">
122
import { onMount } from 'svelte';
133
import UserIcon from '$lib/icons/user.svelte';
144
import Repository from '../../components/repository.svelte';
15-
import { RegistryBackend, type Catalog, type DetailedRepository } from '../../apis/registry';
5+
import { RegistryBackend, type Catalog } from '../../apis/registry';
166
import type { User } from 'src/apis/auth';
177
import StarIcon from '$lib/icons/star.svelte';
188
import UserGroupIcon from '$lib/icons/userGroup.svelte';
9+
import { goto } from '$app/navigation';
10+
import { session } from '$app/stores';
1911
export let user: User;
2012
2113
let isRepo = true;
2214
let isStarred = false;
2315
let isContrib = false;
2416
17+
onMount(async () => {
18+
// @ts-ignore
19+
if (!$session.authenticated) {
20+
await goto('/auth/unauthorized');
21+
}
22+
23+
// @ts-ignore
24+
user = $session.user;
25+
await fetchPageData();
26+
});
27+
2528
const toggleRepo = () => {
2629
isContrib = false;
2730
isStarred = false;
@@ -58,10 +61,6 @@
5861
5962
catalog = data;
6063
};
61-
let showTooltip = false;
62-
onMount(async () => {
63-
fetchPageData();
64-
});
6564
</script>
6665

6766
<svelte:head>
@@ -135,7 +134,7 @@
135134

136135
{#if isRepo}
137136
<div>
138-
<div class="w-full px-16 p-8">
137+
<div class="w-full px-16 py-8">
139138
{#if catalog?.repositories}
140139
{#each catalog.repositories as repo}
141140
<Repository compact={false} data={repo} />
@@ -150,7 +149,7 @@
150149
{/if}
151150

152151
{#if isStarred}
153-
<div class="w-full px-8">
152+
<div class="w-full px-16 py-8">
154153
<div
155154
class="bg-gray-50 w-full rounded-md px-28 py-20 flex flex-col justify-center items-center"
156155
>
@@ -164,7 +163,7 @@
164163
{/if}
165164

166165
{#if isContrib}
167-
<div class="w-full px-8">
166+
<div class="w-full px-16 py-8">
168167
<div
169168
class="bg-gray-50 w-full rounded-md px-28 py-20 flex flex-col justify-center items-center"
170169
>

0 commit comments

Comments
 (0)