feat: add instance community browsing
This commit is contained in:
5 files changed
+54
-14
No files matched your search
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { navigating, page } from '$app/state'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import CommunityItem from '$lib/components/lemmy/community/CommunityItem.svelte'
|
||||
import Location from '$lib/components/lemmy/dropdowns/Location.svelte'
|
||||
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
||||
@@ -11,8 +12,14 @@
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||
import { t } from '$lib/i18n/translations.js'
|
||||
import { Button, Material, TextInput } from 'mono-svelte'
|
||||
import { Icon, MagnifyingGlass, QuestionMarkCircle } from 'svelte-hero-icons'
|
||||
import { LINKED_INSTANCE_URL } from '$lib/instance.svelte'
|
||||
import { Button, Material, Option, TextInput } from 'mono-svelte'
|
||||
import {
|
||||
Icon,
|
||||
MagnifyingGlass,
|
||||
QuestionMarkCircle,
|
||||
ServerStack,
|
||||
} from 'svelte-hero-icons'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { fly } from 'svelte/transition'
|
||||
|
||||
@@ -77,7 +84,24 @@
|
||||
name="type"
|
||||
selected={data.type}
|
||||
onchange={() => form?.requestSubmit()}
|
||||
/>
|
||||
>
|
||||
{#if !LINKED_INSTANCE_URL}
|
||||
{@const instanceSet = new Set(
|
||||
profile.meta.profiles.map(i => i.instance),
|
||||
)}
|
||||
{#if instanceSet.size > 1}
|
||||
<Option disabled data-label="true">—</Option>
|
||||
{#each instanceSet as instance}
|
||||
<Option
|
||||
icon={ServerStack}
|
||||
value={encodeURIComponent(`instance-${instance}`)}
|
||||
>
|
||||
{instance}
|
||||
</Option>
|
||||
{/each}
|
||||
{/if}
|
||||
{/if}
|
||||
</Location>
|
||||
<Sort
|
||||
name="sort"
|
||||
selected={data.sort}
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
import { LINKED_INSTANCE_URL } from '$lib/instance.svelte.js'
|
||||
import { getClient } from '$lib/lemmy.svelte.js'
|
||||
import { client } from '$lib/lemmy.svelte.js'
|
||||
import { ReactiveState } from '$lib/promise.svelte'
|
||||
import { type ListingType, type SortType } from 'lemmy-js-client'
|
||||
|
||||
export async function load({ url, fetch }) {
|
||||
const type =
|
||||
(url.searchParams.get('type') as ListingType) ||
|
||||
(LINKED_INSTANCE_URL ? 'Local' : 'All')
|
||||
const typeParam = url.searchParams.get('type')
|
||||
const typeInstance = typeParam?.split('instance-')[1]
|
||||
|
||||
const type = typeInstance
|
||||
? 'Local'
|
||||
: (typeParam as ListingType) || (LINKED_INSTANCE_URL ? 'Local' : 'All')
|
||||
|
||||
const sort = (url.searchParams.get('sort') as SortType) || 'TopDay'
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
const query = url.searchParams.get('q') || ''
|
||||
|
||||
const communities =
|
||||
query != ''
|
||||
? await getClient(undefined, fetch).search({
|
||||
? await client({ func: fetch, instanceURL: typeInstance }).search({
|
||||
limit: 40,
|
||||
page: page,
|
||||
sort: sort,
|
||||
@@ -21,7 +25,10 @@ export async function load({ url, fetch }) {
|
||||
listing_type: type,
|
||||
q: query,
|
||||
})
|
||||
: await getClient(undefined, fetch).listCommunities({
|
||||
: await client({
|
||||
func: fetch,
|
||||
instanceURL: typeInstance,
|
||||
}).listCommunities({
|
||||
limit: 40,
|
||||
page: page,
|
||||
sort: sort,
|
||||
@@ -31,7 +38,7 @@ export async function load({ url, fetch }) {
|
||||
|
||||
return {
|
||||
communities: new ReactiveState(communities.communities),
|
||||
type: type,
|
||||
type: typeParam ?? type,
|
||||
sort: sort,
|
||||
query: query,
|
||||
page: page,
|
||||
|
||||
Reference in new issue
Block a user