feat: add sticky table header

This commit is contained in:
Xyphyn committed 2023-08-22 18:56:17 -07:00
1 parent 114856a052
commit 12b1329364
3 files changed
+99 -33

No files matched your search

+49 -23
View File
@@ -1,39 +1,65 @@
<script lang="ts">
import Card from '$lib/components/ui/Card.svelte'
import { ExclamationTriangle, Icon } from 'svelte-hero-icons'
import ModlogItem from './ModlogItem.svelte'
import Pageination from '$lib/components/ui/Pageination.svelte'
import { searchParam } from '$lib/util.js'
import { page } from '$app/stores'
export let data
</script>
<svelte:head>
<title>Modlog</title>
</svelte:head>
<div class="flex flex-col gap-4">
<h1 class="font-bold text-2xl">Modlog</h1>
{#if data.modlog}
<table class="table border-collapse">
<colgroup>
<col />
<col />
<col />
<col />
<col />
</colgroup>
<thead class="text-left">
<tr>
<th>Action</th>
<th>Moderator</th>
<th>Moderatee</th>
<th>Community</th>
<th>Link</th>
</tr>
</thead>
{#each data.modlog as modlog}
<ModlogItem item={modlog} />
{/each}
</table>
<div class="">
<table
class="table overflow-x-auto table-fixed relative"
style="width: 100%;"
>
<colgroup class="table-fixed">
<col width="20%" />
<col width="30%" />
<col width="25%" class="overflow-x-auto" />
<col width="30%" />
<col width="30%" />
<col width="40%" />
<col width="50%" />
<col width="30%" />
</colgroup>
<thead class="text-left sticky top-16">
<tr class="sticky top-16 rounded-t-lg overflow-hidden">
<th>Time</th>
<th>Moderator</th>
<th>Action</th>
<th>User</th>
<th>Community</th>
<th>Content</th>
<th>Reason</th>
<th>Link</th>
</tr>
</thead>
<tbody class="text-xs">
{#each data.modlog as modlog}
<ModlogItem item={modlog} />
{/each}
</tbody>
</table>
</div>
{/if}
<Pageination
page={data.page}
on:change={(e) => searchParam($page.url, 'page', e.detail.toString())}
/>
</div>
<style lang="postcss">
:global(.table thead tr th) {
@apply border border-slate-200 dark:border-zinc-800 px-4 py-2;
@apply border border-slate-200 dark:border-zinc-800 px-4 py-2 bg-slate-100;
}
:global(.table tr td) {
@@ -45,6 +71,6 @@
}
:global(.dark thead tr th) {
@apply border-zinc-800;
@apply border-zinc-800 bg-zinc-900;
}
</style>
+6 -5
View File
@@ -34,13 +34,13 @@ export const _toModLog = (item: ModAction): ModLog => {
moderator: item.moderator,
moderatee: item.banned_person,
community: item.community,
actionName: 'Ban',
actionName: 'ban',
reason: item.mod_ban_from_community.reason,
timestamp: Date.parse(`${item.mod_ban_from_community.when_}Z`),
}
} else if ('mod_remove_comment' in item) {
return {
actionName: 'Comment Removal',
actionName: 'commentRemoval',
community: item.community,
content: item.comment.content,
timestamp: Date.parse(`${item.mod_remove_comment.when_}Z`),
@@ -51,7 +51,7 @@ export const _toModLog = (item: ModAction): ModLog => {
}
} else if ('mod_remove_post' in item) {
return {
actionName: 'Post Removal',
actionName: 'postRemoval',
community: item.community,
content: item.post.name,
timestamp: Date.parse(`${item.mod_remove_post.when_}Z`),
@@ -68,9 +68,9 @@ export const _toModLog = (item: ModAction): ModLog => {
}
export async function load({ url }) {
if (!get(profile)) return
if (!get(profile)) return { page: 1 }
const { jwt } = get(profile)!
if (!jwt) return
if (!jwt) return { page: 1 }
let community = Number(url.searchParams.get('community')) || undefined
let modId = Number(url.searchParams.get('mod_id')) || undefined
@@ -96,6 +96,7 @@ export async function load({ url }) {
.sort((b, a) => b.timestamp - a.timestamp)
return {
page: page,
modlog: moderationActions,
}
}
+44 -5
View File
@@ -4,28 +4,67 @@
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
import Card from '$lib/components/ui/Card.svelte'
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
import { Icon, Trash, XCircle } from 'svelte-hero-icons'
import type { ModLog } from './+page.js'
export let item: ModLog
</script>
<tr class="text-sm">
<tr class="">
<td>
<span class="font-bold">{item.actionName}</span>
<span>
<RelativeDate date={new Date(item.timestamp)} />
</span>
</td>
<td>
{#if item.moderator}
<UserLink showInstance={false} avatar user={item.moderator} />
<UserLink
showInstance={false}
avatar
avatarSize={20}
user={item.moderator}
/>
{/if}
</td>
<td>
<span class="font-bold">
{#if item.actionName == 'ban'}
<span class="flex items-center gap-1 text-red-600 dark:text-red-400">
<Icon src={XCircle} size="16" mini class="inline" /> Ban
</span>
{:else if item.actionName == 'postRemoval' || item.actionName == 'commentRemoval'}
<span class="flex items-center gap-1 text-red-600 dark:text-red-400">
<Icon src={Trash} size="16" mini class="inline" /> Removal
</span>
{:else}
{item.actionName}
{/if}
</span>
</td>
<td>
{#if item.moderatee}
<UserLink showInstance={false} avatar user={item.moderatee} />
<UserLink showInstance={false} user={item.moderatee} />
{/if}
</td>
<td>
{#if item.community}
<CommunityLink showInstance={false} avatar community={item.community} />
<CommunityLink
showInstance={false}
avatar
avatarSize={20}
community={item.community}
/>
{/if}
</td>
<td>
{#if item.content}
<p>{item.content}</p>
{/if}
</td>
<td>
{#if item.reason}
<p>{item.reason}</p>
{/if}
</td>
<td>