diff --git a/src/lib/components/input/SearchInput.svelte b/src/lib/components/input/SearchInput.svelte index 4b1dea24..13df9129 100644 --- a/src/lib/components/input/SearchInput.svelte +++ b/src/lib/components/input/SearchInput.svelte @@ -12,6 +12,9 @@ export let options: T[] export let extractSelected: (item: T | null) => any export let extractName: (item: T) => string + export let showWhenEmpty: boolean = false + let canSearch: boolean = false + export { canSearch as searchOnMount } const debounce = (fn: Function, ms = 300) => { let timeoutId: ReturnType @@ -24,6 +27,7 @@ const dispatcher = createEventDispatcher<{ search: string }>() const debounceFunc = debounce(() => { + canSearch = true dispatcher('search', query) }, debounceTime) @@ -37,13 +41,20 @@ }} {...$$restProps} /> - - {#each options as option} - - extractSelected(option)}> - {extractName(option)} - - - {/each} + + {#if query == '' && showWhenEmpty} + + {:else} + {#each options as option} + + extractSelected(option)}> + {extractName(option)} + + + {/each} + {/if} diff --git a/src/lib/components/input/TextInput.svelte b/src/lib/components/input/TextInput.svelte index 9c69bc5a..af7df2ed 100644 --- a/src/lib/components/input/TextInput.svelte +++ b/src/lib/components/input/TextInput.svelte @@ -40,6 +40,7 @@ on:keydown={(e) => dispatcher('keydown', e)} on:input={(e) => dispatcher('input', e)} on:change={(e) => dispatcher('change', e)} + on:focus {...$$restProps} class={className} {required} diff --git a/src/lib/components/lemmy/ObjectAutocomplete.svelte b/src/lib/components/lemmy/ObjectAutocomplete.svelte index 4d73977f..66a6307f 100644 --- a/src/lib/components/lemmy/ObjectAutocomplete.svelte +++ b/src/lib/components/lemmy/ObjectAutocomplete.svelte @@ -5,6 +5,7 @@ import { getClient } from '$lib/lemmy.js' import type { Community, ListingType } from 'lemmy-js-client' import { createEventDispatcher } from 'svelte' + import { Icon, XCircle } from 'svelte-hero-icons' let type: 'community' = 'community' export let q: string = '' @@ -12,6 +13,8 @@ export let jwt: string | undefined = undefined export let listing_type: ListingType = 'Subscribed' export let items: Community[] | undefined = undefined + export let showWhenEmpty: boolean = false + let showNone: boolean = false const dispatcher = createEventDispatcher<{ select: Community }>() @@ -20,8 +23,11 @@ { + if (q == '') showNone = true + else showNone = false + const results = await getClient().search({ - q: q, + q: q || ' ', auth: jwt, type_: 'Communities', limit: 20, @@ -40,15 +46,27 @@ let:extractName let:extractSelected let:option + {showWhenEmpty} + {...$$restProps} + let:query > - extractSelected(option)}> - -
- {option.title} - - {new URL(option.actor_id).hostname} - -
-
+ {#if query == '' && showWhenEmpty} + dispatcher('select', undefined)}> + +
+ None +
+
+ {:else if option} + extractSelected(option)}> + +
+ {option.title} + + {new URL(option.actor_id).hostname} + +
+
+ {/if}
{/if} diff --git a/src/lib/components/lemmy/SiteCard.svelte b/src/lib/components/lemmy/SiteCard.svelte index 96a54b01..52995f41 100644 --- a/src/lib/components/lemmy/SiteCard.svelte +++ b/src/lib/components/lemmy/SiteCard.svelte @@ -54,6 +54,12 @@ +
+ +
{#if taglines && taglines.length > 0} { navigator.clipboard.writeText( - `${$page.url.origin}/post/${getInstance()}/${ - comment.post.id - }?thread=${comment.comment.path}#${comment.comment.id}` + `/comment/${getInstance()}/${comment.comment.id}` ) }} > diff --git a/src/lib/settings.ts b/src/lib/settings.ts index d969608f..bb2b5ecc 100644 --- a/src/lib/settings.ts +++ b/src/lib/settings.ts @@ -49,6 +49,7 @@ interface Settings { } newVote: boolean randomPlaceholders: boolean + modlogCardView: boolean | undefined } export const defaultSettings: Settings = { @@ -85,6 +86,7 @@ export const defaultSettings: Settings = { }, newVote: toBool(env.PUBLIC_NEW_VOTE_BUTTONS) ?? false, randomPlaceholders: toBool(env.PUBLIC_RANDOM_PLACEHOLDERS) ?? true, + modlogCardView: toBool(env.PUBLIC_MODLOG_CARD_VIEW) ?? undefined, } export const userSettings = writable(defaultSettings) diff --git a/src/routes/comment/[instance]/+page.ts b/src/routes/comment/[instance]/+page.ts new file mode 100644 index 00000000..7cec2e91 --- /dev/null +++ b/src/routes/comment/[instance]/+page.ts @@ -0,0 +1,6 @@ +import { getInstance } from '$lib/lemmy.js' +import { redirect } from '@sveltejs/kit' + +export function load({ params }) { + throw redirect(300, `/comment/${getInstance()}/${params.instance}`) +} diff --git a/src/routes/comment/[instance]/[id]/+page.ts b/src/routes/comment/[instance]/[id]/+page.ts new file mode 100644 index 00000000..1581aa15 --- /dev/null +++ b/src/routes/comment/[instance]/[id]/+page.ts @@ -0,0 +1,16 @@ +import { profile } from '$lib/auth.js' +import { getClient } from '$lib/lemmy.js' +import { redirect } from '@sveltejs/kit' +import { get } from 'svelte/store' + +export async function load({ params, fetch }) { + const comment = await getClient(undefined, fetch).getComment({ + id: Number(params.id), + auth: get(profile)?.jwt, + }) + + throw redirect( + 300, + `/post/${comment.comment_view.post.id}?thread=${comment.comment_view.comment.path}#${comment.comment_view.comment.id}` + ) +} diff --git a/src/routes/moderation/+page.svelte b/src/routes/moderation/+page.svelte index e95e7e2f..9d1e808c 100644 --- a/src/routes/moderation/+page.svelte +++ b/src/routes/moderation/+page.svelte @@ -6,26 +6,28 @@ import MultiSelect from '$lib/components/input/MultiSelect.svelte' import { page } from '$app/stores' import { goto } from '$app/navigation' - import { EnvelopeOpen, Icon, Inbox } from 'svelte-hero-icons' + import { EnvelopeOpen, Icon, Inbox, Newspaper } from 'svelte-hero-icons' import Placeholder from '$lib/components/ui/Placeholder.svelte' + import Button from '$lib/components/input/Button.svelte' + import { searchParam } from '$lib/util.js' export let data

Reports

- { - $page.url.searchParams.delete('page') - $page.url.searchParams.set('type', e.detail) - goto($page.url.toString(), { - invalidateAll: true, - }) - }} - /> +
+ searchParam($page.url, 'type', e.detail, 'page')} + /> + +
{#if data.items && data.items.length > 0}
diff --git a/src/routes/modlog/+page.svelte b/src/routes/modlog/+page.svelte index e69de29b..87e5954c 100644 --- a/src/routes/modlog/+page.svelte +++ b/src/routes/modlog/+page.svelte @@ -0,0 +1,147 @@ + + + + Modlog + + +
+

Modlog

+
+ searchParam($page.url, 'type', e.detail, 'page')} + /> +
+
Community
+ + searchParam($page.url, 'community', e.detail?.id.toString(), 'page')} + /> +
+ ($userSettings.modlogCardView = e.detail)} + /> +
+ {#if data.modlog} + {#if $userSettings.modlogCardView ?? !window.matchMedia('(min-width: 1600px)').matches} +
+ {#each data.modlog as modlog} + + {/each} +
+ {:else} +
+ + + + + + + + + + + + + + + + + + + + + + + + + {#each data.modlog as modlog} + + {/each} + +
TimeModeratorActionUserCommunityContentReasonLink
+
+ {/if} + {/if} + searchParam($page.url, 'page', e.detail.toString())} + /> +
+ + diff --git a/src/routes/modlog/+page.ts b/src/routes/modlog/+page.ts index e69de29b..1d6a5d89 100644 --- a/src/routes/modlog/+page.ts +++ b/src/routes/modlog/+page.ts @@ -0,0 +1,244 @@ +import { profile } from '$lib/auth.js' +import { getClient } from '$lib/lemmy.js' +import type { + AdminPurgeCommentView, + AdminPurgeCommunityView, + AdminPurgePersonView, + AdminPurgePostView, + Community, + ModAddCommunityView, + ModAddView, + ModBanFromCommunityView, + ModBanView, + ModFeaturePostView, + ModHideCommunityView, + ModLockPostView, + ModRemoveCommentView, + ModRemovePostView, + ModTransferCommunityView, + ModlogActionType, + ModlogListParams, + Person, +} from 'lemmy-js-client' +import { get } from 'svelte/store' + +export type ActionName = + | 'ban' + | 'banCommunity' + | 'unban' + | 'unbanCommunity' + | 'postRemoval' + | 'commentRemoval' + | 'postLock' + | 'postUnlock' + | 'postUnfeature' + | 'postFeature' + | 'modAdd' + | 'modRemove' + | 'purge' + | 'Unknown' + +type ModAction = + | ModBanFromCommunityView + | ModRemoveCommentView + | ModRemovePostView + | ModAddCommunityView + | ModLockPostView + | ModFeaturePostView + | ModTransferCommunityView + | AdminPurgeCommentView + | AdminPurgeCommunityView + | AdminPurgePostView + | AdminPurgePersonView + | ModHideCommunityView + | ModBanView + | ModAddView + +export interface ModLog { + reason?: string + moderatee?: Person + content?: string + moderator?: Person + community?: Community + actionName: ActionName + timestamp: number + link?: string +} + +const fullUserName = (user: Person) => + `${user.name}@${new URL(user.actor_id).hostname}` +const timestamp = (when: string) => Date.parse(`${when}Z`) + +export const _toModLog = (item: ModAction): ModLog => { + if ('mod_ban_from_community' in item) { + return { + moderator: item.moderator, + moderatee: item.banned_person, + community: item.community, + actionName: item.mod_ban_from_community.banned + ? 'banCommunity' + : 'unbanCommunity', + reason: item.mod_ban_from_community.reason, + timestamp: timestamp(item.mod_ban_from_community.when_), + } + } else if ('mod_remove_comment' in item) { + return { + actionName: 'commentRemoval', + community: item.community, + content: item.comment.content, + timestamp: timestamp(item.mod_remove_comment.when_), + moderatee: item.commenter, + moderator: item.moderator, + reason: item.mod_remove_comment.reason, + link: `/comment/${item.comment.id}`, + } + } else if ('mod_remove_post' in item) { + return { + actionName: 'postRemoval', + community: item.community, + content: item.post.name, + timestamp: timestamp(item.mod_remove_post.when_), + moderator: item.moderator, + reason: item.mod_remove_post.reason, + link: `/post/${item.post.id}`, + } + } else if ('mod_add_community' in item) { + return { + actionName: item.mod_add_community.removed ? 'modRemove' : 'modAdd', + community: item.community, + timestamp: timestamp(item.mod_add_community.when_), + moderator: item.moderator, + moderatee: item.modded_person, + } + } else if ('mod_feature_post' in item) { + return { + actionName: item.mod_feature_post.featured + ? 'postFeature' + : 'postUnfeature', + timestamp: timestamp(item.mod_feature_post.when_), + community: item.community, + link: `/post/${item.post.id}`, + moderator: item.moderator, + content: item.post.name, + } + } else if ('mod_lock_post' in item) { + return { + actionName: item.mod_lock_post.locked ? 'postLock' : 'postUnlock', + timestamp: timestamp(item.mod_lock_post.when_), + community: item.community, + link: `/post/${item.post.id}`, + moderator: item.moderator, + content: item.post.name, + } + } else if ('mod_transfer_community' in item) { + return { + actionName: 'Unknown', + timestamp: timestamp(item.mod_transfer_community.when_), + moderator: item.moderator, + moderatee: item.modded_person, + community: item.community, + } + } else if ('admin_purge_post' in item) { + return { + actionName: 'purge', + timestamp: timestamp(item.admin_purge_post.when_), + moderator: item.admin, + community: item.community, + content: 'Purged a post', + reason: item.admin_purge_post.reason, + } + } else if ('admin_purge_comment' in item) { + return { + actionName: 'purge', + timestamp: timestamp(item.admin_purge_comment.when_), + moderator: item.admin, + content: 'Purged a comment', + reason: item.admin_purge_comment.reason, + } + } else if ('admin_purge_community' in item) { + return { + actionName: 'purge', + timestamp: timestamp(item.admin_purge_community.when_), + moderator: item.admin, + content: 'Purged a community', + reason: item.admin_purge_community.reason, + } + } else if ('admin_purge_person' in item) { + return { + actionName: 'purge', + timestamp: timestamp(item.admin_purge_person.when_), + moderator: item.admin, + content: 'Purged a user', + reason: item.admin_purge_person.reason, + } + } else if ('mod_ban' in item) { + return { + actionName: item.mod_ban.banned ? 'ban' : 'unban', + timestamp: timestamp(item.mod_ban.when_), + moderator: item.moderator, + moderatee: item.banned_person, + reason: item.mod_ban.reason, + link: `/u/${fullUserName(item.banned_person)}`, + } + } else if ('mod_add' in item) { + return { + actionName: item.mod_add.removed ? 'modRemove' : 'modAdd', + timestamp: timestamp(item.mod_add.when_), + moderator: item.moderator, + moderatee: item.modded_person, + } + } + + return { + actionName: 'Unknown', + timestamp: 0, + } +} + +export async function load({ url }) { + let community = Number(url.searchParams.get('community')) || undefined + let modId = Number(url.searchParams.get('mod_id')) || undefined + const page = Number(url.searchParams.get('page')) || 1 + let type: ModlogActionType = + (url.searchParams.get('type') as ModlogActionType) || 'All' + + const results = await getClient().getModlog({ + auth: get(profile)?.jwt, + community_id: community, + limit: 40, + type_: type, + page: page, + mod_person_id: modId, + }) + + const moderation = [ + ...results.banned_from_community, + ...results.removed_comments, + ...results.removed_posts, + + ...results.added_to_community, + ...results.transferred_to_community, + + ...results.featured_posts, + ...results.locked_posts, + + ...results.admin_purged_comments, + ...results.admin_purged_communities, + ...results.admin_purged_posts, + ...results.admin_purged_persons, + + ...results.hidden_communities, + ...results.banned, + ...results.added, + ] + + const moderationActions = moderation + .map(_toModLog) + .sort((a, b) => b.timestamp - a.timestamp) + + return { + page: page, + type: type, + modlog: moderationActions, + } +} diff --git a/src/routes/modlog/ModlogAction.svelte b/src/routes/modlog/ModlogAction.svelte new file mode 100644 index 00000000..37eb12d4 --- /dev/null +++ b/src/routes/modlog/ModlogAction.svelte @@ -0,0 +1,132 @@ + + + + + + {actionData.text} + + diff --git a/src/routes/modlog/item/ModlogItemCard.svelte b/src/routes/modlog/item/ModlogItemCard.svelte new file mode 100644 index 00000000..9af77b05 --- /dev/null +++ b/src/routes/modlog/item/ModlogItemCard.svelte @@ -0,0 +1,61 @@ + + + +
+ {#if item.community} + + {/if} + + + +
+ {#if item.actionName} + Action + + + + {/if} + {#if item.moderator} + Moderator + + + {#if !item.moderator.admin} + + {/if} + + {/if} + {#if item.moderatee} + User + + {/if} + {#if item.link || item.content} + Item + {#if item.link && item.content} + + {item.content} + + {:else if item.content} +

{item.content}

+ {:else if item.link} + + {/if} + {/if} + {#if item.reason} + Reason +

{item.reason}

+ {/if} +
diff --git a/src/routes/modlog/item/ModlogItemTable.svelte b/src/routes/modlog/item/ModlogItemTable.svelte new file mode 100644 index 00000000..07122ae4 --- /dev/null +++ b/src/routes/modlog/item/ModlogItemTable.svelte @@ -0,0 +1,61 @@ + + + + + + + + + + {#if item.moderator} + + {/if} + + + + + + {#if item.moderatee} + + {/if} + + + {#if item.community} + + {/if} + + + {#if item.content} +

{item.content}

+ {/if} + + + {#if item.reason} +

{item.reason}

+ {/if} + + + {#if item.link} + + {/if} + +