From 9efe1df0c2218596a4c362bef4feeb92092c79db Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Tue, 4 Jul 2023 19:39:27 -0700 Subject: [PATCH] feat: Add user pages --- src/hooks.server.ts | 9 +- .../components/community/CommunityLink.svelte | 12 +-- src/lib/components/lemmy/Post.svelte | 3 +- .../components/lemmy/comment/Comment.svelte | 10 +-- src/lib/components/ui/Navbar.svelte | 4 + src/lib/components/user/UserLink.svelte | 29 +++++++ src/routes/+error.svelte | 4 +- src/routes/communities/+page.svelte | 40 +++++++-- src/routes/communities/Subscribe.svelte | 37 ++++++++ src/routes/post/[instance]/[id]/+page.svelte | 3 +- src/routes/u/[name]/+page.svelte | 86 +++++++++++++++++++ src/routes/u/[name]/+page.ts | 14 +++ 12 files changed, 222 insertions(+), 29 deletions(-) create mode 100644 src/lib/components/user/UserLink.svelte create mode 100644 src/routes/communities/Subscribe.svelte create mode 100644 src/routes/u/[name]/+page.svelte create mode 100644 src/routes/u/[name]/+page.ts diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 87050853..5ff6f710 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -1,5 +1,3 @@ -import { error } from '@sveltejs/kit' - function buildUrl(inputUrl: URL): URL { let withoutCors = inputUrl.pathname.replace('/cors/', '') @@ -10,9 +8,9 @@ function buildUrl(inputUrl: URL): URL { return new URL(`${withoutCors}?${inputUrl.searchParams.toString()}`) } -export async function handleError() { +export function handleError({ error, event }) { return { - message: 'The proxy failed to fetch from that URL', + message: 'There was an error during rendering', } } @@ -71,13 +69,12 @@ export async function handle({ event, resolve }) { }) } } catch (error) { - console.log('caught it') return new Response( JSON.stringify({ message: 'the proxy failed to fetch from server', }), { - status: 500, + status: 200, } ) } diff --git a/src/lib/components/community/CommunityLink.svelte b/src/lib/components/community/CommunityLink.svelte index 0ef51309..dd7ac010 100644 --- a/src/lib/components/community/CommunityLink.svelte +++ b/src/lib/components/community/CommunityLink.svelte @@ -5,19 +5,15 @@ export let avatar: boolean = false function linkFromCommunity(community: Community) { - const local = community.local - - // if (local) { - // return `/c/${community.name}` - // } else { const domain = new URL(community.actor_id).hostname - return `/c/${community.name}@${domain}` - // } } - + {#if avatar}
- {postRes.creator.name} + diff --git a/src/lib/components/lemmy/comment/Comment.svelte b/src/lib/components/lemmy/comment/Comment.svelte index 57b6a231..e002af6e 100644 --- a/src/lib/components/lemmy/comment/Comment.svelte +++ b/src/lib/components/lemmy/comment/Comment.svelte @@ -15,6 +15,7 @@ import { Color } from '$lib/ui/colors.js' import CommentForm from './CommentForm.svelte' import { page } from '$app/stores' + import UserLink from '$lib/components/user/UserLink.svelte' export let node: CommentNodeI @@ -66,12 +67,9 @@ - - {node.comment_view.creator.name} + + + + {#if avatar} + + {/if} + {user.name} + diff --git a/src/routes/+error.svelte b/src/routes/+error.svelte index 98438c16..3269d95b 100644 --- a/src/routes/+error.svelte +++ b/src/routes/+error.svelte @@ -6,8 +6,8 @@

{$page.status}

- Failed to fetch page. The lemmy servers are having quite a lot of issues - right now, this is likely on their end. + Failed to fetch page. Most major lemmy instances are having quite a lot of + issues right now, this might be on their end.

{JSON.stringify($page.error)} diff --git a/src/routes/communities/+page.svelte b/src/routes/communities/+page.svelte index a66ae8e0..21dab308 100644 --- a/src/routes/communities/+page.svelte +++ b/src/routes/communities/+page.svelte @@ -13,6 +13,8 @@ import Link from '$lib/components/input/Link.svelte' import { Color } from '$lib/ui/colors.js' import TextInput from '$lib/components/input/TextInput.svelte' + import Subscribe from './Subscribe.svelte' + import Button from '$lib/components/input/Button.svelte' export let data @@ -56,11 +58,39 @@ class="py-4 border-b border-black/20 dark:border-white/20 flex flex-col gap-1 text-sm" > - - - +
+ + + +
+ + + +
+
{#if !community.community.local} {new URL(community.community.actor_id).hostname} diff --git a/src/routes/communities/Subscribe.svelte b/src/routes/communities/Subscribe.svelte new file mode 100644 index 00000000..88da9a0e --- /dev/null +++ b/src/routes/communities/Subscribe.svelte @@ -0,0 +1,37 @@ + + + diff --git a/src/routes/post/[instance]/[id]/+page.svelte b/src/routes/post/[instance]/[id]/+page.svelte index 7dc71197..c8cae14e 100644 --- a/src/routes/post/[instance]/[id]/+page.svelte +++ b/src/routes/post/[instance]/[id]/+page.svelte @@ -11,6 +11,7 @@ import PostVote from '$lib/components/lemmy/PostVote.svelte' import { page } from '$app/stores' import { onMount } from 'svelte' + import UserLink from '$lib/components/user/UserLink.svelte' export let data @@ -88,7 +89,7 @@
- {postData.creator.name} +

{post.name}

{#if post.url} diff --git a/src/routes/u/[name]/+page.svelte b/src/routes/u/[name]/+page.svelte new file mode 100644 index 00000000..286c85fe --- /dev/null +++ b/src/routes/u/[name]/+page.svelte @@ -0,0 +1,86 @@ + + +
+
+ {#each data.user.comments as item} + +
+
+ + + + + {item.post.name} + +
+ Jump +
+
+ +
+
+ {/each} +
+ + +
diff --git a/src/routes/u/[name]/+page.ts b/src/routes/u/[name]/+page.ts new file mode 100644 index 00000000..65ad5a0e --- /dev/null +++ b/src/routes/u/[name]/+page.ts @@ -0,0 +1,14 @@ +import { authData, getClient } from '$lib/lemmy.js' +import { get } from 'svelte/store' + +export function load({ params }) { + return { + user: getClient().getPersonDetails({ + limit: 40, + page: 1, + username: params.name, + sort: 'New', + auth: get(authData)?.token, + }), + } +}