Merge pull request #199 from 0xCmdrKeen/feature/modlog_instance_selection
Feature: allow instance selection on modlog page
This commit is contained in:
4 files changed
+63
-5
No files matched your search
@@ -4,23 +4,25 @@
|
|||||||
import type { Community, ListingType } from 'lemmy-js-client'
|
import type { Community, ListingType } from 'lemmy-js-client'
|
||||||
import { MenuButton, Search } from 'mono-svelte'
|
import { MenuButton, Search } from 'mono-svelte'
|
||||||
import { createEventDispatcher } from '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'
|
import { fly } from 'svelte/transition'
|
||||||
|
|
||||||
let type: 'community' | 'instance' = 'community'
|
export let type: 'community' | 'instance' = 'community'
|
||||||
export let q: string = ''
|
export let q: string = ''
|
||||||
|
|
||||||
|
export let instance: string | undefined = undefined
|
||||||
export let jwt: string | undefined = undefined
|
export let jwt: string | undefined = undefined
|
||||||
export let listing_type: ListingType = 'Subscribed'
|
export let listing_type: ListingType = 'Subscribed'
|
||||||
export let showWhenEmpty: boolean = false
|
export let showWhenEmpty: boolean = false
|
||||||
|
|
||||||
const dispatcher = createEventDispatcher<{ select: Community | undefined }>()
|
const dispatcher = createEventDispatcher<{ select: Community | undefined }>()
|
||||||
|
$: instances = type == 'instance' && getClient().getFederatedInstances()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if type == 'community'}
|
{#if type == 'community'}
|
||||||
<Search
|
<Search
|
||||||
search={async (q) => {
|
search={async (q) => {
|
||||||
const results = await getClient().search({
|
const results = await getClient(instance).search({
|
||||||
q: q || ' ',
|
q: q || ' ',
|
||||||
type_: 'Communities',
|
type_: 'Communities',
|
||||||
limit: 20,
|
limit: 20,
|
||||||
@@ -62,4 +64,41 @@
|
|||||||
</MenuButton>
|
</MenuButton>
|
||||||
</div>
|
</div>
|
||||||
</Search>
|
</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}
|
{/if}
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
export let q: string = ''
|
export let q: string = ''
|
||||||
|
|
||||||
|
export let instance: string | undefined = undefined
|
||||||
export let listing_type: ListingType = 'Subscribed'
|
export let listing_type: ListingType = 'Subscribed'
|
||||||
export let showWhenEmpty: boolean = false
|
export let showWhenEmpty: boolean = false
|
||||||
|
|
||||||
@@ -17,7 +18,7 @@
|
|||||||
|
|
||||||
<Search
|
<Search
|
||||||
search={async (q) => {
|
search={async (q) => {
|
||||||
const results = await getClient().search({
|
const results = await getClient(instance).search({
|
||||||
q: q || ' ',
|
q: q || ' ',
|
||||||
type_: 'Users',
|
type_: 'Users',
|
||||||
limit: 20,
|
limit: 20,
|
||||||
|
|||||||
@@ -74,6 +74,22 @@
|
|||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col md:flex-row md:items-center gap-2 w-full">
|
<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
|
<ObjectAutocomplete
|
||||||
placeholder="Filter by community"
|
placeholder="Filter by community"
|
||||||
jwt={$profile?.jwt}
|
jwt={$profile?.jwt}
|
||||||
@@ -91,6 +107,7 @@
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<UserAutocomplete
|
<UserAutocomplete
|
||||||
|
instance={$page.url.searchParams.get('instance') || undefined}
|
||||||
placeholder="Filter by user"
|
placeholder="Filter by user"
|
||||||
jwt={$profile?.jwt}
|
jwt={$profile?.jwt}
|
||||||
listing_type="All"
|
listing_type="All"
|
||||||
|
|||||||
@@ -203,6 +203,7 @@ export const _toModLog = (item: ModAction): ModLog => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function load({ url }) {
|
export async function load({ url }) {
|
||||||
|
let instance = url.searchParams.get('instance') || undefined
|
||||||
let community = Number(url.searchParams.get('community')) || undefined
|
let community = Number(url.searchParams.get('community')) || undefined
|
||||||
let user = Number(url.searchParams.get('user')) || undefined
|
let user = Number(url.searchParams.get('user')) || undefined
|
||||||
let modId = Number(url.searchParams.get('mod_id')) || undefined
|
let modId = Number(url.searchParams.get('mod_id')) || undefined
|
||||||
@@ -210,7 +211,7 @@ export async function load({ url }) {
|
|||||||
let type: ModlogActionType =
|
let type: ModlogActionType =
|
||||||
(url.searchParams.get('type') as ModlogActionType) || 'All'
|
(url.searchParams.get('type') as ModlogActionType) || 'All'
|
||||||
|
|
||||||
const results = await getClient().getModlog({
|
const results = await getClient(instance).getModlog({
|
||||||
community_id: community,
|
community_id: community,
|
||||||
limit: 40,
|
limit: 40,
|
||||||
type_: type,
|
type_: type,
|
||||||
|
|||||||
Reference in new issue
Block a user