feat: add instance community browsing
This commit is contained in:
5 files changed
+54
-14
No files matched your search
@@ -26,6 +26,7 @@
|
||||
selected = $bindable(),
|
||||
navigate = true,
|
||||
showLabel = true,
|
||||
children,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
@@ -63,4 +64,5 @@
|
||||
>
|
||||
{$t('filter.location.moderator')}
|
||||
</Option>
|
||||
{@render children?.()}
|
||||
</Select>
|
||||
@@ -14,7 +14,8 @@
|
||||
value: optionElement?.value ?? '',
|
||||
label: optionElement?.innerText?.trim() ?? '',
|
||||
icon: icon,
|
||||
disabled: false,
|
||||
disabled: optionElement?.disabled,
|
||||
isLabel: optionElement?.getAttribute('data-label') != null,
|
||||
})
|
||||
|
||||
interface SelectContext {
|
||||
@@ -22,7 +23,8 @@
|
||||
value: string
|
||||
label: string
|
||||
icon?: IconSource
|
||||
disabled: boolean
|
||||
disabled?: boolean
|
||||
isLabel?: boolean
|
||||
}[]
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
label: string
|
||||
icon?: IconSource
|
||||
disabled?: boolean
|
||||
isLabel?: boolean
|
||||
}[]
|
||||
}
|
||||
|
||||
@@ -141,10 +142,14 @@
|
||||
}}
|
||||
size="custom"
|
||||
disabled={option.disabled}
|
||||
color="none"
|
||||
class={[
|
||||
'min-h-0! py-[5px]!',
|
||||
'min-h-0! py-[5px]! hover:bg-slate-100 dark:hover:bg-zinc-800',
|
||||
option.value == value &&
|
||||
'bg-slate-100! dark:bg-zinc-800! text-primary-900 dark:text-primary-100 font-medium!',
|
||||
'bg-slate-100 dark:bg-zinc-800 text-primary-900 dark:text-primary-100 font-medium',
|
||||
option.disabled &&
|
||||
'pointer-events-none text-slate-600 dark:text-zinc-400',
|
||||
option.isLabel && 'text-xs mt-2',
|
||||
]}
|
||||
>
|
||||
{#if option.value == value}
|
||||
|
||||
@@ -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