feat: add moderation tools (#33)
* feat: Add post submission removal * feat: add comment submission removal * feat: add report viewing and resolving * misc: add notification dot * misc: add locked thread badge * feat: add thread locking * feat: add initiating message conversations * feat: add post pinning/unpinning * misc: bump version * fix: tweak lock colors * fix: update post data on pin * fix: return if reason is empty
This commit is contained in:
1 parent
53ef843cde
commit
d3aae647a8
29 files changed
+835
-67
No files matched your search
@@ -88,7 +88,6 @@
|
||||
</a>
|
||||
{:else}
|
||||
<button
|
||||
disabled={loading}
|
||||
{...$$restProps}
|
||||
on:click
|
||||
class="{`
|
||||
@@ -96,7 +95,8 @@
|
||||
${buttonSize[size]}
|
||||
${buttonRoundness[rounded]}
|
||||
text-sm transition-colors disabled:!opacity-70 disabled:!pointer-events-none
|
||||
disabled:!border disabled:!border-slate-300 disabled:!bg-slate-200 disabled:dark:!border-zinc-700 disabled:dark:!bg-zinc-800
|
||||
disabled:!border disabled:!border-slate-300 disabled:!bg-slate-200
|
||||
disabled:dark:!border-zinc-700 disabled:dark:!bg-zinc-800 disabled:text-inherit
|
||||
${$$props.class}
|
||||
`} {loading
|
||||
? color == 'primary'
|
||||
|
||||
@@ -22,7 +22,9 @@
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import { isCommentMutable } from '$lib/components/lemmy/post/helpers.js'
|
||||
import { report } from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import { isMod, report } from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte'
|
||||
import CommentModerationMenu from '$lib/components/lemmy/moderation/CommentModerationMenu.svelte'
|
||||
|
||||
export let comment: CommentView
|
||||
export let replying: boolean = false
|
||||
@@ -59,10 +61,18 @@
|
||||
bind:vote={comment.my_vote}
|
||||
commentId={comment.comment.id}
|
||||
/>
|
||||
<Button color="elevatedLow" size="sm" on:click={() => (replying = !replying)}>
|
||||
<Button
|
||||
color="elevatedLow"
|
||||
size="sm"
|
||||
on:click={() => (replying = !replying)}
|
||||
disabled={comment.post.locked}
|
||||
>
|
||||
<Icon src={ArrowUturnLeft} width={14} height={14} mini />
|
||||
<span class="text-xs">Reply</span>
|
||||
</Button>
|
||||
{#if $user && isMod($user, comment.community.id)}
|
||||
<CommentModerationMenu item={comment} />
|
||||
{/if}
|
||||
<Menu
|
||||
let:toggleOpen
|
||||
class="h-[26px] top-0 leading-3"
|
||||
@@ -91,7 +101,7 @@
|
||||
</MenuButton>
|
||||
{#if $user && $authData && isCommentMutable(comment, $user.local_user_view)}
|
||||
<MenuButton
|
||||
color={Color.dangerSecondary}
|
||||
color="dangerSecondary"
|
||||
on:click={async () => {
|
||||
if (!$authData) return
|
||||
try {
|
||||
@@ -117,10 +127,7 @@
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if $authData && $user?.local_user_view.person.id != comment.creator.id}
|
||||
<MenuButton
|
||||
on:click={() => report(comment)}
|
||||
color={Color.dangerSecondary}
|
||||
>
|
||||
<MenuButton on:click={() => report(comment)} color="dangerSecondary">
|
||||
<Icon src={Flag} mini size="16" />
|
||||
<span>Report</span>
|
||||
</MenuButton>
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
export let postId: number
|
||||
export let parentId: number | undefined = undefined
|
||||
export let locked: boolean = false
|
||||
|
||||
const dispatch = createEventDispatcher<{ comment: CommentResponse }>()
|
||||
|
||||
@@ -51,9 +52,10 @@
|
||||
<div class="flex flex-col gap-2 relative">
|
||||
<TextArea
|
||||
rows={4}
|
||||
placeholder="What are you thinking?"
|
||||
placeholder={locked ? 'This post is locked.' : 'What are you thinking?'}
|
||||
class="!bg-slate-100 dark:!bg-zinc-900"
|
||||
bind:value={newComment}
|
||||
disabled={locked}
|
||||
/>
|
||||
<div class="sm:ml-auto sm:w-28">
|
||||
<Button
|
||||
@@ -63,6 +65,7 @@
|
||||
size="lg"
|
||||
class="w-full"
|
||||
{loading}
|
||||
disabled={locked || loading}
|
||||
>
|
||||
Submit
|
||||
</Button>
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<script lang="ts">
|
||||
import { authData, getClient, user } from '$lib/lemmy'
|
||||
import type {
|
||||
CommentView,
|
||||
Community,
|
||||
CommunityView,
|
||||
PostView,
|
||||
} from 'lemmy-js-client'
|
||||
import { isMod, remove } from './moderation'
|
||||
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
||||
import { Icon, Trash } from 'svelte-hero-icons'
|
||||
import { Color } from '$lib/ui/colors.js'
|
||||
import { isComment } from '$lib/lemmy/item.js'
|
||||
|
||||
export let item: PostView | CommentView
|
||||
</script>
|
||||
|
||||
<Menu let:toggleOpen alignment="bottom-center" class="top-0 h-[26px] w-[26px]">
|
||||
<Button
|
||||
class="!p-1 hover:text-green-500 text-zinc-400"
|
||||
size="sm"
|
||||
on:click={toggleOpen}
|
||||
slot="button"
|
||||
color="elevatedLow"
|
||||
{...$$restProps}
|
||||
>
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 20 22"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
slot="icon"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
clip-rule="evenodd"
|
||||
d="M10.516 1.17C10.3767 1.03791 10.192 0.964283 10 0.964283C9.80801 0.964283 9.62333 1.03791 9.484 1.17C7.36127 3.18588 4.53412 4.29133 1.607 4.25C1.44753 4.24793 1.29156 4.29674 1.16172 4.38935C1.03189 4.48196 0.934957 4.61355 0.885 4.765C0.462973 6.05116 0.248618 7.39637 0.25 8.75C0.25 14.692 4.314 19.683 9.813 21.098C9.93566 21.1296 10.0643 21.1296 10.187 21.098C15.686 19.683 19.75 14.692 19.75 8.75C19.75 7.36 19.527 6.02 19.115 4.765C19.0652 4.61336 18.9684 4.48156 18.8385 4.38875C18.7087 4.29595 18.5526 4.247 18.393 4.249L18.25 4.25C15.254 4.25 12.533 3.08 10.516 1.17Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
</svg>
|
||||
</Button>
|
||||
<span class="px-4 py-1 my-1 text-xs text-slate-600 dark:text-zinc-400">
|
||||
Moderation
|
||||
</span>
|
||||
<MenuButton color="success" on:click={() => remove(item)}>
|
||||
<Icon src={Trash} size="16" mini />
|
||||
{#if isComment(item)}
|
||||
{item.comment.removed ? 'Restore' : 'Remove'}
|
||||
{:else}
|
||||
{item.post.removed ? 'Restore' : 'Remove'}
|
||||
{/if}
|
||||
</MenuButton>
|
||||
</Menu>
|
||||
@@ -1,6 +1,8 @@
|
||||
<script lang="ts">
|
||||
import RemoveModal from '$lib/components/lemmy/moderation/RemoveModal.svelte'
|
||||
import { modals } from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import ReportModal from './ReportModal.svelte'
|
||||
</script>
|
||||
|
||||
<ReportModal bind:open={$modals.reporting.open} item={$modals.reporting.item} />
|
||||
<RemoveModal bind:open={$modals.removing.open} item={$modals.removing.item} />
|
||||
@@ -0,0 +1,151 @@
|
||||
<script lang="ts">
|
||||
import { authData, getClient, user } from '$lib/lemmy'
|
||||
import type {
|
||||
CommentView,
|
||||
Community,
|
||||
CommunityView,
|
||||
PostView,
|
||||
} from 'lemmy-js-client'
|
||||
import { isMod, remove } from './moderation'
|
||||
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
||||
import {
|
||||
Icon,
|
||||
InformationCircle,
|
||||
LockClosed,
|
||||
LockOpen,
|
||||
Trash,
|
||||
} from 'svelte-hero-icons'
|
||||
import { Color } from '$lib/ui/colors.js'
|
||||
import { isComment, isPost } from '$lib/lemmy/item.js'
|
||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
|
||||
export let item: PostView | CommentView
|
||||
|
||||
let locking = false
|
||||
let pinning = false
|
||||
|
||||
$: acting = locking || pinning
|
||||
|
||||
async function lock(lock: boolean) {
|
||||
if (!$authData || !isPost(item)) return
|
||||
locking = true
|
||||
|
||||
try {
|
||||
await getClient().lockPost({
|
||||
auth: $authData.token,
|
||||
locked: lock,
|
||||
post_id: item.post.id,
|
||||
})
|
||||
|
||||
item.post.locked = lock
|
||||
|
||||
toast({
|
||||
content: `Successfully ${
|
||||
lock ? 'locked' : 'unlocked'
|
||||
} that post. You must refresh to see changes.`,
|
||||
type: ToastType.success,
|
||||
})
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: err as any,
|
||||
type: ToastType.error,
|
||||
})
|
||||
}
|
||||
|
||||
locking = false
|
||||
}
|
||||
|
||||
async function pin(pinned: boolean) {
|
||||
if (!$authData || !isPost(item)) return
|
||||
|
||||
pinning = true
|
||||
|
||||
try {
|
||||
await getClient().featurePost({
|
||||
feature_type: 'Community',
|
||||
auth: $authData.token,
|
||||
featured: pinned,
|
||||
post_id: item.post.id,
|
||||
})
|
||||
|
||||
item.post.featured_community = pinned
|
||||
|
||||
toast({
|
||||
content: `Successfully ${
|
||||
pinned ? 'pinned' : 'unpinned'
|
||||
} that post. You must refresh to see changes.`,
|
||||
type: ToastType.success,
|
||||
})
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: err as any,
|
||||
type: ToastType.error,
|
||||
})
|
||||
}
|
||||
|
||||
pinning = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<Menu let:toggleOpen alignment="bottom-right">
|
||||
<Button
|
||||
class="!p-1.5 hover:text-green-500 text-zinc-400"
|
||||
on:click={toggleOpen}
|
||||
slot="button"
|
||||
size="sm"
|
||||
loading={acting}
|
||||
{...$$restProps}
|
||||
>
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 20 22"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
slot="icon"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
clip-rule="evenodd"
|
||||
d="M10.516 1.17C10.3767 1.03791 10.192 0.964283 10 0.964283C9.80801 0.964283 9.62333 1.03791 9.484 1.17C7.36127 3.18588 4.53412 4.29133 1.607 4.25C1.44753 4.24793 1.29156 4.29674 1.16172 4.38935C1.03189 4.48196 0.934957 4.61355 0.885 4.765C0.462973 6.05116 0.248618 7.39637 0.25 8.75C0.25 14.692 4.314 19.683 9.813 21.098C9.93566 21.1296 10.0643 21.1296 10.187 21.098C15.686 19.683 19.75 14.692 19.75 8.75C19.75 7.36 19.527 6.02 19.115 4.765C19.0652 4.61336 18.9684 4.48156 18.8385 4.38875C18.7087 4.29595 18.5526 4.247 18.393 4.249L18.25 4.25C15.254 4.25 12.533 3.08 10.516 1.17Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
</svg>
|
||||
</Button>
|
||||
<span class="px-4 py-1 my-1 text-xs text-slate-600 dark:text-zinc-400">
|
||||
Moderation
|
||||
</span>
|
||||
<MenuButton
|
||||
color="warning"
|
||||
on:click={() => lock(!item.post.locked)}
|
||||
loading={locking}
|
||||
disabled={locking}
|
||||
>
|
||||
<Icon
|
||||
src={item.post.locked ? LockOpen : LockClosed}
|
||||
size="16"
|
||||
mini
|
||||
slot="icon"
|
||||
/>
|
||||
{item.post.locked ? 'Unlock' : 'Lock'}
|
||||
</MenuButton>
|
||||
<MenuButton
|
||||
color="success"
|
||||
on:click={() => pin(isPost(item) ? !item.post.featured_community : false)}
|
||||
loading={pinning}
|
||||
disabled={pinning}
|
||||
>
|
||||
<Icon src={InformationCircle} size="16" mini />
|
||||
{item.post.featured_community ? 'Unpin' : 'Pin'}
|
||||
</MenuButton>
|
||||
<MenuButton color="dangerSecondary" on:click={() => remove(item)}>
|
||||
<Icon src={Trash} size="16" mini />
|
||||
{#if isComment(item)}
|
||||
{item.comment.removed ? 'Restore' : 'Remove'}
|
||||
{:else}
|
||||
{item.post.removed ? 'Restore' : 'Remove'}
|
||||
{/if}
|
||||
</MenuButton>
|
||||
</Menu>
|
||||
@@ -0,0 +1,110 @@
|
||||
<script lang="ts">
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import TextArea from '$lib/components/input/TextArea.svelte'
|
||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
import { authData, getClient } from '$lib/lemmy.js'
|
||||
import { isComment, isPost } from '$lib/lemmy/item.js'
|
||||
import type { CommentView, PostView } from 'lemmy-js-client'
|
||||
|
||||
export let open: boolean
|
||||
export let item: PostView | CommentView | undefined = undefined
|
||||
|
||||
let reason = ''
|
||||
let loading = false
|
||||
|
||||
$: removed = item
|
||||
? isComment(item)
|
||||
? item.comment.removed
|
||||
: item.post.removed
|
||||
: false
|
||||
|
||||
async function remove() {
|
||||
if (!item) return
|
||||
if (!$authData) throw new Error('Unauthenticated')
|
||||
|
||||
loading = true
|
||||
|
||||
try {
|
||||
if (isComment(item)) {
|
||||
await getClient().removeComment({
|
||||
auth: $authData.token,
|
||||
comment_id: item.comment.id,
|
||||
removed: !removed,
|
||||
reason: reason || undefined,
|
||||
})
|
||||
item.comment.removed = !removed
|
||||
} else if (isPost(item)) {
|
||||
await getClient().removePost({
|
||||
auth: $authData.token,
|
||||
post_id: item.post.id,
|
||||
removed: !removed,
|
||||
reason: reason || undefined,
|
||||
})
|
||||
|
||||
item.post.removed = !removed
|
||||
}
|
||||
|
||||
open = false
|
||||
|
||||
toast({
|
||||
content: `Successfully ${
|
||||
removed ? 'restored' : 'removed'
|
||||
} that submission.`,
|
||||
type: ToastType.success,
|
||||
})
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: err as any,
|
||||
type: ToastType.error,
|
||||
})
|
||||
}
|
||||
|
||||
loading = false
|
||||
}
|
||||
|
||||
const resetText = () => (reason = '')
|
||||
|
||||
$: {
|
||||
if (item) {
|
||||
resetText()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<Modal bind:open>
|
||||
<span slot="title">{removed ? 'Restoring' : 'Removing'} submission</span>
|
||||
{#if item}
|
||||
<form
|
||||
on:submit|preventDefault={remove}
|
||||
class="flex flex-col gap-4 list-none"
|
||||
>
|
||||
{#if isComment(item)}
|
||||
<Comment
|
||||
node={{
|
||||
children: [],
|
||||
comment_view: item,
|
||||
depth: 1,
|
||||
}}
|
||||
postId={item.post.id}
|
||||
actions={false}
|
||||
/>
|
||||
{:else if isPost(item)}
|
||||
<Post actions={false} post={item} />
|
||||
{/if}
|
||||
|
||||
<TextArea
|
||||
rows={3}
|
||||
label="Reason"
|
||||
placeholder="Optional"
|
||||
bind:value={reason}
|
||||
/>
|
||||
|
||||
<Button color="primary" size="lg" {loading} disabled={loading} submit>
|
||||
{removed ? 'Restore' : 'Remove'}
|
||||
</Button>
|
||||
</form>
|
||||
{/if}
|
||||
</Modal>
|
||||
@@ -21,7 +21,7 @@
|
||||
let reason = ''
|
||||
|
||||
async function report() {
|
||||
if (!item || !$authData) return
|
||||
if (!item || !$authData || reason == '') return
|
||||
loading = true
|
||||
|
||||
try {
|
||||
@@ -38,6 +38,7 @@
|
||||
reason: reason,
|
||||
})
|
||||
}
|
||||
open = false
|
||||
toast({
|
||||
content: 'That submission has been reported.',
|
||||
type: ToastType.success,
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<script lang="ts">
|
||||
export let width: number = 16
|
||||
</script>
|
||||
|
||||
<svg
|
||||
{width}
|
||||
height={width}
|
||||
viewBox="0 0 20 22"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
clip-rule="evenodd"
|
||||
d="M10.516 1.17C10.3767 1.03791 10.192 0.964283 10 0.964283C9.80801 0.964283 9.62333 1.03791 9.484 1.17C7.36127 3.18588 4.53412 4.29133 1.607 4.25C1.44753 4.24793 1.29156 4.29674 1.16172 4.38935C1.03189 4.48196 0.934957 4.61355 0.885 4.765C0.462973 6.05116 0.248618 7.39637 0.25 8.75C0.25 14.692 4.314 19.683 9.813 21.098C9.93566 21.1296 10.0643 21.1296 10.187 21.098C15.686 19.683 19.75 14.692 19.75 8.75C19.75 7.36 19.527 6.02 19.115 4.765C19.0652 4.61336 18.9684 4.48156 18.8385 4.38875C18.7087 4.29595 18.5526 4.247 18.393 4.249L18.25 4.25C15.254 4.25 12.533 3.08 10.516 1.17Z"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
/>
|
||||
</svg>
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { CommentView, PostView } from 'lemmy-js-client'
|
||||
import type { CommentView, MyUserInfo, PostView } from 'lemmy-js-client'
|
||||
import { writable } from 'svelte/store'
|
||||
|
||||
interface Modals {
|
||||
@@ -6,6 +6,10 @@ interface Modals {
|
||||
open: boolean
|
||||
item: PostView | CommentView | undefined
|
||||
}
|
||||
removing: {
|
||||
open: boolean
|
||||
item: PostView | CommentView | undefined
|
||||
}
|
||||
}
|
||||
|
||||
export let modals = writable<Modals>({
|
||||
@@ -13,6 +17,10 @@ export let modals = writable<Modals>({
|
||||
open: false,
|
||||
item: undefined,
|
||||
},
|
||||
removing: {
|
||||
open: false,
|
||||
item: undefined,
|
||||
},
|
||||
})
|
||||
|
||||
export function report(item: PostView | CommentView) {
|
||||
@@ -24,3 +32,20 @@ export function report(item: PostView | CommentView) {
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
export function remove(item: PostView | CommentView) {
|
||||
modals.update((m) => ({
|
||||
...m,
|
||||
removing: {
|
||||
open: true,
|
||||
item: item,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
export const isMod = (me: MyUserInfo, community: number) =>
|
||||
me.moderates.map((c) => c.community.id).includes(community)
|
||||
|
||||
export const isModOfAny = (me?: MyUserInfo) => me && me.moderates.length > 0
|
||||
|
||||
export const isAdmin = (me: MyUserInfo) => me.local_user_view.person.admin
|
||||
@@ -26,6 +26,8 @@
|
||||
upvotes={post.counts.upvotes}
|
||||
downvotes={post.counts.downvotes}
|
||||
deleted={post.post.deleted}
|
||||
removed={post.post.removed}
|
||||
locked={post.post.locked}
|
||||
featured={post.post.featured_local || post.post.featured_community}
|
||||
nsfw={post.post.nsfw}
|
||||
saved={post.saved}
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
||||
import PostForm from '$lib/components/lemmy/post/PostForm.svelte'
|
||||
import { report } from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import { isMod, report } from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte'
|
||||
|
||||
export let post: PostView
|
||||
|
||||
@@ -98,7 +99,11 @@
|
||||
<Icon slot="icon" src={ChatBubbleOvalLeft} mini width={16} height={16} />
|
||||
<FormattedNumber number={post.counts.comments} />
|
||||
</Button>
|
||||
<Menu alignment="bottom-right" class="ml-auto overflow-auto" let:toggleOpen>
|
||||
<div class="ml-auto" />
|
||||
{#if $user && isMod($user, post.community.id)}
|
||||
<ModerationMenu item={post} community={post.community} />
|
||||
{/if}
|
||||
<Menu alignment="bottom-right" class="overflow-auto" let:toggleOpen>
|
||||
<Button
|
||||
slot="button"
|
||||
label="Post actions"
|
||||
@@ -148,13 +153,13 @@
|
||||
{post.saved ? 'Unsave' : 'Save'}
|
||||
</MenuButton>
|
||||
{#if $user && isMutable(post, $user.local_user_view)}
|
||||
<MenuButton on:click={deletePost} color={Color.dangerSecondary}>
|
||||
<MenuButton on:click={deletePost} color="dangerSecondary">
|
||||
<Icon src={Trash} width={16} mini />
|
||||
Delete
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if $user?.local_user_view.person.id != post.creator.id}
|
||||
<MenuButton on:click={() => report(post)} color={Color.dangerSecondary}>
|
||||
<MenuButton on:click={() => report(post)} color="dangerSecondary">
|
||||
<Icon src={Flag} width={16} mini />
|
||||
Report
|
||||
</MenuButton>
|
||||
|
||||
@@ -202,7 +202,13 @@
|
||||
bind:files={data.image}
|
||||
/>
|
||||
</div>
|
||||
<Button submit color="primary" loading={data.loading} size="lg">
|
||||
<Button
|
||||
submit
|
||||
color="primary"
|
||||
loading={data.loading}
|
||||
size="lg"
|
||||
disabled={data.loading}
|
||||
>
|
||||
Submit
|
||||
</Button>
|
||||
</form>
|
||||
@@ -5,7 +5,13 @@
|
||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||
import type { Community, Person } from 'lemmy-js-client'
|
||||
import { Bookmark, Icon, InformationCircle, Trash } from 'svelte-hero-icons'
|
||||
import {
|
||||
Bookmark,
|
||||
Icon,
|
||||
InformationCircle,
|
||||
LockClosed,
|
||||
Trash,
|
||||
} from 'svelte-hero-icons'
|
||||
|
||||
export let community: Community
|
||||
export let user: Person | undefined = undefined
|
||||
@@ -20,13 +26,17 @@
|
||||
export let saved: boolean
|
||||
export let featured: boolean
|
||||
export let deleted: boolean
|
||||
export let removed: boolean = false
|
||||
export let locked: boolean = false
|
||||
</script>
|
||||
|
||||
<span class="flex flex-row gap-2 text-sm items-center">
|
||||
<Avatar url={community.icon} width={24} alt={community.name} />
|
||||
<div class="flex flex-col text-xs">
|
||||
<CommunityLink {community} />
|
||||
<span class="text-slate-600 dark:text-zinc-400 flex flex-row gap-1 flex-wrap">
|
||||
<span
|
||||
class="text-slate-600 dark:text-zinc-400 flex flex-row gap-1 flex-wrap"
|
||||
>
|
||||
{#if user}
|
||||
<UserLink {user} />
|
||||
<span>•</span>
|
||||
@@ -50,6 +60,16 @@
|
||||
<Icon src={Bookmark} mini width={16} />
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if locked}
|
||||
<Badge class="bg-yellow-400 text-black py-1" label="Locked">
|
||||
<Icon src={LockClosed} mini width={16} />
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if removed}
|
||||
<Badge class="bg-green-600 text-white py-1" label="Removed">
|
||||
<Icon src={Trash} mini width={16} />
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if deleted}
|
||||
<Badge class="bg-red-600 text-white py-1" label="Deleted">
|
||||
<Icon src={Trash} mini width={16} />
|
||||
|
||||
@@ -6,6 +6,3 @@ export const isMutable = (post: PostView, me: PersonView) =>
|
||||
export const isCommentMutable = (comment: CommentView, me: PersonView) =>
|
||||
(me.person.admin && comment.comment.local) ||
|
||||
me.person.id == comment.creator.id
|
||||
|
||||
export const isComment = (item: CommentView | PostView): item is CommentView =>
|
||||
'comment' in item
|
||||
@@ -14,7 +14,7 @@
|
||||
</script>
|
||||
|
||||
<a
|
||||
class="items-center flex flex-row gap-1 hover:underline"
|
||||
class="items-center inline-flex flex-row gap-1 hover:underline"
|
||||
href={linkFromCommunity(user)}
|
||||
>
|
||||
{#if avatar}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
import { goto } from '$app/navigation'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import Link from '$lib/components/input/Link.svelte'
|
||||
import ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte'
|
||||
import { isModOfAny } from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import Logo from '$lib/components/ui/Logo.svelte'
|
||||
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
|
||||
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
||||
@@ -40,7 +42,7 @@
|
||||
<div class="flex flex-row gap-2 items-center mr-auto">
|
||||
<a href="/" class="flex flex-row items-center gap-2">
|
||||
<Logo width={40} />
|
||||
<div class="flex flex-row items-center gap-2 max-[400px]:hidden">
|
||||
<div class="flex flex-row items-center gap-2 max-[500px]:hidden">
|
||||
<span class="opacity-30 text-xl">/</span>
|
||||
<span class="text-sm font-bold">
|
||||
{$instance}
|
||||
@@ -49,23 +51,40 @@
|
||||
</a>
|
||||
</div>
|
||||
<div class="flex flex-row gap-2 py-2 px-2">
|
||||
{#if $user && isModOfAny($user)}
|
||||
<Button
|
||||
href="/moderation"
|
||||
label="Search"
|
||||
class="max-md:w-9 max-md:h-8 max-md:!p-0 items-center justify-center
|
||||
dark:text-zinc-300 text-slate-700 hover:text-inherit
|
||||
hover:bg-slate-200 hover:dark:bg-zinc-900 relative"
|
||||
>
|
||||
{#if $user.reports ?? 0 > 0}
|
||||
<div
|
||||
class="rounded-full w-2 h-2 bg-red-500 absolute -top-1 -left-1"
|
||||
/>
|
||||
{/if}
|
||||
<ShieldIcon width={15} />
|
||||
<span class="hidden md:inline">Reports</span>
|
||||
</Button>
|
||||
{/if}
|
||||
<Button
|
||||
href="/search"
|
||||
label="Search"
|
||||
class="max-sm:w-9 max-sm:h-8 max-sm:!p-0 items-center justify-center
|
||||
class="max-md:w-9 max-md:h-8 max-md:!p-0 items-center justify-center
|
||||
dark:text-zinc-300 text-slate-700 hover:text-inherit hover:bg-slate-200 hover:dark:bg-zinc-900"
|
||||
>
|
||||
<Icon src={MagnifyingGlass} width={16} slot="icon" />
|
||||
<span class="hidden sm:inline">Search</span>
|
||||
<span class="hidden md:inline">Search</span>
|
||||
</Button>
|
||||
<Button
|
||||
href="/communities"
|
||||
label="Communities"
|
||||
class="max-sm:w-9 max-sm:h-8 max-sm:!p-0 items-center justify-center
|
||||
class="max-md:w-9 max-md:h-8 max-md:!p-0 items-center justify-center
|
||||
dark:text-zinc-300 text-slate-700 hover:text-inherit hover:bg-slate-200 hover:dark:bg-zinc-900"
|
||||
>
|
||||
<Icon src={GlobeAlt} width={16} slot="icon" />
|
||||
<span class="hidden sm:inline">Explore</span>
|
||||
<span class="hidden md:inline">Explore</span>
|
||||
</Button>
|
||||
<Menu let:toggleOpen alignment="bottom-right">
|
||||
<Button
|
||||
@@ -73,10 +92,10 @@
|
||||
slot="button"
|
||||
label="Create"
|
||||
on:click={toggleOpen}
|
||||
class="max-sm:w-9 max-sm:h-8 max-sm:!p-0"
|
||||
class="max-md:w-9 max-md:h-8 max-md:!p-0"
|
||||
>
|
||||
<Icon src={Plus} width={18} mini slot="icon" />
|
||||
<span class="hidden sm:inline">Create</span>
|
||||
<span class="hidden md:inline">Create</span>
|
||||
</Button>
|
||||
<li class="text-xs opacity-80 text-left mx-4 my-1 py-1">Create</li>
|
||||
<MenuButton link href="/create/post">
|
||||
@@ -141,7 +160,7 @@
|
||||
user.set(undefined)
|
||||
authData.set(undefined)
|
||||
}}
|
||||
color={Color.dangerSecondary}
|
||||
color="dangerSecondary"
|
||||
>
|
||||
<Icon src={ArrowRightOnRectangle} mini width={16} />Log out
|
||||
</MenuButton>
|
||||
|
||||
@@ -1,10 +1,24 @@
|
||||
<script lang="ts">
|
||||
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
|
||||
import { Color } from '$lib/ui/colors'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
|
||||
export let color: Color = Color.secondary
|
||||
type ButtonColor = keyof typeof buttonColors
|
||||
|
||||
const buttonColors = {
|
||||
secondary:
|
||||
'hover:bg-black/10 hover:dark:bg-white/10 text-black dark:text-white fill-black dark:fill-white',
|
||||
dangerSecondary: 'hover:bg-red-500 text-red-500 hover:text-white',
|
||||
success: 'hover:bg-green-600 text-green-500 hover:text-white',
|
||||
warning:
|
||||
'hover:bg-yellow-500 dark:text-yellow-300 text-yellow-500 hover:text-black',
|
||||
}
|
||||
|
||||
export let color: ButtonColor = 'secondary'
|
||||
export let link = false
|
||||
export let href = ''
|
||||
export let loading = false
|
||||
export let disabled = false
|
||||
|
||||
const click = createEventDispatcher()
|
||||
</script>
|
||||
@@ -13,7 +27,9 @@
|
||||
{#if link}
|
||||
<a
|
||||
{href}
|
||||
class="flex flex-row gap-2 items-center px-4 py-2 w-full text-sm transition-colors {color}"
|
||||
class="flex flex-row gap-2 items-center px-4 py-2 w-full text-sm transition-colors {buttonColors[
|
||||
color
|
||||
]}"
|
||||
>
|
||||
<slot />
|
||||
</a>
|
||||
@@ -21,8 +37,17 @@
|
||||
<button
|
||||
on:click={(e) => click('click', e)}
|
||||
type="button"
|
||||
class="flex flex-row gap-2 items-center px-4 py-2 w-full text-sm transition-colors {color}"
|
||||
class="flex flex-row gap-2 items-center px-4 py-2 w-full text-sm
|
||||
transition-colors {buttonColors[
|
||||
color
|
||||
]} disabled:opacity-50 disabled:pointer-events-none"
|
||||
{disabled}
|
||||
>
|
||||
{#if loading}
|
||||
<Spinner width={16} />
|
||||
{:else}
|
||||
<slot name="icon" />
|
||||
{/if}
|
||||
<slot />
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
+16
-2
@@ -3,6 +3,7 @@ import { get, writable } from 'svelte/store'
|
||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { env } from '$env/dynamic/public'
|
||||
import { isModOfAny } from '$lib/components/lemmy/moderation/moderation.js'
|
||||
|
||||
export const LINKED_INSTANCE_URL = env.PUBLIC_INSTANCE_URL
|
||||
export const DEFAULT_INSTANCE_URL = env.PUBLIC_INSTANCE_URL || 'lemm.ee'
|
||||
@@ -39,6 +40,7 @@ export interface AuthData {
|
||||
|
||||
export interface UserData {
|
||||
unreads: number
|
||||
reports?: number
|
||||
}
|
||||
|
||||
export const authData = writable<AuthData | undefined>()
|
||||
@@ -55,10 +57,22 @@ setInterval(async () => {
|
||||
})
|
||||
|
||||
const u = get(user)
|
||||
u!.unreads = response.mentions + response.private_messages + response.replies
|
||||
if (!u) return
|
||||
u.unreads = response.mentions + response.private_messages + response.replies
|
||||
|
||||
if (isModOfAny(u)) {
|
||||
const reports = await getClient().getReportCount({
|
||||
auth: get(authData)!.token,
|
||||
})
|
||||
|
||||
u.reports =
|
||||
reports.comment_reports +
|
||||
reports.post_reports +
|
||||
(reports.private_message_reports ?? 0)
|
||||
}
|
||||
|
||||
user.set(u)
|
||||
}, 60 * 1000)
|
||||
}, 30 * 1000)
|
||||
|
||||
if (typeof localStorage != 'undefined') {
|
||||
if (localStorage.getItem('user')) {
|
||||
|
||||
+35
-12
@@ -1,26 +1,39 @@
|
||||
import type {
|
||||
CommentReportView,
|
||||
CommentView,
|
||||
CommunityView,
|
||||
PersonView,
|
||||
PostReportView,
|
||||
PostView,
|
||||
PrivateMessage,
|
||||
PrivateMessageReportView,
|
||||
PrivateMessageView,
|
||||
} from 'lemmy-js-client'
|
||||
|
||||
type Result = PostView | CommentView | PersonView | CommunityView
|
||||
type Result =
|
||||
| PostView
|
||||
| CommentView
|
||||
| PersonView
|
||||
| CommunityView
|
||||
| PrivateMessageView
|
||||
| PostReportView
|
||||
| CommentReportView
|
||||
| PrivateMessageReportView
|
||||
|
||||
export function getItemPublished(item: Result) {
|
||||
if ('comment' in item) {
|
||||
return item.comment.published
|
||||
} else if ('post' in item) {
|
||||
return item.post.published
|
||||
}
|
||||
// reports... why
|
||||
if ('post_report' in item) return item.post_report.published
|
||||
if ('comment_report' in item) return item.comment_report.published
|
||||
if ('private_message_report' in item)
|
||||
return item.private_message_report.published
|
||||
|
||||
if ('person' in item) {
|
||||
return item.person.published
|
||||
}
|
||||
// others
|
||||
if ('private_message' in item) return item.private_message.published
|
||||
if ('comment' in item) return item.comment.published
|
||||
else if ('post' in item) return item.post.published
|
||||
|
||||
if ('community' in item) {
|
||||
return item.community.published
|
||||
}
|
||||
if ('person' in item) return item.person.published
|
||||
if ('community' in item) return item.community.published
|
||||
|
||||
return ''
|
||||
}
|
||||
@@ -35,3 +48,13 @@ export const isCommunity = (item: Result): item is CommunityView =>
|
||||
'community' in item
|
||||
|
||||
export const isUser = (item: Result): item is PersonView => 'person' in item
|
||||
|
||||
export const isPostReport = (item: Result): item is PostReportView =>
|
||||
'post_report' in item
|
||||
|
||||
export const isCommentReport = (item: Result): item is CommentReportView =>
|
||||
'comment_report' in item
|
||||
|
||||
export const isPrivateMessageReport = (
|
||||
item: Result
|
||||
): item is PrivateMessageReportView => 'private_message_report' in item
|
||||
@@ -1,6 +0,0 @@
|
||||
import type { MyUserInfo } from 'lemmy-js-client'
|
||||
|
||||
export const isMod = (me: MyUserInfo, community: number) =>
|
||||
me.moderates.map((c) => c.community.id).includes(community)
|
||||
|
||||
export const isAdmin = (me: MyUserInfo) => me.local_user_view.person.admin
|
||||
Reference in new issue
Block a user