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(),
|
selected = $bindable(),
|
||||||
navigate = true,
|
navigate = true,
|
||||||
showLabel = true,
|
showLabel = true,
|
||||||
|
children,
|
||||||
...rest
|
...rest
|
||||||
}: Props = $props()
|
}: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
@@ -63,4 +64,5 @@
|
|||||||
>
|
>
|
||||||
{$t('filter.location.moderator')}
|
{$t('filter.location.moderator')}
|
||||||
</Option>
|
</Option>
|
||||||
|
{@render children?.()}
|
||||||
</Select>
|
</Select>
|
||||||
@@ -14,7 +14,8 @@
|
|||||||
value: optionElement?.value ?? '',
|
value: optionElement?.value ?? '',
|
||||||
label: optionElement?.innerText?.trim() ?? '',
|
label: optionElement?.innerText?.trim() ?? '',
|
||||||
icon: icon,
|
icon: icon,
|
||||||
disabled: false,
|
disabled: optionElement?.disabled,
|
||||||
|
isLabel: optionElement?.getAttribute('data-label') != null,
|
||||||
})
|
})
|
||||||
|
|
||||||
interface SelectContext {
|
interface SelectContext {
|
||||||
@@ -22,7 +23,8 @@
|
|||||||
value: string
|
value: string
|
||||||
label: string
|
label: string
|
||||||
icon?: IconSource
|
icon?: IconSource
|
||||||
disabled: boolean
|
disabled?: boolean
|
||||||
|
isLabel?: boolean
|
||||||
}[]
|
}[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,7 @@
|
|||||||
label: string
|
label: string
|
||||||
icon?: IconSource
|
icon?: IconSource
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
|
isLabel?: boolean
|
||||||
}[]
|
}[]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,10 +142,14 @@
|
|||||||
}}
|
}}
|
||||||
size="custom"
|
size="custom"
|
||||||
disabled={option.disabled}
|
disabled={option.disabled}
|
||||||
|
color="none"
|
||||||
class={[
|
class={[
|
||||||
'min-h-0! py-[5px]!',
|
'min-h-0! py-[5px]! hover:bg-slate-100 dark:hover:bg-zinc-800',
|
||||||
option.value == value &&
|
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}
|
{#if option.value == value}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { navigating, page } from '$app/state'
|
import { navigating, page } from '$app/state'
|
||||||
|
import { profile } from '$lib/auth.svelte.js'
|
||||||
import CommunityItem from '$lib/components/lemmy/community/CommunityItem.svelte'
|
import CommunityItem from '$lib/components/lemmy/community/CommunityItem.svelte'
|
||||||
import Location from '$lib/components/lemmy/dropdowns/Location.svelte'
|
import Location from '$lib/components/lemmy/dropdowns/Location.svelte'
|
||||||
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
import Sort from '$lib/components/lemmy/dropdowns/Sort.svelte'
|
||||||
@@ -11,8 +12,14 @@
|
|||||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||||
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||||
import { t } from '$lib/i18n/translations.js'
|
import { t } from '$lib/i18n/translations.js'
|
||||||
import { Button, Material, TextInput } from 'mono-svelte'
|
import { LINKED_INSTANCE_URL } from '$lib/instance.svelte'
|
||||||
import { Icon, MagnifyingGlass, QuestionMarkCircle } from 'svelte-hero-icons'
|
import { Button, Material, Option, TextInput } from 'mono-svelte'
|
||||||
|
import {
|
||||||
|
Icon,
|
||||||
|
MagnifyingGlass,
|
||||||
|
QuestionMarkCircle,
|
||||||
|
ServerStack,
|
||||||
|
} from 'svelte-hero-icons'
|
||||||
import { expoOut } from 'svelte/easing'
|
import { expoOut } from 'svelte/easing'
|
||||||
import { fly } from 'svelte/transition'
|
import { fly } from 'svelte/transition'
|
||||||
|
|
||||||
@@ -77,7 +84,24 @@
|
|||||||
name="type"
|
name="type"
|
||||||
selected={data.type}
|
selected={data.type}
|
||||||
onchange={() => form?.requestSubmit()}
|
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
|
<Sort
|
||||||
name="sort"
|
name="sort"
|
||||||
selected={data.sort}
|
selected={data.sort}
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
import { LINKED_INSTANCE_URL } from '$lib/instance.svelte.js'
|
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 { ReactiveState } from '$lib/promise.svelte'
|
||||||
import { type ListingType, type SortType } from 'lemmy-js-client'
|
import { type ListingType, type SortType } from 'lemmy-js-client'
|
||||||
|
|
||||||
export async function load({ url, fetch }) {
|
export async function load({ url, fetch }) {
|
||||||
const type =
|
const typeParam = url.searchParams.get('type')
|
||||||
(url.searchParams.get('type') as ListingType) ||
|
const typeInstance = typeParam?.split('instance-')[1]
|
||||||
(LINKED_INSTANCE_URL ? 'Local' : 'All')
|
|
||||||
|
const type = typeInstance
|
||||||
|
? 'Local'
|
||||||
|
: (typeParam as ListingType) || (LINKED_INSTANCE_URL ? 'Local' : 'All')
|
||||||
|
|
||||||
const sort = (url.searchParams.get('sort') as SortType) || 'TopDay'
|
const sort = (url.searchParams.get('sort') as SortType) || 'TopDay'
|
||||||
const page = Number(url.searchParams.get('page')) || 1
|
const page = Number(url.searchParams.get('page')) || 1
|
||||||
const query = url.searchParams.get('q') || ''
|
const query = url.searchParams.get('q') || ''
|
||||||
|
|
||||||
const communities =
|
const communities =
|
||||||
query != ''
|
query != ''
|
||||||
? await getClient(undefined, fetch).search({
|
? await client({ func: fetch, instanceURL: typeInstance }).search({
|
||||||
limit: 40,
|
limit: 40,
|
||||||
page: page,
|
page: page,
|
||||||
sort: sort,
|
sort: sort,
|
||||||
@@ -21,7 +25,10 @@ export async function load({ url, fetch }) {
|
|||||||
listing_type: type,
|
listing_type: type,
|
||||||
q: query,
|
q: query,
|
||||||
})
|
})
|
||||||
: await getClient(undefined, fetch).listCommunities({
|
: await client({
|
||||||
|
func: fetch,
|
||||||
|
instanceURL: typeInstance,
|
||||||
|
}).listCommunities({
|
||||||
limit: 40,
|
limit: 40,
|
||||||
page: page,
|
page: page,
|
||||||
sort: sort,
|
sort: sort,
|
||||||
@@ -31,7 +38,7 @@ export async function load({ url, fetch }) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
communities: new ReactiveState(communities.communities),
|
communities: new ReactiveState(communities.communities),
|
||||||
type: type,
|
type: typeParam ?? type,
|
||||||
sort: sort,
|
sort: sort,
|
||||||
query: query,
|
query: query,
|
||||||
page: page,
|
page: page,
|
||||||
|
|||||||
Reference in new issue
Block a user