From 4c7ae5d7810147c4aab748b466f3fb9941c6a3a2 Mon Sep 17 00:00:00 2001 From: Xylight Date: Fri, 6 Sep 2024 16:23:47 -0700 Subject: [PATCH] impr: improve community experience --- .../lemmy/community/CommunityItem.svelte | 2 +- src/lib/components/ui/EntityHeader.svelte | 2 +- src/lib/i18n/en.json | 5 +- src/routes/c/[name]/+page.svelte | 26 ++++---- src/routes/communities/+page.svelte | 19 ++++-- src/routes/communities/+page.ts | 63 +++++++++---------- 6 files changed, 65 insertions(+), 52 deletions(-) diff --git a/src/lib/components/lemmy/community/CommunityItem.svelte b/src/lib/components/lemmy/community/CommunityItem.svelte index c9b2862a..2dcec3cc 100644 --- a/src/lib/components/lemmy/community/CommunityItem.svelte +++ b/src/lib/components/lemmy/community/CommunityItem.svelte @@ -51,7 +51,7 @@ community.community.name, community.community.actor_id )}" - class="flex-1" + class="flex-1 w-full overflow-hidden" data-sveltekit-preload-data="tap" >
{#if banner} diff --git a/src/lib/i18n/en.json b/src/lib/i18n/en.json index 43e7dede..8313e79f 100644 --- a/src/lib/i18n/en.json +++ b/src/lib/i18n/en.json @@ -217,7 +217,10 @@ }, "translators": "Translators", "accounts": "Accounts", - "communities": "Communities", + "communities": { + "title": "Communities", + "trending": "Trending" + }, "search": { "title": "Search", "federating": "Federating", diff --git a/src/routes/c/[name]/+page.svelte b/src/routes/c/[name]/+page.svelte index 26df4e7e..86f04f18 100644 --- a/src/routes/c/[name]/+page.svelte +++ b/src/routes/c/[name]/+page.svelte @@ -115,13 +115,13 @@ community.community.actor_id )} -
+
{#if $profile?.jwt} {#if $profile?.user && $profile.user.moderates .map((c) => c.community.id) .includes(community.community.id)} {/if} -
diff --git a/src/routes/communities/+page.svelte b/src/routes/communities/+page.svelte index f16ac8a8..950759ca 100644 --- a/src/routes/communities/+page.svelte +++ b/src/routes/communities/+page.svelte @@ -9,7 +9,14 @@ } from 'svelte-hero-icons' import Pageination from '$lib/components/ui/Pageination.svelte' import { searchParam } from '$lib/util.js' - import { Button, Material, Popover, Select, TextInput } from 'mono-svelte' + import { + Button, + Material, + Popover, + Select, + Spinner, + TextInput, + } from 'mono-svelte' import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte' import Placeholder from '$lib/components/ui/Placeholder.svelte' import CommunityItem from '$lib/components/lemmy/community/CommunityItem.svelte' @@ -32,11 +39,11 @@ - {$t('routes.communities')} + {$t('routes.communities.title')}
- {$t('routes.communities')} + {$t('routes.communities.title')} {/if} - {#if data.communities.slice(data.query ?? '' != '' ? 3 : 0).length > 0} + {#if data.communities.slice((data.query ?? '' != '') ? 3 : 0).length > 0} {$t('routes.search.other')} {/if} {#if data.communities} - {@const sliced = data.communities.slice(data.query ?? '' != '' ? 3 : 0)} + {@const sliced = data.communities.slice((data.query ?? '' != '') ? 3 : 0)}
{#each sliced as community}
diff --git a/src/routes/communities/+page.ts b/src/routes/communities/+page.ts index b0d6f877..6b320ae4 100644 --- a/src/routes/communities/+page.ts +++ b/src/routes/communities/+page.ts @@ -1,44 +1,43 @@ import { profile } from '$lib/auth.js' import { LINKED_INSTANCE_URL } from '$lib/instance.js' -import { getClient } from '$lib/lemmy.js' -import type { ListingType, SortType } from 'lemmy-js-client' +import { client, getClient } from '$lib/lemmy.js' +import { + type ListCommunitiesResponse, + type ListingType, + type SortType, +} from 'lemmy-js-client' import { get } from 'svelte/store' export async function load({ url, fetch }) { const type = (url.searchParams.get('type') as ListingType) || (LINKED_INSTANCE_URL ? 'Local' : 'All') - const sort = (url.searchParams.get('sort') as SortType) || 'TopAll' + const sort = (url.searchParams.get('sort') as SortType) || 'TopDay' const page = Number(url.searchParams.get('page')) || 1 - const query = url.searchParams.get('q') + const query = url.searchParams.get('q') || '' - if (query) { - return { - ...(await getClient(undefined, fetch).search({ - limit: 40, - page: page, - sort: sort, - type_: 'Communities', - listing_type: type, - q: query, - })), - type: type, - sort: sort, - query: query, - page: page, - } - } else { - return { - ...(await getClient(undefined, fetch).listCommunities({ - limit: 40, - page: page, - sort: sort, - type_: type, - })), - type: type, - sort: sort, - query: query, - page: page, - } + const communities = + query != '' + ? await getClient(undefined, fetch).search({ + limit: 40, + page: page, + sort: sort, + type_: 'Communities', + listing_type: type, + q: query, + }) + : await getClient(undefined, fetch).listCommunities({ + limit: 40, + page: page, + sort: sort, + type_: type, + }) + + return { + ...communities, + type: type, + sort: sort, + query: query, + page: page, } }