From bacce3dd89ce67ecdf0c41cd36f16a0cb0e14222 Mon Sep 17 00:00:00 2001 From: Xylight Date: Fri, 5 Dec 2025 20:05:22 -0800 Subject: [PATCH] design: redesign blocked pages to not look like buns --- src/lib/app/i18n/en.json | 24 ++- src/lib/feature/feeds/feed.svelte.ts | 1 + src/lib/feature/user/index.ts | 8 +- src/lib/ui/generic/ItemList.svelte | 32 +-- .../(local_user)/blocks/+layout.svelte | 33 ++++ .../profile/(local_user)/blocks/+page.svelte | 185 ------------------ .../profile/(local_user)/blocks/+page.ts | 5 + .../blocks/communities/+page.svelte | 60 ++++++ .../blocks/instances/+page.svelte | 51 +++++ .../(local_user)/blocks/users/+page.svelte | 61 ++++++ src/routes/profile/+layout.svelte | 92 +++++---- src/routes/profile/+layout.ts | 2 +- src/routes/profile/user/+page.svelte | 1 + src/routes/profile/user/+page.ts | 28 ++- src/routes/u/[name]/+page.ts | 1 + src/routes/u/[name]/UserActions.svelte | 23 ++- 16 files changed, 336 insertions(+), 271 deletions(-) create mode 100644 src/routes/profile/(local_user)/blocks/+layout.svelte delete mode 100644 src/routes/profile/(local_user)/blocks/+page.svelte create mode 100644 src/routes/profile/(local_user)/blocks/+page.ts create mode 100644 src/routes/profile/(local_user)/blocks/communities/+page.svelte create mode 100644 src/routes/profile/(local_user)/blocks/instances/+page.svelte create mode 100644 src/routes/profile/(local_user)/blocks/users/+page.svelte diff --git a/src/lib/app/i18n/en.json b/src/lib/app/i18n/en.json index 5e206001..e729332d 100644 --- a/src/lib/app/i18n/en.json +++ b/src/lib/app/i18n/en.json @@ -84,14 +84,14 @@ "time": { "label": "Period", "all": "All time", - "9months": "Past 9 months", - "6months": "Past 6 months", - "3months": "Past 3 months", + "9months": "9 months", + "6months": "6 months", + "3months": "3 months", "month": "Past month", "week": "Past week", "day": "Past day", - "12hours": "Past 12 hours", - "6hours": "Past 6 hours", + "12hours": "12 hours", + "6hours": "6 hours", "hour": "Past hour" } }, @@ -250,8 +250,18 @@ "blocks": { "title": "Blocked", "empty": { - "title": "No blocked entities", - "description": "When you block anything, it will no longer appear in your feeds." + "user": { + "title": "No blocked users", + "description": "Blocking a user will hide the user's posts and comments from feeds." + }, + "community": { + "title": "No blocked communities", + "description": "Blocking a community will hide its posts from feeds." + }, + "instance": { + "title": "No blocked servers", + "description": "Blocking a server will hide posts from its communities from feeds." + } } }, "credentials": "Credentials", diff --git a/src/lib/feature/feeds/feed.svelte.ts b/src/lib/feature/feeds/feed.svelte.ts index 02948745..35f31140 100644 --- a/src/lib/feature/feeds/feed.svelte.ts +++ b/src/lib/feature/feeds/feed.svelte.ts @@ -140,6 +140,7 @@ export interface FeedTypes { } }, ] + '/profile/user': [GetPersonDetails, GetPersonDetailsResponse] } export const feeds = new SvelteMap>() diff --git a/src/lib/feature/user/index.ts b/src/lib/feature/user/index.ts index 556623fd..7e97cd74 100644 --- a/src/lib/feature/user/index.ts +++ b/src/lib/feature/user/index.ts @@ -4,18 +4,14 @@ import { profile, type ProfileInfo } from '$lib/app/auth.svelte' // TODO obliterate this file export async function blockUser(block: boolean, id: number) { - const auth = profile.current?.jwt - - if (!auth) throw new Error('Unauthorized') - - await client().blockPerson({ + return await client().blockPerson({ block: block, person_id: id, }) } export function isBlocked(me: MyUserInfo, user: number) { - return me.person_blocks.map((b) => b.target.id).includes(user) + return me.person_blocks.find((b) => b.target.id == user) } export function addSubscription( diff --git a/src/lib/ui/generic/ItemList.svelte b/src/lib/ui/generic/ItemList.svelte index f4f9823e..fe933e1e 100644 --- a/src/lib/ui/generic/ItemList.svelte +++ b/src/lib/ui/generic/ItemList.svelte @@ -1,19 +1,25 @@ @@ -23,7 +29,7 @@ gap="lg" color="none" alignment="left" - href={item.url} + href={link ? item.url : undefined} >
@@ -42,6 +48,10 @@ {/if}
+ {#if action} +
+ {@render action(item)} + {/if} {/snippet}
diff --git a/src/routes/profile/(local_user)/blocks/+layout.svelte b/src/routes/profile/(local_user)/blocks/+layout.svelte new file mode 100644 index 00000000..94f641cd --- /dev/null +++ b/src/routes/profile/(local_user)/blocks/+layout.svelte @@ -0,0 +1,33 @@ + + +
+ {$t('routes.profile.blocks.title')} + + {#snippet extended()} + + {/snippet} +
+ +{@render children?.()} diff --git a/src/routes/profile/(local_user)/blocks/+page.svelte b/src/routes/profile/(local_user)/blocks/+page.svelte deleted file mode 100644 index 7e01ad2b..00000000 --- a/src/routes/profile/(local_user)/blocks/+page.svelte +++ /dev/null @@ -1,185 +0,0 @@ - - -
- {$t('routes.profile.blocks.title')} -
- -
- {#if data.community_blocks?.length > 0 || data.person_blocks?.length > 0 || (data.my_user?.instance_blocks?.length ?? 0) > 0} - {#if data.community_blocks?.length > 0} - - {$t('content.communities')} - -
- - {#snippet item(block)} -
- -
- -
- {/snippet} -
-
- {/if} - {#if data.person_blocks?.length > 0} - - {$t('content.users')} - -
- - {#snippet item(block)} -
- -
- -
- {/snippet} -
-
- {/if} - {#if data.my_user?.instance_blocks && (data.my_user?.instance_blocks?.length ?? 0) > 0} - - {$t('content.instances')} - -
- - {#snippet item(block)} -
- -
- -
- {/snippet} -
-
- {/if} - {:else} -
- -
- {/if} -
diff --git a/src/routes/profile/(local_user)/blocks/+page.ts b/src/routes/profile/(local_user)/blocks/+page.ts new file mode 100644 index 00000000..92a5e0f7 --- /dev/null +++ b/src/routes/profile/(local_user)/blocks/+page.ts @@ -0,0 +1,5 @@ +import { redirect } from '@sveltejs/kit' + +export function load() { + redirect(302, '/profile/blocks/users') +} diff --git a/src/routes/profile/(local_user)/blocks/communities/+page.svelte b/src/routes/profile/(local_user)/blocks/communities/+page.svelte new file mode 100644 index 00000000..766a6cbe --- /dev/null +++ b/src/routes/profile/(local_user)/blocks/communities/+page.svelte @@ -0,0 +1,60 @@ + + +{#if data.community_blocks && data.community_blocks?.length > 0} + ({ + id: i.community.id, + name: i.community.title, + avatar: i.community.icon, + url: communityLink(i.community), + instance: new URL(i.community.actor_id).hostname, + }))} + link={false} + > + {#snippet action(block)} + - {/snippet} - - {$t('routes.profile.media.title')} - - - {$t('routes.profile.upvoted')} - - - {$t('routes.profile.downvoted')} - - - - - {@render children?.()} + { + href: '/profile/password', + name: $t('routes.profile.credentials'), + }, + ]} + > + + {#snippet target(attachment)} + + {/snippet} + + {$t('routes.profile.media.title')} + + + {$t('routes.profile.upvoted')} + + + {$t('routes.profile.downvoted')} + + + +{@render children?.()} diff --git a/src/routes/profile/+layout.ts b/src/routes/profile/+layout.ts index 2802ab17..941bff6a 100644 --- a/src/routes/profile/+layout.ts +++ b/src/routes/profile/+layout.ts @@ -9,7 +9,7 @@ export async function load({ fetch }) { if (!profile.current.jwt) error(401) const my_user = - // profile.current?.user ?? + profile.current?.user ?? (await client({ auth: profile.current?.jwt, func: fetch }).getSite()) .my_user diff --git a/src/routes/profile/user/+page.svelte b/src/routes/profile/user/+page.svelte index 64e399ed..87dd4439 100644 --- a/src/routes/profile/user/+page.svelte +++ b/src/routes/profile/user/+page.svelte @@ -13,6 +13,7 @@ page: data.page, sort: data.sort, type: data.type, + limit: data.limit, }), person_view: { value: data.user.person_view }, moderates: { value: data.user.moderates }, diff --git a/src/routes/profile/user/+page.ts b/src/routes/profile/user/+page.ts index 5f831438..89a51bf3 100644 --- a/src/routes/profile/user/+page.ts +++ b/src/routes/profile/user/+page.ts @@ -1,25 +1,32 @@ -import { getClient } from '$lib/api/client.svelte' +import { client } from '$lib/api/client.svelte' import type { SortType } from '$lib/api/types' +import { feed } from '$lib/feature/feeds/feed.svelte.js' import { getItemPublished } from '$lib/feature/legacy/item' -export async function load({ url, fetch, parent }) { +export async function load({ url, fetch, parent, route }) { const page = Number(url.searchParams.get('page')) || 1 const type: 'comments' | 'posts' | 'all' = (url.searchParams.get('type') as 'comments' | 'posts' | 'all') || 'all' const sort: SortType = (url.searchParams.get('sort') as SortType) || 'New' - const { my_user } = await parent() - - const user = await getClient(undefined, fetch).getPersonDetails({ + const myUser = await parent() + const feedData = await feed(route.id, (params) => + client({ func: fetch }).getPersonDetails({ + limit: params.limit, + page: params.page, + person_id: myUser?.my_user?.local_user_view.person.id, + sort: params.sort, + }), + ).load({ limit: 20, page: page, - username: my_user?.local_user_view.person.name, + person_id: myUser.my_user?.local_user_view.person.id, sort: sort, }) const items = [ - ...(type == 'all' || type == 'posts' ? user.posts : []), - ...(type == 'all' || type == 'comments' ? user.comments : []), + ...(type == 'all' || type == 'posts' ? feedData.posts : []), + ...(type == 'all' || type == 'comments' ? feedData.comments : []), ] if (sort == 'TopAll') { @@ -40,10 +47,11 @@ export async function load({ url, fetch, parent }) { type: type, page: page, sort: sort, + limit: 20, user: { submissions: items, - moderates: user.moderates, - person_view: user.person_view, + moderates: feedData.moderates, + person_view: feedData.person_view, }, } } diff --git a/src/routes/u/[name]/+page.ts b/src/routes/u/[name]/+page.ts index 753de709..03f856ad 100644 --- a/src/routes/u/[name]/+page.ts +++ b/src/routes/u/[name]/+page.ts @@ -37,6 +37,7 @@ export async function load({ params, url, fetch }) { type: type, page: page, sort: sort, + limit: 20, }), person_view: new ReactiveState(user.person_view), moderates: new ReactiveState(user.moderates), diff --git a/src/routes/u/[name]/UserActions.svelte b/src/routes/u/[name]/UserActions.svelte index d91a3155..0141b3e1 100644 --- a/src/routes/u/[name]/UserActions.svelte +++ b/src/routes/u/[name]/UserActions.svelte @@ -162,11 +162,26 @@ - blockUser( - isBlocked(profile.current.user!, person.person.id), + onclick={async () => { + const res = await blockUser( + !isBlocked(profile.current.user!, person.person.id), person.person.id, - )} + ) + + if (res.blocked) { + // TODO technically invalid but i don't use it so idc + profile.current.user!.person_blocks.push({ + person: person.person, + target: person.person, + }) + } else { + const index = profile.current.user!.person_blocks.findIndex( + (i) => i.target.id == person.person.id, + ) + if (index != -1) + profile.current.user!.person_blocks.splice(index, 1) + } + }} > {#snippet prefix()}