feat: add more moderator actions

This commit is contained in:
Xyphyn committed 2023-08-23 17:53:33 -07:00
1 parent 5507cf8254
commit 22ce7bf39e
6 files changed
+96 -6

No files matched your search

+8 -2
View File
@@ -13,6 +13,8 @@
export let extractSelected: (item: T | null) => any export let extractSelected: (item: T | null) => any
export let extractName: (item: T) => string export let extractName: (item: T) => string
export let showWhenEmpty: boolean = false export let showWhenEmpty: boolean = false
let canSearch: boolean = false
export { canSearch as searchOnMount }
const debounce = (fn: Function, ms = 300) => { const debounce = (fn: Function, ms = 300) => {
let timeoutId: ReturnType<typeof setTimeout> let timeoutId: ReturnType<typeof setTimeout>
@@ -25,6 +27,7 @@
const dispatcher = createEventDispatcher<{ search: string }>() const dispatcher = createEventDispatcher<{ search: string }>()
const debounceFunc = debounce(() => { const debounceFunc = debounce(() => {
canSearch = true
dispatcher('search', query) dispatcher('search', query)
}, debounceTime) }, debounceTime)
</script> </script>
@@ -38,8 +41,11 @@
}} }}
{...$$restProps} {...$$restProps}
/> />
<Menu open={options.length != 0 || showWhenEmpty} alignment="bottom-left"> <Menu
{#if query == ''} open={(options.length != 0 || showWhenEmpty) && canSearch}
alignment="bottom-left"
>
{#if query == '' && showWhenEmpty}
<slot {extractName} {extractSelected} {query} /> <slot {extractName} {extractSelected} {query} />
{:else} {:else}
{#each options as option} {#each options as option}
@@ -40,6 +40,7 @@
on:keydown={(e) => dispatcher('keydown', e)} on:keydown={(e) => dispatcher('keydown', e)}
on:input={(e) => dispatcher('input', e)} on:input={(e) => dispatcher('input', e)}
on:change={(e) => dispatcher('change', e)} on:change={(e) => dispatcher('change', e)}
on:focus
{...$$restProps} {...$$restProps}
class={className} class={className}
{required} {required}
@@ -13,6 +13,7 @@
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 items: Community[] | undefined = undefined export let items: Community[] | undefined = undefined
export let showWhenEmpty: boolean = false
let showNone: boolean = false let showNone: boolean = false
const dispatcher = createEventDispatcher<{ select: Community }>() const dispatcher = createEventDispatcher<{ select: Community }>()
@@ -45,11 +46,11 @@
let:extractName let:extractName
let:extractSelected let:extractSelected
let:option let:option
showWhenEmpty {showWhenEmpty}
{...$$restProps} {...$$restProps}
let:query let:query
> >
{#if query == ''} {#if query == '' && showWhenEmpty}
<MenuButton on:click={() => dispatcher('select', undefined)}> <MenuButton on:click={() => dispatcher('select', undefined)}>
<Icon src={XCircle} size="16" mini /> <Icon src={XCircle} size="16" mini />
<div class="flex flex-col text-left"> <div class="flex flex-col text-left">
+20 -1
View File
@@ -38,6 +38,24 @@
'AdminPurgePost', 'AdminPurgePost',
'AdminPurgeComment', 'AdminPurgeComment',
]} ]}
optionNames={[
'All',
'Remove Post',
'Lock Post',
'Feature Post',
'Remove Comment',
'Remove Community',
'Ban From Community',
'Add Community',
'Transfer Community',
'Add',
'Ban',
'Hide Community',
'Purge Person',
'Purge Community',
'Purge Post',
'Purge Comment',
]}
selected={data.type} selected={data.type}
on:select={(e) => searchParam($page.url, 'type', e.detail, 'page')} on:select={(e) => searchParam($page.url, 'type', e.detail, 'page')}
/> />
@@ -47,6 +65,7 @@
placeholder="Filter by community" placeholder="Filter by community"
jwt={$profile?.jwt} jwt={$profile?.jwt}
listing_type="All" listing_type="All"
showWhenEmpty={true}
on:select={(e) => on:select={(e) =>
searchParam($page.url, 'community', e.detail?.id.toString(), 'page')} searchParam($page.url, 'community', e.detail?.id.toString(), 'page')}
/> />
@@ -61,7 +80,7 @@
<colgroup class="table-fixed"> <colgroup class="table-fixed">
<col width="8%" /> <col width="8%" />
<col width="18%" /> <col width="18%" />
<col width="8%" class="overflow-x-auto" /> <col width="12%" class="overflow-x-auto" />
<col width="8%" /> <col width="8%" />
<col width="10%" /> <col width="10%" />
<col width="18%" /> <col width="18%" />
+33 -1
View File
@@ -4,8 +4,11 @@ import type {
Community, Community,
ModAddCommunityView, ModAddCommunityView,
ModBanFromCommunityView, ModBanFromCommunityView,
ModFeaturePostView,
ModLockPostView,
ModRemoveCommentView, ModRemoveCommentView,
ModRemovePostView, ModRemovePostView,
ModTransferCommunityView,
ModlogActionType, ModlogActionType,
ModlogListParams, ModlogListParams,
Person, Person,
@@ -17,6 +20,8 @@ export type ActionName =
| 'postRemoval' | 'postRemoval'
| 'commentRemoval' | 'commentRemoval'
| 'postLock' | 'postLock'
| 'postUnlock'
| 'postUnfeature'
| 'postFeature' | 'postFeature'
| 'modAdd' | 'modAdd'
| 'modRemove' | 'modRemove'
@@ -27,6 +32,9 @@ type ModAction =
| ModRemoveCommentView | ModRemoveCommentView
| ModRemovePostView | ModRemovePostView
| ModAddCommunityView | ModAddCommunityView
| ModLockPostView
| ModFeaturePostView
| ModTransferCommunityView
export interface ModLog { export interface ModLog {
reason?: string reason?: string
@@ -81,8 +89,27 @@ export const _toModLog = (item: ModAction): ModLog => {
moderator: item.moderator, moderator: item.moderator,
moderatee: item.modded_person, moderatee: item.modded_person,
} }
} else if ('mod_feature_post' in item) {
return {
actionName: item.mod_feature_post.featured
? 'postFeature'
: 'postUnfeature',
timestamp: Date.parse(`${item.mod_feature_post.when_}Z`),
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: Date.parse(`${item.mod_lock_post.when_}Z`),
community: item.community,
link: `/post/${item.post.id}`,
moderator: item.moderator,
content: item.post.name,
}
} }
return { return {
actionName: 'Unknown', actionName: 'Unknown',
timestamp: 0, timestamp: 0,
@@ -109,7 +136,12 @@ export async function load({ url }) {
...results.banned_from_community, ...results.banned_from_community,
...results.removed_comments, ...results.removed_comments,
...results.removed_posts, ...results.removed_posts,
...results.added_to_community, ...results.added_to_community,
...results.transferred_to_community,
...results.featured_posts,
...results.locked_posts,
] ]
const moderationActions = moderation const moderationActions = moderation
+31
View File
@@ -2,6 +2,9 @@
import type { IconSource } from 'svelte-hero-icons' import type { IconSource } from 'svelte-hero-icons'
import { import {
Icon, Icon,
InformationCircle,
LockClosed,
LockOpen,
QuestionMarkCircle, QuestionMarkCircle,
Trash, Trash,
UserMinus, UserMinus,
@@ -53,6 +56,34 @@
text: 'Removed Mod', text: 'Removed Mod',
} }
} }
case 'postFeature': {
return {
icon: InformationCircle,
class: 'text-green-600 dark:text-green-400',
text: 'Featured Post',
}
}
case 'postUnfeature': {
return {
icon: InformationCircle,
class: 'text-red-600 dark:text-red-400',
text: 'Unfeatured Post',
}
}
case 'postLock': {
return {
icon: LockClosed,
class: 'text-yellow-600 dark:text-yellow-400',
text: 'Locked Post',
}
}
case 'postUnlock': {
return {
icon: LockOpen,
class: 'text-yellow-600 dark:text-yellow-400',
text: 'Unlocked Post',
}
}
} }
return { return {