Merge pull request #199 from 0xCmdrKeen/feature/modlog_instance_selection

Feature: allow instance selection on modlog page
This commit is contained in:
Xylight authored and GitHub committed 2023-11-27 16:20:47 -08:00
commit 5cce0fb736
4 files changed
+63 -5

No files matched your search

@@ -4,23 +4,25 @@
import type { Community, ListingType } from 'lemmy-js-client'
import { MenuButton, Search } from 'mono-svelte'
import { createEventDispatcher } from 'svelte'
import { Icon, XCircle } from 'svelte-hero-icons'
import { Icon, XCircle, ServerStack } from 'svelte-hero-icons'
import { fly } from 'svelte/transition'
let type: 'community' | 'instance' = 'community'
export let type: 'community' | 'instance' = 'community'
export let q: string = ''
export let instance: string | undefined = undefined
export let jwt: string | undefined = undefined
export let listing_type: ListingType = 'Subscribed'
export let showWhenEmpty: boolean = false
const dispatcher = createEventDispatcher<{ select: Community | undefined }>()
$: instances = type == 'instance' && getClient().getFederatedInstances()
</script>
{#if type == 'community'}
<Search
search={async (q) => {
const results = await getClient().search({
const results = await getClient(instance).search({
q: q || ' ',
type_: 'Communities',
limit: 20,
@@ -62,4 +64,41 @@
</MenuButton>
</div>
</Search>
{:else if type == 'instance'}
<Search
search={async (q) => {
const results = await instances || {}
return q ? (results.federated_instances?.linked || []).filter(
(i) => i.domain.includes(q)
) : []
}}
extractName={(i) => `${i.domain}`}
on:select
bind:query={q}
{showWhenEmpty}
{...$$restProps}
let:item
let:select
>
<div class="w-full h-full" slot="noresults">
{#if q == '' && showWhenEmpty}
<MenuButton on:click={() => dispatcher('select', undefined)}>
<div class="flex flex-col text-left">
<span>None (Start typing to search)</span>
</div>
</MenuButton>
{:else}
<span class="mx-auto my-auto">No results.</span>
{/if}
</div>
<div in:fly|global={{ y: -4, opacity: 0 }}>
<MenuButton on:click={() => select(item)}>
<Icon src={ServerStack} size="16" mini />
<div class="flex flex-col text-left">
<span>{item.domain}</span>
</div>
</MenuButton>
</div>
</Search>
{/if}
@@ -9,6 +9,7 @@
export let q: string = ''
export let instance: string | undefined = undefined
export let listing_type: ListingType = 'Subscribed'
export let showWhenEmpty: boolean = false
@@ -17,7 +18,7 @@
<Search
search={async (q) => {
const results = await getClient().search({
const results = await getClient(instance).search({
q: q || ' ',
type_: 'Users',
limit: 20,
+17
View File
@@ -74,6 +74,22 @@
</Select>
</div>
<div class="flex flex-col md:flex-row md:items-center gap-2 w-full">
<ObjectAutocomplete
type="instance"
placeholder="Filter by instance"
jwt={$profile?.jwt}
showWhenEmpty={true}
label="Instance"
class="flex-1"
q={$page.url.searchParams.get('instance') || ''}
on:select={(e) =>
searchParam(
$page.url,
'instance',
e.detail?.domain.toString() ?? '',
'page', 'community', 'user', 'mod_id'
)}
/>
<ObjectAutocomplete
placeholder="Filter by community"
jwt={$profile?.jwt}
@@ -91,6 +107,7 @@
)}
/>
<UserAutocomplete
instance={$page.url.searchParams.get('instance') || undefined}
placeholder="Filter by user"
jwt={$profile?.jwt}
listing_type="All"
+2 -1
View File
@@ -203,6 +203,7 @@ export const _toModLog = (item: ModAction): ModLog => {
}
export async function load({ url }) {
let instance = url.searchParams.get('instance') || undefined
let community = Number(url.searchParams.get('community')) || undefined
let user = Number(url.searchParams.get('user')) || undefined
let modId = Number(url.searchParams.get('mod_id')) || undefined
@@ -210,7 +211,7 @@ export async function load({ url }) {
let type: ModlogActionType =
(url.searchParams.get('type') as ModlogActionType) || 'All'
const results = await getClient().getModlog({
const results = await getClient(instance).getModlog({
community_id: community,
limit: 40,
type_: type,